U /^zc @s:dddddddddd d d d g Zd dlZd dlZd dlZd dlZd dlZd dlmZd dlZd dl Z d dl Z d dl Z d dl m Z d dlmZejddedZeejejddZddZddZddZddZGdddZGdd d ZdZe dZ dKd 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)Gd/d0d0e)Z*d1d2Z+Gd3dde,Z-d4d5d6d7d8Z.e/Z0Gd9d:d:Z1d;d<Z2e3e4e5eje6fZ7Gd=d>d>e/Z8d?d@Z9e:e;e+e(e*dAeddBe;dCdEd Z?e:dBdFdGdHd Z@e:dFdBdIdJd ZAdS)L 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)Nz8The readPlist function is deprecated, use load() insteadZrbFfmtuse_builtin_types)rDeprecationWarningrr)rrrrrrYs  c Cs8tdtdt|d}t||tdddW5QRXdS)Nz9The writePlist function is deprecated, use dump() insteadrZwbTFr sort_keysskipkeys)rrrr r)valuerrrrrrfs  cCstdtdtt|dddS)NzBThe readPlistFromBytes function is deprecated, use loads() insteadrFr)rrrrdatarrrrss cCs,tdtdt}t||tddd|S)NzAThe writePlistToBytes function is deprecated, use dumps() insteadrTFr)rrrr rgetvalue)r"frrrr~sc@s:eZdZddZeddZd ddZdd Zd d Zd S)rcCst|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__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+rFr=rGr6rHrrrrr 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)rrrOZ a2b_base64encode)rQrrrr,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 groupdictrNrDdatetime)rQZorderZgdZlstkeyZvalrrr_date_from_stringsrYcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZrU)drrr_date_to_stringsr[cCsZt|}|dk rtd|dd}|dd}|dd}|dd}|d d }|S) Nzz>)_controlCharPatZsearchrEreplace)Ztextmrrr_escapes      r`c@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 ParseFilerd)r*Zfileobjrrrparses     z_PlistParser.parsecCs*g|_t|d|d}|dk r&||dS)NZbegin_)r$getattr)r*elementattrshandlerrrrrj#sz!_PlistParser.handle_begin_elementcCs"t|d|d}|dk r|dS)NZend_)rn)r*rorqrrrrk)sz_PlistParser.handle_end_elementcCs|j|dSr)r$rNr)rrrrl.r2z_PlistParser.handle_datacCs|jdk rFt|jdtis.td|jj||jd|j<d|_nB|jsT||_n4t|jdtgsxtd|jj|jd|dS)Nzunexpected element at line %d) rcrrbtyperEriCurrentLineNumberrdrNr*r"rrr add_object1s z_PlistParser.add_objectcCsd|j}g|_|S)NZ)rPr$r)rrrget_dataAs z_PlistParser.get_datacCs"|}|||j|dSr)rfrvrbrN)r*rprZrrr begin_dictHs z_PlistParser.begin_dictcCs*|jrtd|j|jjf|jdS)Nz%missing value for key '%s' at line %d)rcrErirtrbpopr<rrrend_dictMs  z_PlistParser.end_dictcCs8|jst|jdtis*td|jj||_dS)Nrrzunexpected key at line %d)rcrrbrsrErirtrwr<rrrend_keySs z_PlistParser.end_keycCsg}|||j|dSr)rvrbrN)r*rpZarrr begin_arrayYs z_PlistParser.begin_arraycCs|jdSr)rbryr<rrr end_array^r2z_PlistParser.end_arraycC|ddS)NTrvr<rrrend_truear2z_PlistParser.end_truecCr~)NFrr<rrr end_falsedr2z_PlistParser.end_falsecC|t|dSr)rvrDrwr<rrr end_integergr2z_PlistParser.end_integercCrr)rvfloatrwr<rrrend_realjr2z_PlistParser.end_realcCs||dSr)rvrwr<rrr end_stringmr2z_PlistParser.end_stringcCs2|jr|t|n|t|dSr)rervr,rwrr-r<rrrend_datapsz_PlistParser.end_datacCrr)rvrYrwr<rrrend_datewr2z_PlistParser.end_dateN)r:r?r@r+rmrjrkrlrvrwrxrzr{r|r}rrrrrrrrrrrras&rac@s8eZdZdddZddZddZdd d Zd d Zd S)_DumbXMLWriterr  cCs||_g|_||_||_dSr)filerb _indent_levelindent)r*r indent_levelrrrrr+|sz_DumbXMLWriter.__init__cCs,|j||d||jd7_dS)Nz<%s>)rbrNwritelnrr*rorrr 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/>)r`r)r*ror"rrrsimple_elementsz_DumbXMLWriter.simple_elementcCsH|r8t|tr|d}|j|j|j|j||jddS)NrS )rrrTrwriterr)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_valuerurrrrs  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) NZstringTZtrueFZfalselrBZintegerz%dZrealZdatezunsupported type: %s)rrrrD OverflowErrorrr;dict write_dictr write_datar' bytearray write_bytesrWr[tuplelist write_arrayr(rsrurrrrs.           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) rrZmaxrMrr^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 stringsrX) rrsorteditemsrrrr(rrr)r*rZrrXr"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_ENDreadrMrstructunpack _ref_size _read_ints_object_offsets _undefined_objects _read_objectZOSErrorZ IndexErrorerrorrZUnicodeDecodeError)r*rtrailer offset_size num_objects top_objectoffset_table_offsetrrrrm:s*        z_BinaryPlistParser.parsecCsL|dkrH|jddd@}d|>}dt|}t||j|dS|S)Nrr rJr\)rr_BINARY_FORMATrr)r*tokenLr_rQr&rrr _get_sizeSs  z_BinaryPlistParser._get_sizecsr|j|tkr0tdt|SrDt|krJttfddtd|DSdS)Nr\c3s&|]}t||dVqdS)bigN)rD from_bytes).0rRr$sizerr dsz0_BinaryPlistParser._read_ints..r ) rrrrrrMrrrL)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)!Nrr irrFi TrKrrrJZsignedi"z>frI#z>d3)Zseconds@Pr`rutf-16bec3s|]}|VqdSr)r)rZxr<rrrsz2_BinaryPlistParser._read_object..)rrrrrrrDrrrrWZ timedeltarrerrr rZextendrfZziprr) r*refZresultZoffsettokenZtokenHrr&rQZobj_refsZkey_refskorr<rrjsv                         z_BinaryPlistParser._read_objectN) r:r?r@r+rmrrrrrrrrr.s   rcCs0|dkr dS|dkrdS|d>d>r(dSdSdS)NrrrrIrr)Zcountrrr_count_to_sizes rc@rA)_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_flattenrMrrrr _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_scalarsrsrrr$idrrMrrNrrrrrrr( itertoolsZchainrrr) r*r"ZrefnumZkeysvaluesrrvrrrrr sB           z_BinaryPlistWriter._flattencCsNt|tr|jt||fSt|tr<|jt|j|jfS|jt|SdSr)rrrrsrr$rrrurrrr: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>BQrBsrrz>BdrrrrrrrrrrrCriiicsg|]}|qSr)r)rrr<rrZ sz4_BinaryPlistWriter._write_object..rr\rr)$rrrrrrrDrrrrZto_bytesrrWZ total_secondsrrrMr$r'rrrTZUnicodeEncodeErrorr rErrrrrrrrr(rN) r*r"rr&ZtZrefsrQZkeyRefsZvalRefsZ rootItemsrrrr<rrRs                    $     "$z _BinaryPlistWriter._write_objectN) r:r?r@r+rrrrrrrrrrs -0rcCs|dddkS)Nrrr)rrrr_is_fmt_binaryr2r)detectriwriterTrrrhcCsl|dkrJ|d}|dtD]}|d|r$|d}qVq$tn t|d}|||d}||S)Nrr rri)rrh)rr_FORMATSrrrm)rrrrhrZinfoZPZprrrrs      cCst|}t||||dS)Nr)rr)r"rrrhrrrrr sFrcCs:|tkrtd|ft|d|||d}||dS)NzUnsupported format: %rr)r r!)rrEr)r"rrr r!rrrrr srr!r cCs t}t|||||d|S)Nr)rr r%)r"rr!r rrrrr sr>)BZ__all__rOrZ contextlibrWZenumZiorrrZrerZwarningsrZxml.parsers.expatrZEnumr:rZglobalsZupdateZ __members__Zcontextmanagerrrrrrrr rZcompiler]r/r,ZASCIIrVrYr[r`rarrrrErrZobjectrrrrrDrr'rrrrrrrrr r r rrrrZ1s         '"    h&d! a