U /^zc @s>dZddddddddd d d d d g ZddlZddlZddlZddlZddlZddlmZddl Z ddl Z ddl Z ddl Z ddl mZddlmZejddedZeejejddZddZddZddZddZGdddZGdd d ZdZe dZ!dLd!d"Z"d#d$Z#e d%e j$Z%d&d'Z&d(d)Z'd*d+Z(Gd,d-d-Z)Gd.d/d/Z*Gd0d1d1e*Z+d2d3Z,Gd4dde-Z.d5d6d7d8d9Z/e0Z1Gd:d;d;Z2dd?d?e0Z9d@dAZ:e;eddCe", someMoreData = b"" * 10, aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())), ) with open(fileName, 'wb') as fp: dump(pl, fp) Parse Plist example: with open(fileName, 'rb') as fp: pl = load(fp) print(pl["aKey"]) readPlist writePlistreadPlistFromByteswritePlistToBytesDataInvalidFileExceptionFMT_XML FMT_BINARYloaddumploadsdumpsUIDN)BytesIO)warn) ParserCreate PlistFormatzFMT_XML FMT_BINARY)Zmodulec cs2t|tr(t|| }|VW5QRXn|VdSN) isinstancestrZopen) pathOrFileZmodefpr /usr/lib64/python3.8/plistlib.py _maybe_openOs  rc Cs<tdtdt|d}t|dddW5QRSQRXdS)z Read a .plist from a path or file. pathOrFile should either be a file name, or a readable binary file object. This function is deprecated, use load instead. z8The readPlist function is deprecated, use load() insteadZrbNFfmtuse_builtin_types)rDeprecationWarningrr)rrrrrrYs  c Cs8tdtdt|d}t||tdddW5QRXdS)z Write 'value' to a .plist file. 'pathOrFile' may either be a file name or a (writable) file object. This function is deprecated, use dump instead. z9The writePlist function is deprecated, use dump() insteadrZwbTFr sort_keysskipkeysN)rrrr r)valuerrrrrrfs  cCstdtdtt|dddS)z} Read a plist data from a bytes object. Return the root object. This function is deprecated, use loads instead. zBThe readPlistFromBytes function is deprecated, use loads() insteadrNFr)rrrrdatarrrrss cCs,tdtdt}t||tddd|S)zp Return 'value' as a plist-formatted bytes object. This function is deprecated, use dumps instead. zAThe writePlistToBytes function is deprecated, use dumps() insteadrTFr)rrrr rgetvalue)r"frrrr~sc@s>eZdZdZddZeddZdddZd d Zd d Z d S)rz] Wrapper for binary data. This class is deprecated, use a bytes object instead. cCst|tstd||_dS)Nzdata must be as bytes)rbytes TypeErrorr$selfr$rrr__init__s z Data.__init__cCs |t|Sr)_decode_base64)Zclsr$rrr fromBase64szData.fromBase64LcCs t|j|Sr)_encode_base64r$)r* maxlinelengthrrrasBase64z Data.asBase64cCs4t||jr|j|jkSt|tr,|j|kStSdSr)r __class__r$r'NotImplementedr*Zotherrrr__eq__s     z Data.__eq__cCd|jjt|jfSNz%s(%s)r3__name__reprr$r*rrr__repr__r2z Data.__repr__Nr.) r: __module__ __qualname____doc__r+Z classmethodr-r1r6r=rrrrrs  c@<eZdZddZddZddZddZd d Zd d Zd S)r cCs<t|tstd|dkr"td|dkr2td||_dS)Nzdata must be an intzUIDs cannot be >= 2**64r UIDs must be positive)rintr( ValueErrorr$r)rrrr+s z UID.__init__cCs|jSrr#r<rrr __index__r2z UID.__index__cCr7r8r9r<rrrr=r2z UID.__repr__cCs|j|jffSr)r3r$r<rrr __reduce__r2zUID.__reduce__cCst|tstS|j|jkSr)rr r4r$r5rrrr6s z UID.__eq__cCs t|jSr)Zhashr$r<rrr__hash__r2z UID.__hash__N) r:r?r@r+rGr=rHr6rIrrrrr s  s zv[\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]r.cCsP|dd}g}tdt||D]$}||||}|t|q d|S)Nr )rangelenappendbinasciiZ b2a_base64join)sr0Z maxbinsizeZpiecesiZchunkrrrr/s  r/cCs(t|trt|dSt|SdS)Nutf-8)rrrPZ a2b_base64encode)rRrrrr,s r,z{(?P\d\d\d\d)(?:-(?P\d\d)(?:-(?P\d\d)(?:T(?P\d\d)(?::(?P\d\d)(?::(?P\d\d))?)?)?)?)?ZcCsLd}t|}g}|D]&}||}|dkr2qB|t|qtj|S)NZyearZmonthZdayZhourZminuteZsecond) _dateParserZmatchZ groupdictrOrEdatetime)rRZorderZgdZlstkeyZvalrrr_date_from_stringsrZcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZrV)drrr_date_to_stringsr\cCsZt|}|dk rtd|dd}|dd}|dd}|dd}|d d }|S) Nzz>)_controlCharPatZsearchrFreplace)Ztextmrrr_escapes      rac@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'S)( _PlistParsercCs"g|_d|_d|_||_||_dSr)stack current_keyroot_use_builtin_types _dict_typer*r dict_typerrrr+s z_PlistParser.__init__cCs8t|_|j|j_|j|j_|j|j_|j||j Sr) rparserhandle_begin_elementZStartElementHandlerhandle_end_elementZEndElementHandler handle_dataZCharacterDataHandlerZ ParseFilere)r*Zfileobjrrrparses     z_PlistParser.parsecCs*g|_t|d|d}|dk r&||dS)NZbegin_)r$getattr)r*elementattrshandlerrrrrk#sz!_PlistParser.handle_begin_elementcCs"t|d|d}|dk r|dS)NZend_)ro)r*rprrrrrrl)sz_PlistParser.handle_end_elementcCs|j|dSr)r$rOr)rrrrm.r2z_PlistParser.handle_datacCs|jdk rFt|jdtis.td|jj||jd|j<d|_nB|jsT||_n4t|jdtgsxtd|jj|jd|dS)Nzunexpected element at line %d) rdrrctyperFrjCurrentLineNumberrerOr*r"rrr add_object1s z_PlistParser.add_objectcCsd|j}g|_|S)NZ)rQr$r)rrrget_dataAs z_PlistParser.get_datacCs"|}|||j|dSr)rgrwrcrO)r*rqr[rrr begin_dictHs z_PlistParser.begin_dictcCs*|jrtd|j|jjf|jdS)Nz%missing value for key '%s' at line %d)rdrFrjrurcpopr<rrrend_dictMs  z_PlistParser.end_dictcCs8|jst|jdtis*td|jj||_dS)Nrszunexpected key at line %d)rdrrcrtrFrjrurxr<rrrend_keySs z_PlistParser.end_keycCsg}|||j|dSr)rwrcrO)r*rqZarrr begin_arrayYs z_PlistParser.begin_arraycCs|jdSr)rcrzr<rrr end_array^r2z_PlistParser.end_arraycC|ddS)NTrwr<rrrend_truear2z_PlistParser.end_truecCr)NFrr<rrr end_falsedr2z_PlistParser.end_falsecC|t|dSr)rwrErxr<rrr end_integergr2z_PlistParser.end_integercCrr)rwfloatrxr<rrrend_realjr2z_PlistParser.end_realcCs||dSr)rwrxr<rrr end_stringmr2z_PlistParser.end_stringcCs2|jr|t|n|t|dSr)rfrwr,rxrr-r<rrrend_datapsz_PlistParser.end_datacCrr)rwrZrxr<rrrend_datewr2z_PlistParser.end_dateN)r:r?r@r+rnrkrlrmrwrxryr{r|r}r~rrrrrrrrrrrrbs&rbc@s8eZdZdddZddZddZdd d Zd d Zd S)_DumbXMLWriterr  cCs||_g|_||_||_dSr)filerc _indent_levelindent)r*r indent_levelrrrrr+|sz_DumbXMLWriter.__init__cCs,|j||d||jd7_dS)Nz<%s>)rcrOwritelnrr*rprrr begin_elements z_DumbXMLWriter.begin_elementcCs |jd8_|d|dS)Nrz)rrrrrr end_elementsz_DumbXMLWriter.end_elementNcCs8|dk r&t|}|d|||fn|d|dS)Nz <%s>%sz<%s/>)rar)r*rpr"rrrsimple_elementsz_DumbXMLWriter.simple_elementcCsH|r8t|tr|d}|j|j|j|j||jddS)NrT )rrrUrwriterr)r*linerrrrs    z_DumbXMLWriter.writeln)r rr)r:r?r@r+rrrrrrrrr{s   rc@sFeZdZdddZdd Zd d Zd d ZddZddZddZ dS) _PlistWriterr  rTFcCs.|r|tt||||||_||_dSr)r PLISTHEADERrr+ _sort_keys _skipkeys)r*rrrZ writeHeaderr r!rrrr+s  z_PlistWriter.__init__cCs"|d|||ddS)Nzz)r write_valuervrrrrs  z_PlistWriter.writecCs4t|tr|d|n|dkr0|dn|dkrD|dnt|trd|krbdkrxnn|dd |nt|nt|tr|d t|nt|tr||n|t|t r| |nft|t t fr| |nLt|tjr|d t|n,t|ttfr ||ntd t|dS) NZstringTZtrueFZfalselrCZintegerz%dZrealZdatezunsupported type: %s)rrrrE OverflowErrorrr;dict write_dictr write_datar' bytearray write_bytesrXr\tuplelist write_arrayr(rtrvrrrrs.           z_PlistWriter.write_valuecCs||jdSr)rr$r)rrrrr2z_PlistWriter.write_datacCsz|d|jd8_tddt|jdd|j}t||dD]}|rJ||qJ|jd7_| ddS)Nr$rr.rs r) rrZmaxrNrr_r/Zsplitrr)r*r$r0rrrrrs  z_PlistWriter.write_bytescCs|rt|d|jr"t|}n|}|D]8\}}t|tsP|jrHq.td|d|| |q.| dn |ddS)Nrkeys must be stringsrY) rrsorteditemsrrrr(rrr)r*r[rrYr"rrrrs      z_PlistWriter.write_dictcCs<|r.|d|D]}||q|dn |ddS)Narray)rrrr)r*rr"rrrrs    z_PlistWriter.write_arrayN)r rrTF) r:r?r@r+rrrrrrrrrrrs % rcCsd}|D]}||rdSqtjdftjdftjdffD]N\}}||sNq:|D]4}||d|}|dt||krRdSqRq:dS)N)s6xBBQQQ)_fpseekosZSEEK_ENDreadrNrstructunpack _ref_size _read_ints_object_offsets _undefined_objects _read_objectZOSErrorZ IndexErrorerrorrZUnicodeDecodeError)r*rtrailer offset_size num_objects top_objectoffset_table_offsetrrrrn:s*        z_BinaryPlistParser.parsecCsL|dkrH|jddd@}d|>}dt|}t||j|dS|S)z$ return the size of the next object.rr rKr])rr_BINARY_FORMATrr)r*tokenLr`rRr&rrr _get_sizeSs  z_BinaryPlistParser._get_sizecsr|j|tkr0tdt|SrDt|krJttfddtd|DSdS)Nr]c3s&|]}t||dVqdS)bigN)rE from_bytes).0rSr$sizerr dsz0_BinaryPlistParser._read_ints..r ) rrrrrrNrrrM)r*nrrrrr]sz_BinaryPlistParser._read_intscCs|||jSr)rr)r*rrrr _read_refsgr2z_BinaryPlistParser._read_refsc sj|}|tk r|Sj|}j|jdd}|d@|d@}}|dkr^d}nT|dkrnd}nD|dkr~d }n4|dkrd }n$|d krtjjd|>d |d kd}n|dkrt djdd}n|dkrt djdd}n|dkrDt djdd}t dddt j |d}nn|dkr |}j rnj|}ntj|}n0|dkr |}j|d}n|dkr؈ |}j|dd}n|dkrttjd|d }n|dkrF |}|} g}|j|<|fdd | Dnl|d!kr |}|} |} }|j|<t| | D]\} } | || <qnt|j|<|S)"zx read the object by reference. May recursively read sub-objects (content of an array/dict/set) rr irNrFi TrLrrrKZsignedi"z>frJ#z>d3)Zseconds@Pr`rutf-16bec3s|]}|VqdSr)r)rZxr<rrrsz2_BinaryPlistParser._read_object..)rrrrrrrErrrrXZ timedeltarrfrrr rZextendrgZziprr) r*refZresultZoffsettokenZtokenHrr&rRZobj_refsZkey_refskorr<rrjsv                         z_BinaryPlistParser._read_objectN) r:r?r@rAr+rnrrrrrrrrr.s  rcCs0|dkr dS|dkrdS|d>d>r(dSdSdS)NrrrrJrr)Zcountrrr_count_to_sizes rc@rB)_BinaryPlistWritercCs||_||_||_dSr)rrr)r*rr r!rrrr+sz_BinaryPlistWriter.__init__c Csg|_i|_i|_||t|j}dg||_t||_t|j|_ |j d|jD]}| |qZ| |}|j }t|}dt||}|j tj|f|jd}|||j|||f} |j tjd| dS)Nr bplist00r] >5xBBBQQQ)r)_objlist _objtable _objidtable_flattenrNrrrr _ref_formatrr _write_object _getrefnumtellrpack) r*r"rZobjrrrZ offset_formatZ sort_versionrrrrrs2          z_BinaryPlistWriter.writec Csrt|tr"t||f|jkrZdSn8t|trHt|j|jf|jkrZdSnt||jkrZdSt|j }|j |t|tr||jt||f<n0t|tr||jt|j|jf<n||jt|<t|t rHg}g}| }|j rt|}|D]:\}}t|ts|jr qtd| || |qt||D]}||q4n&t|ttfrn|D]}||q\dS)Nr)r_scalarsrtrrr$idrrNrrOrrrrrrr( itertoolsZchainrrr) r*r"ZrefnumZkeysvaluesrrvrrrrr sB           z_BinaryPlistWriter._flattencCsNt|tr|jt||fSt|tr<|jt|j|jfS|jt|SdSr)rrrrtrr$rrrvrrrr:s   z_BinaryPlistWriter._getrefnumcCs|dkr"|jtd||Bn|dkrH|jtd|dBd|nh|dkrn|jtd|dBd|nB|d kr|jtd |dBd |n|jtd |dBd |dS)Nrz>Brz>BBBrrz>BBHz>BBLz>BBQ)rrrr)r*rrrrr _write_sizeBsz_BinaryPlistWriter._write_sizec s|}jj|<|dkr2jdnl|dkrJjdnT|dkrbjdnBqrrz>BBrrz>BHrrz>BLrlz>BQrCsrrz>BdrrrrrrrrrrrDriiicsg|]}|qSr)r)rrr<rrZ sz4_BinaryPlistWriter._write_object..rr]rr)$rrrrrrrErrrrZto_bytesrrXZ total_secondsrrrNr$r'rrrUZUnicodeEncodeErrorr rFrrrrrrrrr(rO) r*r"rr&ZtZrefsrRZkeyRefsZvalRefsZ rootItemsrrrr<rrRs                    $     "$z _BinaryPlistWriter._write_objectN) r:r?r@r+rrrrrrrrrrs -0rcCs|dddkS)Nrrr)rrrr_is_fmt_binaryr2r)detectrjwriterTrrricCsl|dkrJ|d}|dtD]}|d|r$|d}qVq$tn t|d}|||d}||S)zRead a .plist file. 'fp' should be a readable and binary file object. Return the unpacked root object (which usually is a dictionary). Nrr rrj)rri)rr_FORMATSrrrn)rrrrirZinfoZPZprrrrs      cCst|}t||||dS)zqRead a .plist file from a bytes object. Return the unpacked root object (which usually is a dictionary). r)rr)r"rrrirrrrr sFrcCs:|tkrtd|ft|d|||d}||dS)zWWrite 'value' to a .plist file. 'fp' should be a writable, binary file object. zUnsupported format: %rr)r r!N)rrFr)r"rrr r!rrrrr srr!r cCs t}t|||||d|S)z?Return a bytes object with the contents for a .plist file. r)rr r%)r"rr!r rrrrr sr>)CrAZ__all__rPrZ contextlibrXZenumZiorrrZrerZwarningsrZxml.parsers.expatrZEnumr:rZglobalsZupdateZ __members__Zcontextmanagerrrrrrrr rZcompiler^r/r,ZASCIIrWrZr\rarbrrrrFrrZobjectrrrrrErr'rrrrrrrrr r r rrrrZs0         '"    h&d! a