Show More
@@ -30,6 +30,12 next_attr_name = '__next__' if py3compat.PY3 else 'next' | |||
|
30 | 30 | ISO8601="%Y-%m-%dT%H:%M:%S.%f" |
|
31 | 31 | ISO8601_PAT=re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+$") |
|
32 | 32 | |
|
33 | # float constants | |
|
34 | NAN = float('nan') | |
|
35 | INF = float('inf') | |
|
36 | NINF = float('-inf') | |
|
37 | INFS = (INF, NINF) | |
|
38 | ||
|
33 | 39 | #----------------------------------------------------------------------------- |
|
34 | 40 | # Classes and functions |
|
35 | 41 | #----------------------------------------------------------------------------- |
@@ -161,11 +167,17 def json_clean(obj): | |||
|
161 | 167 | """ |
|
162 | 168 | # types that are 'atomic' and ok in json as-is. bool doesn't need to be |
|
163 | 169 | # listed explicitly because bools pass as int instances |
|
164 |
atomic_ok = (unicode, int, |
|
|
170 | atomic_ok = (unicode, int, types.NoneType) | |
|
165 | 171 | |
|
166 | 172 | # containers that we need to convert into lists |
|
167 | 173 | container_to_list = (tuple, set, types.GeneratorType) |
|
168 | 174 | |
|
175 | if isinstance(obj, float): | |
|
176 | # cast out-of-range floats to their reprs | |
|
177 | if obj != obj or obj in INFS: | |
|
178 | return repr(obj) | |
|
179 | return obj | |
|
180 | ||
|
169 | 181 | if isinstance(obj, atomic_ok): |
|
170 | 182 | return obj |
|
171 | 183 |
General Comments 0
You need to be logged in to leave comments.
Login now