�`^c @s�dZddddddddd g Zd
dlZd
dlZd
dlmZd
dlZd
dlZd
�Zd�Z d�Z
d�Zddd�Zddd�Z
dd(d��YZejd�Zd�Zd�Zejd�Zd�ZdZdefd��YZdefd ��YZd efd!��YZdefd"��YZd#d$�Zdd)d%��YZd&d*d'��YZdS(+s�plistlib.py -- a tool to generate and parse MacOSX .plist files.
The PropertyList (.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.
To write out a plist file, use the writePlist(rootObject, pathOrFile)
function. 'rootObject' is the top level object, 'pathOrFile' is a
filename or a (writable) file object.
To parse a plist from a file, use the readPlist(pathOrFile) function,
with a file name or a (readable) file object as the only argument. It
returns the top level object (again, usually a dictionary).
To work with plist data in strings, you can use readPlistFromString()
and writePlistToString().
Values can be strings, integers, floats, booleans, tuples, lists,
dictionaries, Data or datetime.datetime objects. String values (including
dictionary keys) may be unicode strings -- they will be written out as
UTF-8.
The <data> plist type is supported through the Data class. This is a
thin wrapper around a Python string.
Generate Plist example:
pl = dict(
aString="Doodah",
aList=["A", "B", 12, 32.1, [1, 2, 3]],
aFloat=0.1,
anInt=728,
aDict=dict(
anotherString="<hello & hi there!>",
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
aTrueValue=True,
aFalseValue=False,
),
someData=Data("<binary gunk>"),
someMoreData=Data("<lots of binary gunk>" * 10),
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)
Parse Plist example:
pl = readPlist(pathOrFile)
print pl["aKey"]
t readPlistt
writePlisttreadPlistFromStringtwritePlistToStringtreadPlistFromResourcetwritePlistToResourcetPlisttDatatDicti�N(tStringIOcCs_d}t|ttf�r0t|�}d}nt�}|j|�}|r[|j�n|S(s�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).
ii(t
isinstancetstrtunicodetopentPlistParsertparsetclose(t
pathOrFiletdidOpentpt
rootObject((s/sys/lib/python2.7/plistlib.pyRDs
cCs}d}t|ttf�r3t|d�}d}nt|�}|jd�|j|�|jd�|ry|j�ndS(sqWrite 'rootObject' to a .plist file. 'pathOrFile' may either be a
file name or a (writable) file object.
itwis<plist version="1.0">s</plist>N(R
RRR
tPlistWritertwritelnt
writeValueR(RRRtwriter((s/sys/lib/python2.7/plistlib.pyRTs
cCstt|��S(s=Read a plist data from a string. Return the root object.
(RR (tdata((s/sys/lib/python2.7/plistlib.pyRdscCs t�}t||�|j�S(s5Return 'rootObject' as a plist-formatted string.
(R Rtgetvalue(Rtf((s/sys/lib/python2.7/plistlib.pyRjs
tplstic
Cs�tjddd�ddlm}m}ddlm}ddlm}||�}|j ||�|�}|j
|�|j||�j} |j
|�t| �S(s7Read plst resource from the resource fork of path.
s)In 3.x, readPlistFromResource is removed.t
stacklevelii�(tFSReftFSGetResourceForkName(tfsRdPerm(tRes(twarningstwarnpy3ktCarbon.FileRR tCarbon.FilesR!tCarbonR"tFSOpenResourceFilet
UseResFiletGet1ResourceRtCloseResFileR(
tpathtrestypetresidRR R!R"tfsReftresNumt plistData((s/sys/lib/python2.7/plistlib.pyRrs
cCs�tjddd�ddlm}m}ddlm}ddlm}t |�}||�} |j
| |�|�}
|j|
�y|j||�j
�Wn|jk
r�nX|j|�}|j||d�|j�|j|
�d S(
sHWrite 'rootObject' as a plst resource to the resource fork of path.
s(In 3.x, writePlistToResource is removed.Rii�(RR (t
fsRdWrPerm(R"tN(R#R$R%RR R&R2R'R"RR(R)R*tRemoveResourcetErrortResourcetAddResourcet
WriteResourceR+(RR,R-R.RR R2R"R1R/R0tres((s/sys/lib/python2.7/plistlib.pyR�s
t
DumbXMLWritercBs>eZddd�Zd�Zd�Zdd�Zd�ZRS(is cCs(||_g|_||_||_dS(N(tfiletstacktindentLeveltindent(tselfR;R=R>((s/sys/lib/python2.7/plistlib.pyt__init__�s cCs4|jj|�|jd|�|jd7_dS(Ns<%s>i(R<tappendRR=(R?telement((s/sys/lib/python2.7/plistlib.pytbeginElement�scCs$|jd8_|jd|�dS(Nis</%s>(R=R(R?RB((s/sys/lib/python2.7/plistlib.pyt
endElement�scCsJ|dk r5t|�}|jd|||f�n|jd|�dS(Ns<%s>%s</%s>s<%s/>(tNonet_escapeAndEncodeR(R?RBtvalue((s/sys/lib/python2.7/plistlib.pyt
simpleElement�scCs?|r+|jj|j|j|d�n|jjd�dS(Ns
(R;twriteR=R>(R?tline((s/sys/lib/python2.7/plistlib.pyR�s%N(t__name__t
__module__R@RCRDRERHR(((s/sys/lib/python2.7/plistlib.pyR:�s
s{(?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))?)?)?)?)?ZcCsld}tj|�j�}g}x;|D]3}||}|dkrHPn|jt|��q(Wtj|�S(Ntyeartmonthtdaythourtminutetsecond(syearsmonthsdayshoursminutessecond(t_dateParsertmatcht groupdictRERAtinttdatetime(tstordertgdtlsttkeytval((s/sys/lib/python2.7/plistlib.pyt_dateFromString�s
cCs,d|j|j|j|j|j|jfS(Ns%04d-%02d-%02dT%02d:%02d:%02dZ(RMRNRORPRQRR(td((s/sys/lib/python2.7/plistlib.pyt
_dateToString�ssv[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]cCs�tj|�}|dk r*td��n|jdd�}|jdd�}|jdd�}|jdd�}|jd d
�}|jd�S(NsDstrings can't contains control characters; use plistlib.Data insteads
s
s
t&s&t<s<t>s>sutf-8(t_controlCharPattsearchREt
ValueErrortreplacetencode(ttexttm((s/sys/lib/python2.7/plistlib.pyRF�ss�<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
RcBs>eZdddd�Zd�Zd�Zd�Zd�ZRS(is icCs0|r|jt�ntj||||�dS(N(RItPLISTHEADERR:R@(R?R;R=R>twriteHeader((s/sys/lib/python2.7/plistlib.pyR@�scCsYt|ttf�r(|jd|�n-t|t�r]|rM|jd�qU|jd�n�|ttf�r�|jdd|�n�t|t�r�|jdt|��n�t|t �r�|j
|�n�t|t�r�j|�nft|t
j
�r|jdt|��n;t|ttf�r?|j|�ntdt|���dS( Ntstringttruetfalsetintegers%dtrealtdatesunsuported type: %s(R
RRRHtboolRVtlongtfloattreprtdictt writeDictRt writeDataRWR`ttupletlistt
writeArrayt TypeErrorttype(R?RG((s/sys/lib/python2.7/plistlib.pyR�s&cCs�|jd�|jd8_tddt|jjdd �|j��}x6|j|�jd�D]}|rd|j|�qdqdW|jd7_|j d�dS(
NRiiiLs t is
s (
RCR=tmaxtlenR>RgtasBase64tsplitRRD(R?Rt
maxlinelengthRJ((s/sys/lib/python2.7/plistlib.pyRys
cCs�|jd�|j�}|j�xU|D]M\}}t|ttf�sZtd��n|jd|�|j|�q*W|j d�dS(NRwskeys must be stringsR\(
RCtitemstsortR
RRR}RHRRD(R?R_R�R\RG((s/sys/lib/python2.7/plistlib.pyRxs
cCs<|jd�x|D]}|j|�qW|jd�dS(Ntarray(RCRRD(R?R�RG((s/sys/lib/python2.7/plistlib.pyR|s
(RKRLR@RRyRxR|(((s/sys/lib/python2.7/plistlib.pyR�s
t
_InternalDictcBs#eZd�Zd�Zd�ZRS(cCsOy||}Wntk
r*t|�nXddlm}|dtd�|S(Ni�(twarnsLAttribute access from plist dicts is deprecated, use d[key] notation insteadi(tKeyErrortAttributeErrorR#R�tPendingDeprecationWarning(R?tattrRGR�((s/sys/lib/python2.7/plistlib.pyt__getattr__)s
cCs.ddlm}|dtd�|||<dS(Ni�(R�sLAttribute access from plist dicts is deprecated, use d[key] notation insteadi(R#R�R�(R?R�RGR�((s/sys/lib/python2.7/plistlib.pyt__setattr__3s
cCsLy||=Wntk
r't|�nXddlm}|dtd�dS(Ni�(R�sLAttribute access from plist dicts is deprecated, use d[key] notation insteadi(R�R�R#R�R�(R?R�R�((s/sys/lib/python2.7/plistlib.pyt__delattr__9s
(RKRLR�R�R�(((s/sys/lib/python2.7/plistlib.pyR�#s
cBseZd�ZRS(cKs:ddlm}|dtd�tt|�j|�dS(Ni�(R�s?The plistlib.Dict class is deprecated, use builtin dict insteadi(R#R�R�tsuperRR@(R?tkwargsR�((s/sys/lib/python2.7/plistlib.pyR@Ds
(RKRLR@(((s/sys/lib/python2.7/plistlib.pyRBscBs5eZdZd�Zd�Zee�Zd�ZRS(s�This class has been deprecated. Use readPlist() and writePlist()
functions instead, together with regular dict objects.
cKs:ddlm}|dtd�tt|�j|�dS(Ni�(R�sUThe Plist class is deprecated, use the readPlist() and writePlist() functions insteadi(R#R�R�R�RR@(R?R�R�((s/sys/lib/python2.7/plistlib.pyR@Qs
cCs&t|�}|�}|j|�|S(s1Deprecated. Use the readPlist() function instead.(Rtupdate(tclsRRtplist((s/sys/lib/python2.7/plistlib.pytfromFileWs
cCst||�dS(s2Deprecated. Use the writePlist() function instead.N(R(R?R((s/sys/lib/python2.7/plistlib.pyRI_s(RKRLt__doc__R@R�tclassmethodRI(((s/sys/lib/python2.7/plistlib.pyRKs
iLcCsk|dd}g}xGtdt|�|�D]-}||||!}|jtj|��q-Wdj|�S(NiiiR3(trangeR�RAtbinasciit
b2a_base64tjoin(RXR�t
maxbinsizetpiecestitchunk((s/sys/lib/python2.7/plistlib.pyt
_encodeBase64dscBsJeZdZd�Zd�Zee�Zdd�Zd�Zd�ZRS(sWrapper for binary data.cCs
||_dS(N(R(R?R((s/sys/lib/python2.7/plistlib.pyR@qscCs|tj|��S(N(R�t
a2b_base64(R�R((s/sys/lib/python2.7/plistlib.pyt
fromBase64tsiLcCst|j|�S(N(R�R(R?R�((s/sys/lib/python2.7/plistlib.pyR�zscCsat||j�r%t|j|j�St|t�rDt|j|�Stt|�t|��SdS(N(R
t __class__tcmpRRtid(R?tother((s/sys/lib/python2.7/plistlib.pyt__cmp__}s
cCsd|jjt|j�fS(Ns%s(%s)(R�RKRvR(R?((s/sys/lib/python2.7/plistlib.pyt__repr__�s( RKRLR�R@R�R�R�R�R�(((s/sys/lib/python2.7/plistlib.pyRms RcBs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�ZRS(cCsg|_d|_d|_dS(N(R<REt
currentKeytroot(R?((s/sys/lib/python2.7/plistlib.pyR@�s cCsQddlm}|�}|j|_|j|_|j|_|j|�|j S(Ni�(tParserCreate(
txml.parsers.expatR�thandleBeginElementtStartElementHandlerthandleEndElementtEndElementHandlert
handleDatatCharacterDataHandlert ParseFileR�(R?tfileobjR�tparser((s/sys/lib/python2.7/plistlib.pyR�s
cCs<g|_t|d|d�}|dk r8||�ndS(Ntbegin_(RtgetattrRE(R?RBtattrsthandler((s/sys/lib/python2.7/plistlib.pyR��s cCs0t|d|d�}|dk r,|�ndS(Ntend_(R�RE(R?RBR�((s/sys/lib/python2.7/plistlib.pyR��scCs|jj|�dS(N(RRA(R?R((s/sys/lib/python2.7/plistlib.pyR��scCs\|jdk r/||jd|j<d|_n)|jsD||_n|jdj|�dS(Ni�(R�RER<R�RA(R?RG((s/sys/lib/python2.7/plistlib.pyt addObject�s cCsFdj|j�}y|jd�}Wntk
r8nXg|_|S(NR3tascii(R�RRhtUnicodeError(R?R((s/sys/lib/python2.7/plistlib.pytgetData�s
cCs*t�}|j|�|jj|�dS(N(R�R�R<RA(R?R�R_((s/sys/lib/python2.7/plistlib.pyt
begin_dict�s
cCs|jj�dS(N(R<tpop(R?((s/sys/lib/python2.7/plistlib.pytend_dict�scCs|j�|_dS(N(R�R�(R?((s/sys/lib/python2.7/plistlib.pytend_key�scCs'g}|j|�|jj|�dS(N(R�R<RA(R?R�ta((s/sys/lib/python2.7/plistlib.pytbegin_array�s
cCs|jj�dS(N(R<R�(R?((s/sys/lib/python2.7/plistlib.pyt end_array�scCs|jt�dS(N(R�tTrue(R?((s/sys/lib/python2.7/plistlib.pytend_true�scCs|jt�dS(N(R�tFalse(R?((s/sys/lib/python2.7/plistlib.pyt end_false�scCs|jt|j���dS(N(R�RVR�(R?((s/sys/lib/python2.7/plistlib.pytend_integer�scCs|jt|j���dS(N(R�RuR�(R?((s/sys/lib/python2.7/plistlib.pytend_real�scCs|j|j��dS(N(R�R�(R?((s/sys/lib/python2.7/plistlib.pyt
end_string�scCs |jtj|j���dS(N(R�RR�R�(R?((s/sys/lib/python2.7/plistlib.pytend_data�scCs|jt|j���dS(N(R�R^R�(R?((s/sys/lib/python2.7/plistlib.pytend_date�s(RKRLR@RR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s/sys/lib/python2.7/plistlib.pyR�s&
((((R�t__all__R�RWt cStringIOR treR#RRRRRRR:tcompileRSR^R`RdRFRkRRwR�RRR�RR(((s/sys/lib/python2.7/plistlib.pyt<module>3s: $ =
|