##// END OF EJS Templates
Merge pull request #2194 from minrk/clean_nan...
Bradley M. Froehle -
r8047:157d99af merge
parent child Browse files
Show More
@@ -11,6 +11,7 b''
11 # Imports
11 # Imports
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # stdlib
13 # stdlib
14 import math
14 import re
15 import re
15 import sys
16 import sys
16 import types
17 import types
@@ -161,11 +162,17 b' def json_clean(obj):'
161 """
162 """
162 # types that are 'atomic' and ok in json as-is. bool doesn't need to be
163 # types that are 'atomic' and ok in json as-is. bool doesn't need to be
163 # listed explicitly because bools pass as int instances
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 # containers that we need to convert into lists
167 # containers that we need to convert into lists
167 container_to_list = (tuple, set, types.GeneratorType)
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 if isinstance(obj, atomic_ok):
176 if isinstance(obj, atomic_ok):
170 return obj
177 return obj
171
178
General Comments 0
You need to be logged in to leave comments. Login now