[#2504] Serialize prettytoml ArrayElements as lists

This commit is contained in:
Jacob Hayes
2018-07-10 20:58:57 -05:00
parent f0a1413c70
commit 6e05a3e0d2
+9 -1
View File
@@ -14,6 +14,7 @@ import pipfile.api
import six
import toml
import json as simplejson
from prettytoml.elements.array import ArrayElement
from ._compat import Path
@@ -64,6 +65,12 @@ def _normalized(p):
DEFAULT_NEWLINES = u"\n"
def encode_toml_elements(obj):
if isinstance(obj, ArrayElement):
return obj.primitive_value
raise TypeError(repr(obj) + " is not JSON serializable")
def preferred_newlines(f):
if isinstance(f.newlines, six.text_type):
return f.newlines
@@ -631,7 +638,8 @@ class Project(object):
"""
newlines = self._lockfile_newlines
s = simplejson.dumps( # Send Unicode in to guarentee Unicode out.
content, indent=4, separators=(u",", u": "), sort_keys=True
content, indent=4, separators=(u",", u": "), sort_keys=True,
default=encode_toml_elements,
)
with atomic_open_for_write(self.lockfile_location, newline=newlines) as f:
f.write(s)