usr/lib64/python2.7/plistlib.pyc000064400000046773147204505100012423 0ustar00 zfc @sdZddddddddd g Zd d lZd d lZd d lmZd d lZd d lZd ZdZ dZ dZ dddZ dddZ dd*dYZejdZdZdZejdZdZdZdefdYZdefd YZd efd!YZdefd"YZd#d$Zdd+d%YZd&efd'YZd(d,d)YZd S(-splistlib.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 writePlisttreadPlistFromStringtwritePlistToStringtreadPlistFromResourcetwritePlistToResourcetPlisttDatatDictiN(tStringIOcCs_d}t|ttfr0t|}d}nt}|j|}|r[|jn|S(sRead 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|ttfr3t|d}d}nt|}|jd|j||jd|ry|jndS(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|||jS(s5Return 'rootObject' as a plist-formatted string. (R Rtgetvalue(Rtf((s /usr/lib64/python2.7/plistlib.pyRjs  tplstic Cstjdddddlm}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 Cstjdddddlm}m}ddlm}ddlm}t |}||} |j | ||} |j | y|j ||j Wn|jk rnX|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.pyRs     t DumbXMLWritercBs>eZdddZdZdZddZdZRS(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 beginElementscCsT|jdkst|jj|ks0t|jd8_|jd|dS(Niis(R=tAssertionErrorR<tpopR(R?RB((s /usr/lib64/python2.7/plistlib.pyt endElementscCsJ|dk r5t|}|jd|||fn|jd|dS(Ns <%s>%ss<%s/>(tNonet_escapeAndEncodeR(R?RBtvalue((s /usr/lib64/python2.7/plistlib.pyt simpleElements  cCs?|r+|jj|j|j|dn|jjddS(Ns (R;twriteR=R>(R?tline((s /usr/lib64/python2.7/plistlib.pyRs%N(t__name__t __module__R@RCRFRGRJR(((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(RORPRQRRRSRT(t _dateParsertmatcht groupdictRGRAtinttdatetime(tstordertgdtlsttkeytval((s /usr/lib64/python2.7/plistlib.pyt_dateFromStrings   cCs,d|j|j|j|j|j|jfS(Ns%04d-%02d-%02dT%02d:%02d:%02dZ(RORPRQRRRSRT(td((s /usr/lib64/python2.7/plistlib.pyt _dateToStringssv[\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]cCstj|}|dk r*tdn|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_controlCharPattsearchRGt ValueErrortreplacetencode(ttexttm((s /usr/lib64/python2.7/plistlib.pyRHs s RcBs>eZddddZdZdZdZdZRS(is icCs0|r|jtntj||||dS(N(RKt PLISTHEADERR:R@(R?R;R=R>t writeHeader((s /usr/lib64/python2.7/plistlib.pyR@scCsYt|ttfr(|jd|n-t|tr]|rM|jdqU|jdnt|ttfr|jdd|nt|tr|jdt|nt|t r|j |nt|t r|j |nft|t j r|jdt|n;t|ttfr?|j|ntdt|dS( Ntstringttruetfalsetintegers%dtrealtdatesunsuported type: %s(R R R RJtboolRXtlongtfloattreprtdictt writeDictRt writeDataRYRbttupletlistt writeArrayt TypeErrorttype(R?RI((s /usr/lib64/python2.7/plistlib.pyRs&cCs|jd|jd8_tddt|jjdd |j}x6|j|jdD]}|rd|j|qdqdW|jd7_|j ddS( NRiiiLs t is s ( RCR=tmaxtlenR>RitasBase64tsplitRRF(R?Rt maxlinelengthRL((s /usr/lib64/python2.7/plistlib.pyR{s cCs|jd|j}|jxU|D]M\}}t|ttfsZtdn|jd||j|q*W|j ddS(NRyskeys must be stringsR^( RCtitemstsortR R R RRJRRF(R?RaRR^RI((s /usr/lib64/python2.7/plistlib.pyRzs   cCs<|jdx|D]}|j|qW|jddS(Ntarray(RCRRF(R?RRI((s /usr/lib64/python2.7/plistlib.pyR~s  (RMRNR@RR{RzR~(((s /usr/lib64/python2.7/plistlib.pyRs   t _InternalDictcBs#eZdZdZdZRS(cCsOy||}Wntk r*t|nXddlm}|dtd|S(Ni(twarnsLAttribute access from plist dicts is deprecated, use d[key] notation insteadi(tKeyErrortAttributeErrorR#RtPendingDeprecationWarning(R?tattrRIR((s /usr/lib64/python2.7/plistlib.pyt __getattr__)s   cCs.ddlm}|dtd|||3s<         $   =