1
:mod:`plistlib` --- Generate and parse Mac OS X ``.plist`` files
2
================================================================
5
:synopsis: Generate and parse Mac OS X plist files.
6
.. moduleauthor:: Jack Jansen
7
.. sectionauthor:: Georg Brandl <georg@python.org>
8
.. (harvested from docstrings in the original file)
14
This module provides an interface for reading and writing the "property list"
15
XML files used mainly by Mac OS X.
17
The property list (``.plist``) file format is a simple XML pickle supporting
18
basic object types, like dictionaries, lists, numbers and strings. Usually the
19
top level object is a dictionary.
21
Values can be strings, integers, floats, booleans, tuples, lists, dictionaries
22
(but only with string keys), :class:`Data` or :class:`datetime.datetime`
23
objects. String values (including dictionary keys) may be unicode strings --
24
they will be written out as UTF-8.
26
The ``<data>`` plist type is supported through the :class:`Data` class. This is
27
a thin wrapper around a Python string. Use :class:`Data` if your strings
28
contain control characters.
32
`PList manual page <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html>`
33
Apple's documentation of the file format.
36
This module defines the following functions:
38
.. function:: readPlist(pathOrFile)
40
Read a plist file. *pathOrFile* may either be a file name or a (readable)
41
file object. Return the unpacked root object (which usually is a
44
The XML data is parsed using the Expat parser from :mod:`xml.parsers.expat`
45
-- see its documentation for possible exceptions on ill-formed XML.
46
Unknown elements will simply be ignored by the plist parser.
49
.. function:: writePlist(rootObject, pathOrFile)
51
Write *rootObject* to a plist file. *pathOrFile* may either be a file name
52
or a (writable) file object.
54
A :exc:`TypeError` will be raised if the object is of an unsupported type or
55
a container that contains objects of unsupported types.
58
.. function:: readPlistFromString(data)
60
Read a plist from a string. Return the root object.
63
.. function:: writePlistToString(rootObject)
65
Return *rootObject* as a plist-formatted string.
68
The following class is available:
72
Return a "data" wrapper object around the string *data*. This is used in
73
functions converting from/to plists to represent the ``<data>`` type
76
It has one attribute, :attr:`data`, that can be used to retrieve the Python
87
aList=["A", "B", 12, 32.1, [1, 2, 3]],
91
anotherString="<hello & hi there!>",
92
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
96
someData = Data("<binary gunk>"),
97
someMoreData = Data("<lots of binary gunk>" * 10),
98
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
100
# unicode keys are possible, but a little awkward to use:
101
pl[u'\xc5benraa'] = "That was a unicode key."
102
writePlist(pl, fileName)
106
pl = readPlist(pathOrFile)