-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
451 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from addon_toolkit.storage import StorageInterface | ||
from addon_toolkit.storage import ( | ||
RedirectResult, | ||
StorageInterface, | ||
) | ||
|
||
|
||
class MyBlargStorage(StorageInterface): | ||
"""blarg?""" | ||
|
||
def item_download_url(self, item_id): | ||
def download(self, item_id) -> RedirectResult: | ||
"""blarg blarg blarg""" | ||
return f"http://blarg.example/{item_id}" | ||
return RedirectResult(f"http://blarg.example/{item_id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import abc | ||
import json | ||
from urllib.parse import ( | ||
quote, | ||
unquote, | ||
) | ||
|
||
from addon_service.common.opaque import ( | ||
make_opaque, | ||
unmake_opaque, | ||
) | ||
|
||
|
||
# not a database model; just a convenience wrapper for | ||
# AddonOperationImplementation to give the serializer | ||
class BaseDataclassModel(abc.ABC): | ||
### | ||
# abstract methods | ||
|
||
@classmethod | ||
@abc.abstractmethod | ||
def get_by_natural_key(cls, key: list): | ||
raise NotImplementedError | ||
|
||
@property | ||
@abc.abstractmethod | ||
def natural_key(self) -> list: | ||
raise NotImplementedError | ||
|
||
### | ||
# class methods | ||
|
||
@classmethod | ||
def get_by_pk(cls, pk: str): | ||
_natural_key = json.loads(unmake_opaque(pk)) | ||
return cls.get_by_natural_key(_natural_key) | ||
|
||
@classmethod | ||
def get_by_natural_key_str(cls, key_str: str): | ||
_key = [unquote(_key_segment) for _key_segment in key_str.split(":")] | ||
return cls.get_by_natural_key(_key) | ||
|
||
### | ||
# instance methods | ||
|
||
@property | ||
def natural_key_str(self) -> str: | ||
return ":".join(quote(_key_segment) for _key_segment in self.natural_key) | ||
|
||
@property | ||
def pk(self) -> str: | ||
return make_opaque(json.dumps(self.natural_key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.