summaryrefslogtreecommitdiffstats
path: root/Lib/plistlib.py
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-05-29 10:04:54 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-05-29 10:04:54 (GMT)
commit52209d3a1eb03d5a9ef200ffe400c36d32d42ad1 (patch)
treead485f302dd4f2919a60dd2dc2f31ecd34b2cddd /Lib/plistlib.py
parent737b173355b0473d134b1715dd8b1695eb023d8b (diff)
downloadcpython-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.py30
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):