-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decreased timeout for retries, fixed encoding, show source as alter f…
…or unavailable images
- Loading branch information
Showing
3 changed files
with
12 additions
and
4 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
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,22 +1,30 @@ | ||
""" | ||
App utilities. | ||
""" | ||
import logging | ||
from typing import Any | ||
|
||
import orjson | ||
from fastapi.encoders import jsonable_encoder | ||
from fastapi_cache import Coder | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
# pylint: disable=no-member | ||
class ORJsonCoder(Coder): | ||
"""orjson coder""" | ||
|
||
@classmethod | ||
def encode(cls, value: Any) -> str: | ||
"""serialize python object to json-bytes""" | ||
return str(orjson.dumps(value, default=jsonable_encoder)) # pylint: disable=no-member | ||
return orjson.dumps(value, default=jsonable_encoder).decode("utf-8") | ||
|
||
@classmethod | ||
def decode(cls, value: Any) -> Any: | ||
"""deserializes JSON to Python objects""" | ||
return orjson.loads(value) # pylint: disable=no-member | ||
try: | ||
return orjson.loads(value) | ||
except orjson.JSONDecodeError: | ||
log.warning("Unable to decode %s", value) | ||
return None |
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