Back to index

python3.2  3.2.2
Classes | Functions | Variables
plistlib Namespace Reference

Classes

class  DumbXMLWriter
class  PlistWriter
class  _InternalDict
class  Dict
class  Plist
class  Data
class  PlistParser

Functions

def readPlist
def writePlist
def readPlistFromBytes
def writePlistToBytes
def _dateFromString
def _dateToString
def _escape
def _encodeBase64

Variables

list __all__
tuple _dateParser = re.compile(r"(?P<year>\d\d\d\d)(?:-(?P<month>\d\d)(?:-(?P<day>\d\d)(?:T(?P<hour>\d\d)(?::(?P<minute>\d\d)(?::(?P<second>\d\d))?)?)?)?)?Z", re.ASCII)
tuple _controlCharPat
string PLISTHEADER

Function Documentation

def plistlib._dateFromString (   s) [private]

Definition at line 155 of file plistlib.py.

00155 
00156 def _dateFromString(s):
00157     order = ('year', 'month', 'day', 'hour', 'minute', 'second')
00158     gd = _dateParser.match(s).groupdict()
00159     lst = []
00160     for key in order:
00161         val = gd[key]
00162         if val is None:
00163             break
00164         lst.append(int(val))
00165     return datetime.datetime(*lst)

Here is the caller graph for this function:

def plistlib._dateToString (   d) [private]

Definition at line 166 of file plistlib.py.

00166 
00167 def _dateToString(d):
00168     return '%04d-%02d-%02dT%02d:%02d:%02dZ' % (
00169         d.year, d.month, d.day,
00170         d.hour, d.minute, d.second
00171     )
00172 
00173 
# Regex to find any control chars, except for \t \n and \r

Here is the caller graph for this function:

def plistlib._encodeBase64 (   s,
  maxlinelength = 76 
) [private]

Definition at line 321 of file plistlib.py.

00321 
00322 def _encodeBase64(s, maxlinelength=76):
00323     # copied from base64.encodebytes(), with added maxlinelength argument
00324     maxbinsize = (maxlinelength//4)*3
00325     pieces = []
00326     for i in range(0, len(s), maxbinsize):
00327         chunk = s[i : i + maxbinsize]
00328         pieces.append(binascii.b2a_base64(chunk))
00329     return b''.join(pieces)

Here is the caller graph for this function:

def plistlib._escape (   text) [private]

Definition at line 178 of file plistlib.py.

00178 
00179 def _escape(text):
00180     m = _controlCharPat.search(text)
00181     if m is not None:
00182         raise ValueError("strings can't contains control characters; "
00183                          "use plistlib.Data instead")
00184     text = text.replace("\r\n", "\n")       # convert DOS line endings
00185     text = text.replace("\r", "\n")         # convert Mac line endings
00186     text = text.replace("&", "&amp;")       # escape '&'
00187     text = text.replace("<", "&lt;")        # escape '<'
00188     text = text.replace(">", "&gt;")        # escape '>'
00189     return text
00190 

Here is the caller graph for this function:

def plistlib.readPlist (   pathOrFile)
Read a .plist file. 'pathOrFile' may either be a file name or a
(readable) file object. Return the unpacked root object (which
usually is a dictionary).

Definition at line 65 of file plistlib.py.

00065 
00066 def readPlist(pathOrFile):
00067     """Read a .plist file. 'pathOrFile' may either be a file name or a
00068     (readable) file object. Return the unpacked root object (which
00069     usually is a dictionary).
00070     """
00071     didOpen = False
00072     try:
00073         if isinstance(pathOrFile, str):
00074             pathOrFile = open(pathOrFile, 'rb')
00075             didOpen = True
00076         p = PlistParser()
00077         rootObject = p.parse(pathOrFile)
00078     finally:
00079         if didOpen:
00080             pathOrFile.close()
00081     return rootObject
00082 

Here is the caller graph for this function:

Read a plist data from a bytes object. Return the root object.

Definition at line 101 of file plistlib.py.

00101 
00102 def readPlistFromBytes(data):
00103     """Read a plist data from a bytes object. Return the root object.
00104     """
00105     return readPlist(BytesIO(data))
00106 

Here is the call graph for this function:

Here is the caller graph for this function:

def plistlib.writePlist (   rootObject,
  pathOrFile 
)
Write 'rootObject' to a .plist file. 'pathOrFile' may either be a
file name or a (writable) file object.

Definition at line 83 of file plistlib.py.

00083 
00084 def writePlist(rootObject, pathOrFile):
00085     """Write 'rootObject' to a .plist file. 'pathOrFile' may either be a
00086     file name or a (writable) file object.
00087     """
00088     didOpen = False
00089     try:
00090         if isinstance(pathOrFile, str):
00091             pathOrFile = open(pathOrFile, 'wb')
00092             didOpen = True
00093         writer = PlistWriter(pathOrFile)
00094         writer.writeln("<plist version=\"1.0\">")
00095         writer.writeValue(rootObject)
00096         writer.writeln("</plist>")
00097     finally:
00098         if didOpen:
00099             pathOrFile.close()
00100 

Here is the caller graph for this function:

def plistlib.writePlistToBytes (   rootObject)
Return 'rootObject' as a plist-formatted bytes object.

Definition at line 107 of file plistlib.py.

00107 
00108 def writePlistToBytes(rootObject):
00109     """Return 'rootObject' as a plist-formatted bytes object.
00110     """
00111     f = BytesIO()
00112     writePlist(rootObject, f)
00113     return f.getvalue()
00114 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [
00002     "readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes",
00003     "Plist", "Data", "Dict"
00004 ]

Definition at line 53 of file plistlib.py.

Initial value:
00001 re.compile(
00002     r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
00003     r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")

Definition at line 174 of file plistlib.py.

tuple plistlib._dateParser = re.compile(r"(?P<year>\d\d\d\d)(?:-(?P<month>\d\d)(?:-(?P<day>\d\d)(?:T(?P<hour>\d\d)(?::(?P<minute>\d\d)(?::(?P<second>\d\d))?)?)?)?)?Z", re.ASCII)

Definition at line 153 of file plistlib.py.

Initial value:
00001 """\
00002 <?xml version="1.0" encoding="UTF-8"?>
00003 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
00004 """

Definition at line 191 of file plistlib.py.