##// END OF EJS Templates
Backport PR #2194: clean nan/inf in json_clean...
MinRK -
Show More
@@ -11,6 +11,7 b''
11 11 # Imports
12 12 #-----------------------------------------------------------------------------
13 13 # stdlib
14 import math
14 15 import re
15 16 import sys
16 17 import types
@@ -161,11 +162,17 b' def json_clean(obj):'
161 162 """
162 163 # types that are 'atomic' and ok in json as-is. bool doesn't need to be
163 164 # listed explicitly because bools pass as int instances
164 atomic_ok = (unicode, int, float, types.NoneType)
165 atomic_ok = (unicode, int, types.NoneType)
165 166
166 167 # containers that we need to convert into lists
167 168 container_to_list = (tuple, set, types.GeneratorType)
168 169
170 if isinstance(obj, float):
171 # cast out-of-range floats to their reprs
172 if math.isnan(obj) or math.isinf(obj):
173 return repr(obj)
174 return obj
175
169 176 if isinstance(obj, atomic_ok):
170 177 return obj
171 178
General Comments 0
You need to be logged in to leave comments. Login now