-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #74] This implements configurability for the json.loads/ json.…
…dumps used. First draft.. not as granular as it could be.. but at least it shouldn't slow down the current applications. Tests pass, adds "json_loads" and "json_dumps" parameters to the socketio_manage() call.
- Loading branch information
Alexandre Bourget
committed
Aug 4, 2012
1 parent
79d188f
commit a8b6d93
Showing
4 changed files
with
65 additions
and
27 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,21 @@ | ||
### default json loaders | ||
try: | ||
import simplejson as json | ||
json_decimal_args = {"use_decimal": True} # pragma: no cover | ||
except ImportError: | ||
import json | ||
import decimal | ||
|
||
class DecimalEncoder(json.JSONEncoder): | ||
def default(self, o): | ||
if isinstance(o, decimal.Decimal): | ||
return float(o) | ||
return super(DecimalEncoder, self).default(o) | ||
json_decimal_args = {"cls": DecimalEncoder} | ||
|
||
def default_json_dumps(data): | ||
return json.dumps(data, separators=(',', ':'), | ||
**json_decimal_args) | ||
|
||
def default_json_loads(data): | ||
return json.loads(data) |
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