##// END OF EJS Templates
libs: ext_json improvements for orjson support
super-admin -
r5073:4a99ba09 default
parent child Browse files
Show More
@@ -1,12 +1,20 b''
1 1 import datetime
2 2 import decimal
3 3 import functools
4 # we keep simplejson for having dump functionality still
5 # orjson doesn't support it
6 import simplejson as sjson
4 import json as stdlib_json
7 5
8 import orjson
9 import orjson as json
6 try:
7 # we keep simplejson for having dump functionality still
8 # orjson doesn't support it
9 import simplejson as sjson
10 except ImportError:
11 sjson = stdlib_json
12
13 try:
14 import orjson
15 import orjson as json
16 except ImportError:
17 json = stdlib_json
10 18
11 19
12 20 from rhodecode.lib.datelib import is_aware
@@ -27,10 +35,11 b' def _obj_dump(obj):'
27 35
28 36 :param obj:
29 37 """
38
39 if isinstance(obj, set):
40 return list(obj)
30 41 # See "Date Time String Format" in the ECMA-262 specification.
31 42 # some code borrowed from django 1.4
32 if isinstance(obj, set):
33 return list(obj)
34 43 elif isinstance(obj, datetime.datetime):
35 44 r = obj.isoformat()
36 45 if isinstance(obj.microsecond, int):
@@ -40,6 +49,8 b' def _obj_dump(obj):'
40 49 return r
41 50 elif isinstance(obj, datetime.date):
42 51 return obj.isoformat()
52 elif isinstance(obj, decimal.Decimal):
53 return str(obj)
43 54 elif isinstance(obj, datetime.time):
44 55 if is_aware(obj):
45 56 raise TypeError("Time-zone aware times are not JSON serializable")
@@ -52,8 +63,6 b' def _obj_dump(obj):'
52 63 return obj.__json__()
53 64 else:
54 65 return obj.__json__
55 elif isinstance(obj, decimal.Decimal):
56 return str(obj)
57 66 elif isinstance(obj, complex):
58 67 return [obj.real, obj.imag]
59 68 elif rhodecode and isinstance(obj, rhodecode.translation._LazyString):
General Comments 0
You need to be logged in to leave comments. Login now