Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e9b1df

Browse files
committed
updated the doc to match the module docstring, fixed a couple of errors in the doc markup and in the module
1 parent 277b6f9 commit 6e9b1df

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

Doc/library/plistlib.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@ The property list (``.plist``) file format is a simple XML pickle supporting
1818
basic object types, like dictionaries, lists, numbers and strings. Usually the
1919
top level object is a dictionary.
2020

21+
To write out and to parse a plist file, use the :func:`writePlist` and
22+
:func:`readPlist` functions.
23+
24+
To work with plist data in bytes objects, use :func:`writePlistToBytes`
25+
and :func:`readPlistFromBytes`.
26+
2127
Values can be strings, integers, floats, booleans, tuples, lists, dictionaries
2228
(but only with string keys), :class:`Data` or :class:`datetime.datetime`
2329
objects. String values (including dictionary keys) have to be unicode strings --
2430
they will be written out as UTF-8.
2531

2632
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
33+
a thin wrapper around a Python bytes object. Use :class:`Data` if your strings
2834
contain control characters.
2935

3036
.. seealso::
3137

32-
`PList manual page <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html>`
38+
`PList manual page <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html>`_
3339
Apple's documentation of the file format.
3440

3541

@@ -55,26 +61,26 @@ This module defines the following functions:
5561
a container that contains objects of unsupported types.
5662

5763

58-
.. function:: readPlistFromString(data)
64+
.. function:: readPlistFromBytes(data)
5965

60-
Read a plist from a string. Return the root object.
66+
Read a plist data from a bytes object. Return the root object.
6167

6268

63-
.. function:: writePlistToString(rootObject)
69+
.. function:: writePlistToBytes(rootObject)
6470

65-
Return *rootObject* as a plist-formatted string.
71+
Return *rootObject* as a plist-formatted bytes object.
6672

6773

6874
The following class is available:
6975

7076
.. class:: Data(data)
7177

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
78+
Return a "data" wrapper object around the bytes object *data*. This is used
79+
in functions converting from/to plists to represent the ``<data>`` type
7480
available in plists.
7581

7682
It has one attribute, :attr:`data`, that can be used to retrieve the Python
77-
string stored in it.
83+
bytes object stored in it.
7884

7985

8086
Examples
@@ -93,8 +99,8 @@ Generating a plist::
9399
aTrueValue = True,
94100
aFalseValue = False,
95101
),
96-
someData = Data("<binary gunk>"),
97-
someMoreData = Data("<lots of binary gunk>" * 10),
102+
someData = Data(b"<binary gunk>"),
103+
someMoreData = Data(b"<lots of binary gunk>" * 10),
98104
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
99105
)
100106
writePlist(pl, fileName)

Lib/plistlib.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
r"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
22
3-
The PropertList (.plist) file format is a simple XML pickle supporting
3+
The property list (.plist) file format is a simple XML pickle supporting
44
basic object types, like dictionaries, lists, numbers and strings.
55
Usually the top level object is a dictionary.
66
@@ -16,32 +16,31 @@
1616
and writePlistToBytes().
1717
1818
Values can be strings, integers, floats, booleans, tuples, lists,
19-
dictionaries, Data or datetime.datetime objects. String values (including
20-
dictionary keys) may be unicode strings -- they will be written out as
21-
UTF-8.
19+
dictionaries (but only with string keys), Data or datetime.datetime objects.
20+
String values (including dictionary keys) have to be unicode strings -- they
21+
will be written out as UTF-8.
2222
2323
The <data> plist type is supported through the Data class. This is a
24-
thin wrapper around a Python bytes object.
24+
thin wrapper around a Python bytes object. Use 'Data' if your strings
25+
contain control characters.
2526
2627
Generate Plist example:
2728
2829
pl = dict(
29-
aString="Doodah",
30-
aList=["A", "B", 12, 32.1, [1, 2, 3]],
30+
aString = "Doodah",
31+
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
3132
aFloat = 0.1,
3233
anInt = 728,
33-
aDict=dict(
34-
anotherString="<hello & hi there!>",
35-
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
36-
aTrueValue=True,
37-
aFalseValue=False,
34+
aDict = dict(
35+
anotherString = "<hello & hi there!>",
36+
aUnicodeValue = "M\xe4ssig, Ma\xdf",
37+
aTrueValue = True,
38+
aFalseValue = False,
3839
),
3940
someData = Data(b"<binary gunk>"),
4041
someMoreData = Data(b"<lots of binary gunk>" * 10),
4142
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
4243
)
43-
# unicode keys are possible, but a little awkward to use:
44-
pl[u'\xc5benraa'] = "That was a unicode key."
4544
writePlist(pl, fileName)
4645
4746
Parse Plist example:
@@ -220,7 +219,7 @@ def writeValue(self, value):
220219
elif isinstance(value, (tuple, list)):
221220
self.writeArray(value)
222221
else:
223-
raise TypeError("unsuported type: %s" % type(value))
222+
raise TypeError("unsupported type: %s" % type(value))
224223

225224
def writeData(self, data):
226225
self.beginElement("data")

0 commit comments

Comments
 (0)