Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/plistlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and XML plist files.

The property list (``.plist``) file format is a simple serialization supporting
basic object types, like dictionaries, lists, numbers and strings. Usually the
top level object is a dictionary.
top level object is a dictionary or frozen dictionary.
Comment thread
hugovk marked this conversation as resolved.
Outdated

To write out and to parse a plist file, use the :func:`dump` and
:func:`load` functions.
Expand Down Expand Up @@ -183,12 +183,12 @@ Generating a plist::
import datetime
import plistlib

pl = dict(
pl = frozendict(
Comment thread
hugovk marked this conversation as resolved.
Outdated
aString = "Doodah",
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
aFloat = 0.1,
anInt = 728,
aDict = dict(
aDict = frozendict(
anotherString = "<hello & hi there!>",
aThirdString = "M\xe4ssig, Ma\xdf",
aTrueValue = True,
Expand Down
20 changes: 10 additions & 10 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The property list (.plist) file format is a simple XML pickle supporting
basic object types, like dictionaries, lists, numbers and strings.
Usually the top level object is a dictionary.
Usually the top level object is a dictionary or frozen dictionary.
Comment thread
hugovk marked this conversation as resolved.
Outdated

To write out a plist file, use the dump(value, file)
function. 'value' is the top level object, 'file' is
Expand All @@ -24,12 +24,12 @@
import datetime
import plistlib

pl = dict(
pl = frozendict(
aString = "Doodah",
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
aFloat = 0.1,
anInt = 728,
aDict = dict(
aDict = frozendict(
anotherString = "<hello & hi there!>",
aThirdString = "M\xe4ssig, Ma\xdf",
aTrueValue = True,
Expand Down Expand Up @@ -357,7 +357,7 @@ def write_value(self, value):
elif isinstance(value, float):
self.simple_element("real", repr(value))

elif isinstance(value, dict):
elif isinstance(value, (dict, frozendict)):
self.write_dict(value)

elif isinstance(value, (bytes, bytearray)):
Expand Down Expand Up @@ -715,7 +715,7 @@ def _flatten(self, value):
self._objidtable[id(value)] = refnum

# And finally recurse into containers
if isinstance(value, dict):
if isinstance(value, (dict, frozendict)):
keys = []
values = []
items = value.items()
Expand Down Expand Up @@ -836,7 +836,7 @@ def _write_object(self, value):
self._write_size(0xA0, s)
self._fp.write(struct.pack('>' + self._ref_format * s, *refs))

elif isinstance(value, dict):
elif isinstance(value, (dict, frozendict)):
keyRefs, valRefs = [], []

if self._sort_keys:
Expand Down Expand Up @@ -869,18 +869,18 @@ def _is_fmt_binary(header):
# Generic bits
#

_FORMATS={
FMT_XML: dict(
_FORMATS=frozendict({
FMT_XML: frozendict(
detect=_is_fmt_xml,
parser=_PlistParser,
writer=_PlistWriter,
),
FMT_BINARY: dict(
FMT_BINARY: frozendict(
detect=_is_fmt_binary,
parser=_BinaryPlistParser,
writer=_BinaryPlistWriter,
)
}
})


def load(fp, *, fmt=None, dict_type=dict, aware_datetime=False):
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,25 @@ def test_dict_members(self):
})
self.assertIsNot(pl2['first'], pl2['second'])

def test_frozendict(self):
pl = frozendict(
aString="Doodah",
anInt=728,
aDict=frozendict(
anotherString="hello",
aTrueValue=True,
),
aList=["A", "B", 12],
)

for fmt in ALL_FORMATS:
with self.subTest(fmt=fmt):
data = plistlib.dumps(pl, fmt=fmt)
pl2 = plistlib.loads(data)
self.assertEqual(pl2, dict(pl))
self.assertIsInstance(pl2, dict)
self.assertIsInstance(pl2['aDict'], dict)

def test_controlcharacters(self):
for i in range(128):
c = chr(i)
Expand Down
Loading