mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merged revisions 74813 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r74813 | ezio.melotti | 2009-09-16 03:49:03 +0300 (Wed, 16 Sep 2009) | 1 line updated the doc to match the module docstring, fixed a couple of errors in the doc markup and in the module ........
This commit is contained in:
parent
6b084241e8
commit
1e112baf6a
2 changed files with 31 additions and 26 deletions
|
@ -18,18 +18,24 @@ The property list (``.plist``) file format is a simple XML pickle supporting
|
||||||
basic object types, like dictionaries, lists, numbers and strings. Usually the
|
basic object types, like dictionaries, lists, numbers and strings. Usually the
|
||||||
top level object is a dictionary.
|
top level object is a dictionary.
|
||||||
|
|
||||||
|
To write out and to parse a plist file, use the :func:`writePlist` and
|
||||||
|
:func:`readPlist` functions.
|
||||||
|
|
||||||
|
To work with plist data in bytes objects, use :func:`writePlistToBytes`
|
||||||
|
and :func:`readPlistFromBytes`.
|
||||||
|
|
||||||
Values can be strings, integers, floats, booleans, tuples, lists, dictionaries
|
Values can be strings, integers, floats, booleans, tuples, lists, dictionaries
|
||||||
(but only with string keys), :class:`Data` or :class:`datetime.datetime`
|
(but only with string keys), :class:`Data` or :class:`datetime.datetime`
|
||||||
objects. String values (including dictionary keys) have to be unicode strings --
|
objects. String values (including dictionary keys) have to be unicode strings --
|
||||||
they will be written out as UTF-8.
|
they will be written out as UTF-8.
|
||||||
|
|
||||||
The ``<data>`` plist type is supported through the :class:`Data` class. This is
|
The ``<data>`` plist type is supported through the :class:`Data` class. This is
|
||||||
a thin wrapper around a Python string. Use :class:`Data` if your strings
|
a thin wrapper around a Python bytes object. Use :class:`Data` if your strings
|
||||||
contain control characters.
|
contain control characters.
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
`PList manual page <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html>`
|
`PList manual page <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html>`_
|
||||||
Apple's documentation of the file format.
|
Apple's documentation of the file format.
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,26 +61,26 @@ This module defines the following functions:
|
||||||
a container that contains objects of unsupported types.
|
a container that contains objects of unsupported types.
|
||||||
|
|
||||||
|
|
||||||
.. function:: readPlistFromString(data)
|
.. function:: readPlistFromBytes(data)
|
||||||
|
|
||||||
Read a plist from a string. Return the root object.
|
Read a plist data from a bytes object. Return the root object.
|
||||||
|
|
||||||
|
|
||||||
.. function:: writePlistToString(rootObject)
|
.. function:: writePlistToBytes(rootObject)
|
||||||
|
|
||||||
Return *rootObject* as a plist-formatted string.
|
Return *rootObject* as a plist-formatted bytes object.
|
||||||
|
|
||||||
|
|
||||||
The following class is available:
|
The following class is available:
|
||||||
|
|
||||||
.. class:: Data(data)
|
.. class:: Data(data)
|
||||||
|
|
||||||
Return a "data" wrapper object around the string *data*. This is used in
|
Return a "data" wrapper object around the bytes object *data*. This is used
|
||||||
functions converting from/to plists to represent the ``<data>`` type
|
in functions converting from/to plists to represent the ``<data>`` type
|
||||||
available in plists.
|
available in plists.
|
||||||
|
|
||||||
It has one attribute, :attr:`data`, that can be used to retrieve the Python
|
It has one attribute, :attr:`data`, that can be used to retrieve the Python
|
||||||
string stored in it.
|
bytes object stored in it.
|
||||||
|
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
|
@ -93,8 +99,8 @@ Generating a plist::
|
||||||
aTrueValue = True,
|
aTrueValue = True,
|
||||||
aFalseValue = False,
|
aFalseValue = False,
|
||||||
),
|
),
|
||||||
someData = Data("<binary gunk>"),
|
someData = Data(b"<binary gunk>"),
|
||||||
someMoreData = Data("<lots of binary gunk>" * 10),
|
someMoreData = Data(b"<lots of binary gunk>" * 10),
|
||||||
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
|
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
|
||||||
)
|
)
|
||||||
writePlist(pl, fileName)
|
writePlist(pl, fileName)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
r"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
|
r"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
|
||||||
|
|
||||||
The PropertList (.plist) file format is a simple XML pickle supporting
|
The property list (.plist) file format is a simple XML pickle supporting
|
||||||
basic object types, like dictionaries, lists, numbers and strings.
|
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.
|
||||||
|
|
||||||
|
@ -16,12 +16,13 @@ To work with plist data in bytes objects, you can use readPlistFromBytes()
|
||||||
and writePlistToBytes().
|
and writePlistToBytes().
|
||||||
|
|
||||||
Values can be strings, integers, floats, booleans, tuples, lists,
|
Values can be strings, integers, floats, booleans, tuples, lists,
|
||||||
dictionaries, Data or datetime.datetime objects. String values (including
|
dictionaries (but only with string keys), Data or datetime.datetime objects.
|
||||||
dictionary keys) may be unicode strings -- they will be written out as
|
String values (including dictionary keys) have to be unicode strings -- they
|
||||||
UTF-8.
|
will be written out as UTF-8.
|
||||||
|
|
||||||
The <data> plist type is supported through the Data class. This is a
|
The <data> plist type is supported through the Data class. This is a
|
||||||
thin wrapper around a Python bytes object.
|
thin wrapper around a Python bytes object. Use 'Data' if your strings
|
||||||
|
contain control characters.
|
||||||
|
|
||||||
Generate Plist example:
|
Generate Plist example:
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ Generate Plist example:
|
||||||
anInt = 728,
|
anInt = 728,
|
||||||
aDict = dict(
|
aDict = dict(
|
||||||
anotherString = "<hello & hi there!>",
|
anotherString = "<hello & hi there!>",
|
||||||
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
|
aUnicodeValue = "M\xe4ssig, Ma\xdf",
|
||||||
aTrueValue = True,
|
aTrueValue = True,
|
||||||
aFalseValue = False,
|
aFalseValue = False,
|
||||||
),
|
),
|
||||||
|
@ -40,8 +41,6 @@ Generate Plist example:
|
||||||
someMoreData = Data(b"<lots of binary gunk>" * 10),
|
someMoreData = Data(b"<lots of binary gunk>" * 10),
|
||||||
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
|
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
|
||||||
)
|
)
|
||||||
# unicode keys are possible, but a little awkward to use:
|
|
||||||
pl[u'\xc5benraa'] = "That was a unicode key."
|
|
||||||
writePlist(pl, fileName)
|
writePlist(pl, fileName)
|
||||||
|
|
||||||
Parse Plist example:
|
Parse Plist example:
|
||||||
|
@ -220,7 +219,7 @@ class PlistWriter(DumbXMLWriter):
|
||||||
elif isinstance(value, (tuple, list)):
|
elif isinstance(value, (tuple, list)):
|
||||||
self.writeArray(value)
|
self.writeArray(value)
|
||||||
else:
|
else:
|
||||||
raise TypeError("unsuported type: %s" % type(value))
|
raise TypeError("unsupported type: %s" % type(value))
|
||||||
|
|
||||||
def writeData(self, data):
|
def writeData(self, data):
|
||||||
self.beginElement("data")
|
self.beginElement("data")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue