U /^z @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)modulec cs2t|tr(t|| }|VW5QRXn|VdSN) isinstancestropen) pathOrFilemodefpr /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() insteadrbNFfmtuse_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() insteadrwbTFr! sort_keysskipkeysN)rr#rr 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 )rr#r rdatarrrrss 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%)rr#rr 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)clsr*rrr fromBase64szData.fromBase64LcCs t|j|Sr)_encode_base64r*)r0 maxlinelengthrrrasBase64sz Data.asBase64cCs4t||jr|j|jkSt|tr,|j|kStSdSr)r __class__r*r-NotImplementedr0otherrrr__eq__s     z Data.__eq__cCsd|jjt|jfSNz%s(%s)r9__name__reprr*r0rrr__repr__sz Data.__repr__N)r5) r@ __module__ __qualname____doc__r1 classmethodr4r8r=rCrrrrrs  c@s<eZdZddZddZddZddZd d Zd d Zd S)r cCs<t|tstd|dkr"td|dkr2td||_dS)Nzdata must be an intzUIDs cannot be >= 2**64rUIDs must be positive)rintr. ValueErrorr*r/rrrr1s z UID.__init__cCs|jSrr)rBrrr __index__sz UID.__index__cCsd|jjt|jfSr>r?rBrrrrCsz UID.__repr__cCs|j|jffSr)r9r*rBrrr __reduce__szUID.__reduce__cCst|tstS|j|jkSr)rr r:r*r;rrrr=s z UID.__eq__cCs t|jSr)hashr*rBrrr__hash__sz UID.__hash__N) r@rDrEr1rLrCrMr=rOrrrrr 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]r5cCsP|dd}g}tdt||D]$}||||}|t|q d|S)Nr)rangelenappendbinasciiZ b2a_base64join)sr7Z maxbinsizepiecesichunkrrrr6s  r6cCs(t|trt|dSt|SdS)Nutf-8)rrrVZ a2b_base64encode)rXrrrr2s r2z{(?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)NZyearZmonthZdayZhourZminutesecond) _dateParsermatch groupdictrUrJdatetime)rXordergdZlstkeyvalrrr_date_from_stringsrhcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZr^)drrr_date_to_stringsrjcCsZt|}|dk rtd|dd}|dd}|dd}|dd}|d d }|S) Nzz>)_controlCharPatsearchrKreplace)textmrrr_escapes      ruc@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_typer0r" dict_typerrrr1s z_PlistParser.__init__cCs8t|_|j|j_|j|j_|j|j_|j||j Sr) rparserhandle_begin_elementZStartElementHandlerhandle_end_elementZEndElementHandler handle_dataZCharacterDataHandlerZ ParseFilery)r0fileobjrrrparses     z_PlistParser.parsecCs*g|_t|d|d}|dk r&||dS)NZbegin_)r*getattr)r0elementattrshandlerrrrr#sz!_PlistParser.handle_begin_elementcCs"t|d|d}|dk r|dS)NZend_)r)r0rrrrrr)sz_PlistParser.handle_end_elementcCs|j|dSr)r*rUr/rrrr.sz_PlistParser.handle_datacCs|jdk rFt|jdtis.td|jj||jd|j<d|_nB|jsT||_n4t|jdtgsxtd|jj|jd|dS)Nzunexpected element at line %d) rxrrwtyperKr~CurrentLineNumberryrUr0r(rrr add_object1s z_PlistParser.add_objectcCsd|j}g|_|S)N)rWr*r/rrrget_dataAs z_PlistParser.get_datacCs"|}|||j|dSr)r{rrwrU)r0rrirrr begin_dictHs z_PlistParser.begin_dictcCs*|jrtd|j|jjf|jdS)Nz%missing value for key '%s' at line %d)rxrKr~rrwpoprBrrrend_dictMs  z_PlistParser.end_dictcCs8|jst|jdtis*td|jj||_dS)Nrzunexpected key at line %d)rxrrwrrKr~rrrBrrrend_keySs z_PlistParser.end_keycCsg}|||j|dSr)rrwrU)r0rarrr begin_arrayYs z_PlistParser.begin_arraycCs|jdSr)rwrrBrrr end_array^sz_PlistParser.end_arraycCs|ddS)NTrrBrrrend_trueasz_PlistParser.end_truecCs|ddS)NFrrBrrr end_falsedsz_PlistParser.end_falsecCs|t|dSr)rrJrrBrrr end_integergsz_PlistParser.end_integercCs|t|dSr)rfloatrrBrrrend_realjsz_PlistParser.end_realcCs||dSr)rrrBrrr end_stringmsz_PlistParser.end_stringcCs2|jr|t|n|t|dSr)rzrr2rrr4rBrrrend_datapsz_PlistParser.end_datacCs|t|dSr)rrhrrBrrrend_datewsz_PlistParser.end_dateN)r@rDrEr1rrrrrrrrrrrrrrrrrrrrrrrvs&rvc@s8eZdZdddZddZddZdd d Zd d Zd S)_DumbXMLWriterr cCs||_g|_||_||_dSr)filerw _indent_levelindent)r0r indent_levelrrrrr1|sz_DumbXMLWriter.__init__cCs,|j||d||jd7_dS)Nz<%s>)rwrUwritelnrr0rrrr 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/>)rur)r0rr(rrrsimple_elementsz_DumbXMLWriter.simple_elementcCsH|r8t|tr|d}|j|j|j|j||jddS)Nr\ )rrr]rwriterr)r0linerrrrs    z_DumbXMLWriter.writeln)rr)N)r@rDrEr1rrrrrrrrr{s   rc@sFeZdZdddZdd Zd d Zd d ZddZddZddZ dS) _PlistWriterr rTFcCs.|r|tt||||||_||_dSr)r PLISTHEADERrr1 _sort_keys _skipkeys)r0rrrZ writeHeaderr&r'rrrr1s  z_PlistWriter.__init__cCs"|d|||ddS)Nzz)r write_valuerrrrrs  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) NstringTtrueFZfalselrHZintegerz%drealdatezunsupported type: %s)rrrrJ OverflowErrorrrAdict write_dictr write_datar- bytearray write_bytesrcrjtuplelist write_arrayr.rrrrrrs.           z_PlistWriter.write_valuecCs||jdSr)rr*r/rrrrsz_PlistWriter.write_datacCsz|d|jd8_tddt|jdd|j}t||dD]}|rJ||qJ|jd7_| ddS)Nr*rr5rs r) rrmaxrTrrrr6splitrr)r0r*r7rrrrrs  z_PlistWriter.write_bytescCs|rt|d|jr"t|}n|}|D]8\}}t|tsP|jrHq.td|d|| |q.| dn |ddS)Nrkeys must be stringsrf) rrsorteditemsrrrr.rrr)r0rirrfr(rrrrs      z_PlistWriter.write_dictcCs<|r.|d|D]}||q|dn |ddS)Narray)rrrr)r0rr(rrrrs    z_PlistWriter.write_arrayN)rrrTF) r@rDrEr1rrrrrrrrrrrs % rcCsd}|D]}||rdSqtjdftjdftjdffD]N\}}||sNq:|D]4}||d|}|dt||krRdSqRq:dS)N)s6xBBQQQ)_fpseekosSEEK_ENDreadrTrstructunpack _ref_size _read_ints_object_offsets _undefined_objects _read_objectOSError IndexErrorerrorrUnicodeDecodeError)r0rtrailer offset_size num_objects top_objectoffset_table_offsetrrrr:s*        z_BinaryPlistParser.parsecCsL|dkrH|jddd@}d|>}dt|}t||j|dS|S)z$ return the size of the next object.rrrQro)rr_BINARY_FORMATrr)r0tokenLrtrXr,rrr _get_sizeSs  z_BinaryPlistParser._get_sizecsr|j|tkr0tdt|SrDt|krJttfddtd|DSdS)Nroc3s&|]}t||dVqdS)bigN)rJ from_bytes).0rZr*sizerr dsz0_BinaryPlistParser._read_ints..r) rrrrrrTrrrS)r0nrrrrr]sz_BinaryPlistParser._read_intscCs|||jSr)rr)r0rrrr _read_refsgsz_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) rrrNrF TrRrrrQsigned"z>frP#z>d3)Zseconds@Pr`rutf-16bec3s|]}|VqdSr)r)rxrBrrrsz2_BinaryPlistParser._read_object..)rrrrrrrJrrrrcZ timedeltarrzrrr rextendr{ziprr) r0refresultoffsettokenZtokenHrr,rXZobj_refsZkey_refskorrBrrjsv                         z_BinaryPlistParser._read_objectN) r@rDrErFr1rrrrrrrrrr.s  rcCs0|dkr dS|dkrdS|d>d>r(dSdSdS)NrrrrPrr)countrrr_count_to_sizes rc@s<eZdZddZddZddZddZd d Zd d Zd S)_BinaryPlistWritercCs||_||_||_dSr)rrr)r0rr&r'rrrr1sz_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)Nrbplist00ro >5xBBBQQQ)r)_objlist _objtable _objidtable_flattenrTrrrr _ref_formatrr _write_object _getrefnumtellrpack) r0r(robjrrrZ 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_scalarsrr rr*idr!rTrrUrrrrrrr. itertoolschainr"rr) r0r(Zrefnumkeysvaluesrrvrrrrr" sB           z_BinaryPlistWriter._flattencCsNt|tr|jt||fSt|tr<|jt|j|jfS|jt|SdSr)rr)r rrr*r!r*rrrrr%: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')r0rrrrr _write_sizeBsz_BinaryPlistWriter._write_sizec s|}jj|<|dkr2jdnl|dkrJjdnT|dkrbjdnBqr3rz>BBrrz>BHr0r1z>BLr2lz>BQrHrrz>Bdrrrrrrr r r rrIr csg|]}|qSr)r%)rrrBrr sz4_BinaryPlistWriter._write_object..r rorr)$r%rr&rrrrJrr'rrto_bytesrrcZ total_secondsrr4rTr*r-rrr]UnicodeEncodeErrorr rKrrr#rrrrrr.rU) r0r(rr,tZrefsrXZkeyRefsZvalRefsZ rootItemsrr/rrBrr$Rs                    $     "$z _BinaryPlistWriter._write_objectN) r@rDrEr1rr"r%r4r$rrrrrs -0rcCs|dddkS)Nrrr)rrrr_is_fmt_binarysr?)detectr~writerTr!r"r}cCsl|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). Nrrr@r~)r"r})rr_FORMATSr.rr)rr!r"r}rinfoPprrrr s      cCst|}t||||dS)zqRead a .plist file from a bytes object. Return the unpacked root object (which usually is a dictionary). rB)rr )r(r!r"r}rrrrr sFr%cCs:|tkrtd|ft|d|||d}||dS)zWWrite 'value' to a .plist file. 'fp' should be a writable, binary file object. zUnsupported format: %rrA)r&r'N)rCrKr)r(rr!r&r'rArrrr sr!r'r&cCs t}t|||||d|S)z?Return a bytes object with the contents for a .plist file. rG)rr r+)r(r!r'r&rrrrr s)r5)CrF__all__rVr contextlibrcenumiorr+rrerwarningsrZxml.parsers.expatrEnumr@rglobalsupdate __members__contextmanagerrrrrrrr rcompilerpr6r2ASCIIr`rhrjrurvrrrrKrrobjectrrrrrJrr-r)rr?rrrrCr r r r rrrrs0         '"    h&d! a