-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure the JSON decoder for safer parsing
- Loading branch information
1 parent
845fc62
commit dd1db2e
Showing
3 changed files
with
18 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""JSON-compatible module with sane defaults.""" | ||
|
||
from json import * # noqa: F401, F403 | ||
from json import loads as original_loads | ||
|
||
|
||
def _safe_int(s): | ||
if len(s) > 100: | ||
raise ValueError('Integer is too large') | ||
return int(s) | ||
|
||
|
||
def loads(*args, **kwargs): | ||
if 'parse_int' not in kwargs: | ||
kwargs['parse_int'] = _safe_int | ||
return original_loads(*args, **kwargs) |
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