mirror of https://github.com/python/cpython
#14835: Make plistlib output empty arrays & dicts like OS X
Patch by Sidney San Martín.
This commit is contained in:
parent
737b173355
commit
52209d3a1e
|
@ -237,20 +237,26 @@ class PlistWriter(DumbXMLWriter):
|
|||
self.endElement("data")
|
||||
|
||||
def writeDict(self, d):
|
||||
self.beginElement("dict")
|
||||
items = sorted(d.items())
|
||||
for key, value in items:
|
||||
if not isinstance(key, str):
|
||||
raise TypeError("keys must be strings")
|
||||
self.simpleElement("key", key)
|
||||
self.writeValue(value)
|
||||
self.endElement("dict")
|
||||
if d:
|
||||
self.beginElement("dict")
|
||||
items = sorted(d.items())
|
||||
for key, value in items:
|
||||
if not isinstance(key, str):
|
||||
raise TypeError("keys must be strings")
|
||||
self.simpleElement("key", key)
|
||||
self.writeValue(value)
|
||||
self.endElement("dict")
|
||||
else:
|
||||
self.simpleElement("dict")
|
||||
|
||||
def writeArray(self, array):
|
||||
self.beginElement("array")
|
||||
for value in array:
|
||||
self.writeValue(value)
|
||||
self.endElement("array")
|
||||
if array:
|
||||
self.beginElement("array")
|
||||
for value in array:
|
||||
self.writeValue(value)
|
||||
self.endElement("array")
|
||||
else:
|
||||
self.simpleElement("array")
|
||||
|
||||
|
||||
class _InternalDict(dict):
|
||||
|
|
|
@ -55,6 +55,10 @@ TESTDATA = b"""<?xml version="1.0" encoding="UTF-8"?>
|
|||
</array>
|
||||
<key>aString</key>
|
||||
<string>Doodah</string>
|
||||
<key>anEmptyDict</key>
|
||||
<dict/>
|
||||
<key>anEmptyList</key>
|
||||
<array/>
|
||||
<key>anInt</key>
|
||||
<integer>728</integer>
|
||||
<key>nestedData</key>
|
||||
|
@ -112,6 +116,8 @@ class TestPlistlib(unittest.TestCase):
|
|||
someMoreData = plistlib.Data(b"<lots of binary gunk>\0\1\2\3" * 10),
|
||||
nestedData = [plistlib.Data(b"<lots of binary gunk>\0\1\2\3" * 10)],
|
||||
aDate = datetime.datetime(2004, 10, 26, 10, 33, 33),
|
||||
anEmptyDict = dict(),
|
||||
anEmptyList = list()
|
||||
)
|
||||
pl['\xc5benraa'] = "That was a unicode key."
|
||||
return pl
|
||||
|
|
|
@ -662,6 +662,7 @@ Alex Martelli
|
|||
Anthony Martin
|
||||
Owen Martin
|
||||
Sébastien Martini
|
||||
Sidney San Martín
|
||||
Roger Masse
|
||||
Nick Mathewson
|
||||
Simon Mathieu
|
||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.3.0 Alpha 4?
|
|||
Core and Builtins
|
||||
-----------------
|
||||
|
||||
- Issue #14835: Make plistlib output empty arrays & dicts like OS X.
|
||||
Patch by Sidney San Martín.
|
||||
|
||||
- Issue #14930: Make memoryview objects weakrefable.
|
||||
|
||||
- Issue #14775: Fix a potential quadratic dict build-up due to the garbage
|
||||
|
|
Loading…
Reference in New Issue