apply fp_serialize() changes on main serialize() method
parent
922de111ed
commit
c2d360d223
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
import io
|
||||||
|
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
|
@ -73,16 +74,9 @@ def serialize(obj, pretty=False, include_optional_defaults=False, **kwargs):
|
||||||
When ``pretty=True`` the following key-value pairs will be added or
|
When ``pretty=True`` the following key-value pairs will be added or
|
||||||
overridden: indent=4, separators=(",", ": "), item_sort_key=sort_by.
|
overridden: indent=4, separators=(",", ": "), item_sort_key=sort_by.
|
||||||
"""
|
"""
|
||||||
if pretty:
|
with io.StringIO() as fp:
|
||||||
def sort_by(element):
|
fp_serialize(obj, fp, pretty, include_optional_defaults, **kwargs)
|
||||||
return find_property_index(obj, *element)
|
return fp.getvalue()
|
||||||
|
|
||||||
kwargs.update({'indent': 4, 'separators': (',', ': '), 'item_sort_key': sort_by})
|
|
||||||
|
|
||||||
if include_optional_defaults:
|
|
||||||
return json.dumps(obj, cls=STIXJSONIncludeOptionalDefaultsEncoder, **kwargs)
|
|
||||||
else:
|
|
||||||
return json.dumps(obj, cls=STIXJSONEncoder, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def fp_serialize(obj, fp, pretty=False, include_optional_defaults=False, **kwargs):
|
def fp_serialize(obj, fp, pretty=False, include_optional_defaults=False, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue