diff options
-rw-r--r-- | Lib/plistlib.py | 30 | ||||
-rw-r--r-- | Lib/test/test_plistlib.py | 6 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 28 insertions, 12 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py index 21076db..41fd8f2 100644 --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -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): diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index 5f980d0..a9e343e 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -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 |