diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-05-29 10:04:54 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-05-29 10:04:54 (GMT) |
commit | 52209d3a1eb03d5a9ef200ffe400c36d32d42ad1 (patch) | |
tree | ad485f302dd4f2919a60dd2dc2f31ecd34b2cddd /Lib/plistlib.py | |
parent | 737b173355b0473d134b1715dd8b1695eb023d8b (diff) | |
download | cpython-52209d3a1eb03d5a9ef200ffe400c36d32d42ad1.zip cpython-52209d3a1eb03d5a9ef200ffe400c36d32d42ad1.tar.gz cpython-52209d3a1eb03d5a9ef200ffe400c36d32d42ad1.tar.bz2 |
#14835: Make plistlib output empty arrays & dicts like OS X
Patch by Sidney San MartÃn.
Diffstat (limited to 'Lib/plistlib.py')
-rw-r--r-- | Lib/plistlib.py | 30 |
1 files changed, 18 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): |