Show More
@@ -12,6 +12,7 b'' | |||||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # stdlib |
|
13 | # stdlib | |
14 | import re |
|
14 | import re | |
|
15 | import sys | |||
15 | import types |
|
16 | import types | |
16 | from datetime import datetime |
|
17 | from datetime import datetime | |
17 |
|
18 | |||
@@ -121,7 +122,7 b' def json_clean(obj):' | |||||
121 | """ |
|
122 | """ | |
122 | # types that are 'atomic' and ok in json as-is. bool doesn't need to be |
|
123 | # types that are 'atomic' and ok in json as-is. bool doesn't need to be | |
123 | # listed explicitly because bools pass as int instances |
|
124 | # listed explicitly because bools pass as int instances | |
124 |
atomic_ok = ( |
|
125 | atomic_ok = (unicode, int, float, types.NoneType) | |
125 |
|
126 | |||
126 | # containers that we need to convert into lists |
|
127 | # containers that we need to convert into lists | |
127 | container_to_list = (tuple, set, types.GeneratorType) |
|
128 | container_to_list = (tuple, set, types.GeneratorType) | |
@@ -129,6 +130,9 b' def json_clean(obj):' | |||||
129 | if isinstance(obj, atomic_ok): |
|
130 | if isinstance(obj, atomic_ok): | |
130 | return obj |
|
131 | return obj | |
131 |
|
132 | |||
|
133 | if isinstance(obj, bytes): | |||
|
134 | return obj.decode(sys.getdefaultencoding(), 'replace') | |||
|
135 | ||||
132 | if isinstance(obj, container_to_list) or ( |
|
136 | if isinstance(obj, container_to_list) or ( | |
133 | hasattr(obj, '__iter__') and hasattr(obj, 'next')): |
|
137 | hasattr(obj, '__iter__') and hasattr(obj, 'next')): | |
134 | obj = list(obj) |
|
138 | obj = list(obj) |
General Comments 0
You need to be logged in to leave comments.
Login now