U e5d} @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)rXorderZgdZlstkeyvalrrr_date_from_stringsrgcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZr^)drrr_date_to_stringsricCsZt|}|dk rtd|dd}|dd}|dd}|dd}|d d }|S) Nzz>)_controlCharPatsearchrKreplace)textmrrr_escapes      rtc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"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__cCsBt|_|j|j_|j|j_|j|j_|j|j_ |j ||j Sr) rparserhandle_begin_elementZStartElementHandlerhandle_end_elementZEndElementHandler handle_dataZCharacterDataHandlerhandle_entity_declZEntityDeclHandlerZ ParseFilerx)r0Zfileobjrrrparses     z_PlistParser.parsecCs tddS)Nz8XML entity declarations are not supported in plist files)r)r0Z entity_nameZis_parameter_entityr(baseZ system_idZ public_idZ notation_namerrrr$sz_PlistParser.handle_entity_declcCs*g|_t|d|d}|dk r&||dS)NZbegin_)r*getattr)r0elementattrshandlerrrrr~*sz!_PlistParser.handle_begin_elementcCs"t|d|d}|dk r|dS)NZend_)r)r0rrrrrr0sz_PlistParser.handle_end_elementcCs|j|dSr)r*rUr/rrrr5sz_PlistParser.handle_datacCs|jdk rFt|jdtis.td|jj||jd|j<d|_nB|jsT||_n4t|jdtgsxtd|jj|jd|dS)Nzunexpected element at line %d) rwrrvtyperKr}CurrentLineNumberrxrUr0r(rrr add_object8s z_PlistParser.add_objectcCsd|j}g|_|S)N)rWr*r/rrrget_dataHs z_PlistParser.get_datacCs"|}|||j|dSr)rzrrvrU)r0rrhrrr begin_dictOs z_PlistParser.begin_dictcCs*|jrtd|j|jjf|jdS)Nz%missing value for key '%s' at line %d)rwrKr}rrvpoprBrrrend_dictTs  z_PlistParser.end_dictcCs8|jst|jdtis*td|jj||_dS)Nrzunexpected key at line %d)rwrrvrrKr}rrrBrrrend_keyZs z_PlistParser.end_keycCsg}|||j|dSr)rrvrU)r0rarrr begin_array`s z_PlistParser.begin_arraycCs|jdSr)rvrrBrrr end_arrayesz_PlistParser.end_arraycCs|ddS)NTrrBrrrend_truehsz_PlistParser.end_truecCs|ddS)NFrrBrrr end_falseksz_PlistParser.end_falsecCs@|}|ds|dr.|t|dn|t|dS)NZ0xZ0X)r startswithrrJ)r0rawrrr end_integernsz_PlistParser.end_integercCs|t|dSr)rfloatrrBrrrend_realusz_PlistParser.end_realcCs||dSr)rrrBrrr end_stringxsz_PlistParser.end_stringcCs2|jr|t|n|t|dSr)ryrr2rrr4rBrrrend_data{sz_PlistParser.end_datacCs|t|dSr)rrgrrBrrrend_datesz_PlistParser.end_dateN)r@rDrEr1rrr~rrrrrrrrrrrrrrrrrrrrrus( ruc@s8eZdZdddZddZddZdd d Zd d Zd S)_DumbXMLWriterr cCs||_g|_||_||_dSr)filerv _indent_levelindent)r0r indent_levelrrrrr1sz_DumbXMLWriter.__init__cCs,|j||d||jd7_dS)Nz<%s>)rvrUwritelnrr0rrrr begin_elements z_DumbXMLWriter.begin_elementcCs@|jdkst|j|ks t|jd8_|d|dS)Nrrz)rAssertionErrorrvrrrrrr end_elementsz_DumbXMLWriter.end_elementNcCs8|dk r&t|}|d|||fn|d|dS)Nz <%s>%sz<%s/>)rtr)r0rr(rrrsimple_elementsz_DumbXMLWriter.simple_elementcCsH|r8t|tr|d}|j|j|j|j||jddS)Nr\ )rrr]rwriterr)r0linerrrrs    z_DumbXMLWriter.writeln)rr)N)r@rDrEr1rrrrrrrrrs   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_bytesrcrituplelist 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*rrr5rs r) rrmaxrTrrqr6splitrr)r0r*r7rrrrrs  z_PlistWriter.write_bytescCs|rt|d|jr"t|}n|}|D]8\}}t|tsP|jrHq.td|d|| |q.| dn |ddS)Nrkeys must be stringsre) rrsorteditemsrrrr.rrr)r0rhrrer(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 IndexErrorerrorrrK)r0rtrailer offset_size num_objects top_objectoffset_table_offsetrrrrEs*        z_BinaryPlistParser.parsecCsL|dkrH|jddd@}d|>}dt|}t||j|dS|S)z$ return the size of the next object.rrrQrn)rr_BINARY_FORMATrr)r0tokenLrsrXr,rrr _get_size^s  z_BinaryPlistParser._get_sizecst|j|tkr2td|tSrFt|krLttfddtd|DSdS)Nrnc3s&|]}t||dVqdS)bigN)rJ from_bytes).0rZr*sizerr osz0_BinaryPlistParser._read_ints..r) rrrrrrTrrrS)r0nrrrrrhsz_BinaryPlistParser._read_intscCs|||jSr)rr)r0rrrr _read_refsrsz_BinaryPlistParser._read_refscsj|}|tk r|Sj|}j|jdd}|d@|d@}}|dkr^d}n|dkrnd}n|dkr~d }n|dkrd }n|d krtjjd|>d |d kd}nT|dkrt djdd}n0|dkrt djdd}n |dkrDt djdd}t dddt j |d}n|dkr |}j|}t ||krxtjst|}n|dkrΈ |}j|} t | |krt| d}n@|dkr |d}j|} t | |krt| d}n|dkr:ttjd|d }n|dkr |}|} g}|j|<|fdd | Dn|d!kr |}|} |} }|j|<z.t| | D]\} } | || <qWntk rtYnXnt|j|<|S)"zx read the object by reference. May recursively read sub-objects (content of an array/dict/set) rrrNrF TrRrrrQZsigned"z>frP#z>d3)Zseconds@Pr`rutf-16bec3s|]}|VqdSr)r)rxrBrrrsz2_BinaryPlistParser._read_object..)rrrrrrrJrrrrcZ timedeltarrTrryrrr rextendrzziprr.)r0refresultoffsettokenZtokenHrr,rXr*Zobj_refsZkey_refskorrBrrus                             z_BinaryPlistParser._read_objectN) r@rDrErFr1rrrrrrrrrr9s  rcCs,|dkr dS|dkrdS|dkr$dSdSdS)NrrrPrr)countrrr_count_to_sizesrc@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)Nrbplist00rn >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"rTr rUrrrrrrr. itertoolschainr#rr) r0r(Zrefnumkeysvaluesrrvrrrrr#sB           z_BinaryPlistWriter._flattencCsNt|tr|jt||fSt|tr<|jt|j|jfS|jt|SdSr)rr*r!rrr*r"r+rrrrr&Ns   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>BBHrz>BBLz>BBQ)rrrr()r0rrrrr _write_sizeVsz_BinaryPlistWriter._write_sizec s|}jj|<|dkr2jdnl|dkrJjdnT|dkrbjdnBqr3rz>BBrrz>BHr1rz>BLr2lz>BQrHrrz>Bdrrrrrrr r r rrIr csg|]}|qSr)r&)rrrBrr sz4_BinaryPlistWriter._write_object..r rnrr)$r&rr'rrrrJrr(rrto_bytesrrcZ total_secondsrr4rTr*r-rrr]UnicodeEncodeErrorr rKrrr$rrrrrr.rU) r0r(rr,tZrefsrXZkeyRefsZvalRefsZ rootItemsrr0rrBrr%fs                    $     "$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 rcompileror6r2ASCIIr`rgrirtrurrrrKrrobjectrrrrrJrr-r*rr?rrrrCr r r r rrrrs0         '"    s&d!$ a