ó zfc @sŸdZddddddddd g Zd d lZd d lZd d lmZd d lZd d lZd „Zd„Z d„Z d„Z ddd„Z ddd„Z dd*d„ƒYZejdƒZd„Zd„ZejdƒZd„ZdZdefd„ƒYZdefd „ƒYZd efd!„ƒYZdefd"„ƒYZd#d$„Zdd+d%„ƒYZd&efd'„ƒYZd(d,d)„ƒYZd S(-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 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="", aUnicodeValue=u'M\xe4ssig, Ma\xdf', aTrueValue=True, aFalseValue=False, ), someData=Data(""), someMoreData=Data("" * 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 isinstancetstrtunicodetopent PlistParsertparsetclose(t pathOrFiletdidOpentpt rootObject((s /usr/lib64/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. itwissN(R R R R t PlistWritertwritelnt writeValueR(RRRtwriter((s /usr/lib64/python2.7/plistlib.pyRTs     cCstt|ƒƒS(s=Read a plist data from a string. Return the root object. (RR (tdata((s /usr/lib64/python2.7/plistlib.pyRdscCs tƒ}t||ƒ|jƒS(s5Return 'rootObject' as a plist-formatted string. (R Rtgetvalue(Rtf((s /usr/lib64/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(twarningstwarnpy3kt Carbon.FileRR t Carbon.FilesR!tCarbonR"tFSOpenResourceFilet UseResFilet Get1ResourceRt CloseResFileR( tpathtrestypetresidRR R!R"tfsReftresNumt plistData((s /usr/lib64/python2.7/plistlib.pyRrs    c Csô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*tRemoveResourcetErrortResourcet AddResourcet WriteResourceR+( RR,R-R.RR R2R"R1R/R0tres((s /usr/lib64/python2.7/plistlib.pyR‚s     t DumbXMLWritercBs>eZddd„Zd„Zd„Zdd„Zd„ZRS(is cCs(||_g|_||_||_dS(N(tfiletstackt indentLeveltindent(tselfR;R=R>((s /usr/lib64/python2.7/plistlib.pyt__init__™s   cCs4|jj|ƒ|jd|ƒ|jd7_dS(Ns<%s>i(R<tappendRR=(R?telement((s /usr/lib64/python2.7/plistlib.pyt beginElementŸscCs$|jd8_|jd|ƒdS(Nis(R=R(R?RB((s /usr/lib64/python2.7/plistlib.pyt endElement¤scCsJ|dk r5t|ƒ}|jd|||fƒn|jd|ƒdS(Ns <%s>%ss<%s/>(tNonet_escapeAndEncodeR(R?RBtvalue((s /usr/lib64/python2.7/plistlib.pyt simpleElementªs  cCs?|r+|jj|j|j|dƒn|jjdƒdS(Ns (R;twriteR=R>(R?tline((s /usr/lib64/python2.7/plistlib.pyR±s%N(t__name__t __module__R@RCRDRERHR(((s /usr/lib64/python2.7/plistlib.pyR:—s    s{(?P\d\d\d\d)(?:-(?P\d\d)(?:-(?P\d\d)(?:T(?P\d\d)(?::(?P\d\d)(?::(?P\d\d))?)?)?)?)?ZcCsld}tj|ƒjƒ}g}x;|D]3}||}|dkrHPn|jt|ƒƒq(Wtj|ŒS(Ntyeartmonthtdaythourtminutetsecond(RMRNRORPRQRR(t _dateParsertmatcht groupdictRERAtinttdatetime(tstordertgdtlsttkeytval((s /usr/lib64/python2.7/plistlib.pyt_dateFromString½s   cCs,d|j|j|j|j|j|jfS(Ns%04d-%02d-%02dT%02d:%02d:%02dZ(RMRNRORPRQRR(td((s /usr/lib64/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&ts>sutf-8(t_controlCharPattsearchREt ValueErrortreplacetencode(ttexttm((s /usr/lib64/python2.7/plistlib.pyRFÔs sŽ RcBs>eZdddd„Zd„Zd„Zd„Zd„ZRS(is icCs0|r|jtƒntj||||ƒdS(N(RIt PLISTHEADERR:R@(R?R;R=R>t writeHeader((s /usr/lib64/python2.7/plistlib.pyR@èscCsYt|ttfƒr(|jd|ƒn-t|tƒr]|rM|jdƒqU|jdƒnøt|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 R R RHtboolRVtlongtfloattreprtdictt writeDictRt writeDataRWR`ttupletlistt writeArrayt TypeErrorttype(R?RG((s /usr/lib64/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 /usr/lib64/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 R R R}RHRRD(R?R_R…R\RG((s /usr/lib64/python2.7/plistlib.pyRxs   cCs<|jdƒx|D]}|j|ƒqW|jdƒdS(Ntarray(RCRRD(R?R‡RG((s /usr/lib64/python2.7/plistlib.pyR|s  (RKRLR@RRyRxR|(((s /usr/lib64/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 /usr/lib64/python2.7/plistlib.pyt __getattr__)s   cCs.ddlm}|dtdƒ|||3s<         $   =