File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 28
28
from datetime import datetime
29
29
from operator import itemgetter , methodcaller
30
30
from statistics import mean
31
- from typing import Dict , List , Union
31
+ from typing import Any , Dict , List , Union
32
32
from urllib .error import HTTPError , URLError
33
33
from urllib .parse import urlparse
34
34
from urllib .request import Request , urlopen
50
50
# Need to log info but importing logger will cause cyclic imports
51
51
pass
52
52
53
- try :
54
- import ujson as json
55
- except ImportError :
56
- # Need to log info but importing logger will cause cyclic imports
57
- pass
58
-
59
53
if 'json' not in globals ():
60
- import json
54
+ try :
55
+ # Note: ujson is not officially supported
56
+ # Available as a fallback to allow orjson's unsupported platforms to use a faster serialization lib
57
+ import ujson as json
58
+ except ImportError :
59
+ import json
60
+
61
+ # To allow ujson & json dumps to serialize datetime
62
+ def _json_default (v : Any ) -> Any :
63
+ if isinstance (v , datetime ):
64
+ return v .isoformat ()
65
+ return v
66
+
67
+ json .dumps = functools .partial (json .dumps , default = _json_default )
61
68
62
69
##############
63
70
# GLOBALS VARS
You can’t perform that action at this time.
0 commit comments