-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #577 from danigosa/feature/ujson_support
Feature: Support ujson if installed
- Loading branch information
Showing
7 changed files
with
35 additions
and
11 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
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,27 @@ | ||
import os | ||
|
||
HUG_USE_UJSON = bool(os.environ.get('HUG_USE_UJSON', 1)) | ||
try: # pragma: no cover | ||
if HUG_USE_UJSON: | ||
import ujson as json | ||
|
||
class dumps_proxy: | ||
"""Proxies the call so non supported kwargs are skipped | ||
and it enables escape_forward_slashes to simulate built-in json | ||
""" | ||
_dumps = json.dumps | ||
|
||
def __call__(self, *args, **kwargs): | ||
kwargs.pop('default', None) | ||
kwargs.pop('separators', None) | ||
kwargs.update(escape_forward_slashes=False) | ||
try: | ||
return self._dumps(*args, **kwargs) | ||
except Exception as exc: | ||
raise TypeError("Type[ujson] is not Serializable", exc) | ||
|
||
json.dumps = dumps_proxy() | ||
else: | ||
import json | ||
except ImportError: # pragma: no cover | ||
import json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ tox==2.7.0 | |
wheel==0.29.0 | ||
pytest-xdist==1.14.0 | ||
marshmallow==2.6.0 | ||
ujson==1.35 |