U e5d} @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)modulec cs2t|tr(t|| }|VW5QRXn|VdSN) isinstancestropen) pathOrFilemodefpr /usr/lib64/python3.8/plistlib.py _maybe_openOs  rc Cs<tdtdt|d}t|dddW5QRSQRXdS)Nz8The readPlist function is deprecated, use load() insteadrbFfmtuse_builtin_types)rDeprecationWarningrr )rrrrrrYs  c Cs8tdtdt|d}t||tdddW5QRXdS)Nz9The writePlist function is deprecated, use dump() insteadrwbTFr! sort_keysskipkeys)rr#rr r)valuerrrrrrfs  cCstdtdtt|dddS)NzBThe readPlistFromBytes function is deprecated, use loads() insteadrFr )rr#r rdatarrrrss cCs,tdtdt}t||tddd|S)NzAThe writePlistToBytes function is deprecated, use dumps() insteadrTFr%)rr#rr 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)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__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@rDrEr1rKrCrLr=rNrrrrr 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)rrrUZ a2b_base64encode)rWrrrr2s 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 groupdictrTrIdatetime)rWorderZgdZlstkeyvalrrr_date_from_stringsrfcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZr])drrr_date_to_stringsrhcCsZt|}|dk rtd|dd}|dd}|dd}|dd}|d d }|S) Nzz>)_controlCharPatsearchrJreplace)textmrrr_escapes      rsc@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 ParseFilerw)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)r0rrrrrr~0sz_PlistParser.handle_end_elementcCs|j|dSr)r*rTr/rrrr5sz_PlistParser.handle_datacCs|jdk rFt|jdtis.td|jj||jd|j<d|_nB|jsT||_n4t|jdtgsxtd|jj|jd|dS)Nzunexpected element at line %d) rvrrutyperJr|CurrentLineNumberrwrTr0r(rrr add_object8s z_PlistParser.add_objectcCsd|j}g|_|S)N)rVr*r/rrrget_dataHs z_PlistParser.get_datacCs"|}|||j|dSr)ryrrurT)r0rrgrrr begin_dictOs z_PlistParser.begin_dictcCs*|jrtd|j|jjf|jdS)Nz%missing value for key '%s' at line %d)rvrJr|rrupoprBrrrend_dictTs  z_PlistParser.end_dictcCs8|jst|jdtis*td|jj||_dS)Nrzunexpected key at line %d)rvrrurrJr|rrrBrrrend_keyZs z_PlistParser.end_keycCsg}|||j|dSr)rrurT)r0rarrr begin_array`s z_PlistParser.begin_arraycCs|jdSr)rurrBrrr 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 startswithrrI)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)rxrr2rrr4rBrrrend_data{sz_PlistParser.end_datacCs|t|dSr)rrfrrBrrrend_datesz_PlistParser.end_dateN)r@rDrEr1rrr}r~rrrrrrrrrrrrrrrrrrrrts( rtc@s8eZdZdddZddZddZdd d Zd d Zd S)_DumbXMLWriterr cCs||_g|_||_||_dSr)fileru _indent_levelindent)r0r indent_levelrrrrr1sz_DumbXMLWriter.__init__cCs,|j||d||jd7_dS)Nz<%s>)rurTwritelnrr0rrrr 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/>)rsr)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) NstringTtrueFZfalselrGZintegerz%drealdatezunsupported type: %s)rrrrI OverflowErrorrrAdict write_dictr write_datar- bytearray write_bytesrbrhtuplelist 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) rrmaxrSrrpr6splitrr)r0r*r7rrrrrs  z_PlistWriter.write_bytescCs|rt|d|jr"t|}n|}|D]8\}}t|tsP|jrHq.td|d|| |q.| dn |ddS)Nrkeys must be stringsrd) rrsorteditemsrrrr.rrr)r0rgrrdr(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_ENDreadrSrstructunpack _ref_size _read_ints_object_offsets _undefined_objects _read_objectOSError IndexErrorerrorrrJ)r0rtrailer offset_size num_objects top_objectoffset_table_offsetrrrrEs*        z_BinaryPlistParser.parsecCsL|dkrH|jddd@}d|>}dt|}t||j|dS|S)NrrrPrm)rr_BINARY_FORMATrr)r0tokenLrrrWr,rrr _get_size^s  z_BinaryPlistParser._get_sizecst|j|tkr2td|tSrFt|krLttfddtd|DSdS)Nrmc3s&|]}t||dVqdS)bigN)rI from_bytes).0rYr*sizerr osz0_BinaryPlistParser._read_ints..r) rrrrrrSrrrR)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)!NrrrrF TrQrrrPZsigned"z>frO#z>d3)Zseconds@Pr`rutf-16bec3s|]}|VqdSr)r)rxrBrrrsz2_BinaryPlistParser._read_object..)rrrrrrrIrrrrbZ timedeltarrSrrxrrr rextendryziprr.)r0refresultoffsettokenZtokenHrr,rWr*Zobj_refsZkey_refskorrBrrus                             z_BinaryPlistParser._read_objectN) r@rDrEr1rrrrrrrrrr9s   rcCs,|dkr dS|dkrdS|dkr$dSdSdS)NrrrOrr)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)Nrbplist00rm >5xBBBQQQ)r)_objlist _objtable _objidtable_flattenrSrrrr _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_scalarsrrrr*idr rSrrTrrrrrrr. itertoolschainr!rr) r0r(Zrefnumkeysvaluesrrvrrrrr!sB           z_BinaryPlistWriter._flattencCsNt|tr|jt||fSt|tr<|jt|j|jfS|jt|SdSr)rr(rrrr*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|dkrbjdnBqr1rz>BBrrz>BHr/rz>BLr0lz>BQrGrrz>Bdrrrrrrrr rrrHr csg|]}|qSr)r$)rrrBrr sz4_BinaryPlistWriter._write_object..r rmrr )$r$rr%rrrrIrr&rrto_bytesrrbZ total_secondsrr2rSr*r-rrr\UnicodeEncodeErrorr rJrrr"rrrrrr.rT) r0r(rr,tZrefsrWZkeyRefsZvalRefsZ rootItemsrr.rrBrr#fs                    $     "$z _BinaryPlistWriter._write_objectN) r@rDrEr1rr!r$r2r#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)Nrrr>r|)r"r{)rr_FORMATSr-rr)rr!r"r{rinfoPprrrr s      cCst|}t||||dS)Nr@)rr )r(r!r"r{rrrrr sFr%cCs:|tkrtd|ft|d|||d}||dS)NzUnsupported format: %rr?)r&r')rArJr)r(rr!r&r'r?rrrr sr!r'r&cCs t}t|||||d|S)NrE)rr r+)r(r!r'r&rrrrr s)r5)B__all__rUr contextlibrbenumiorr*rrerwarningsrZxml.parsers.expatrEnumr@rglobalsupdate __members__contextmanagerrrrrrrr rcompilernr6r2ASCIIr_rfrhrsrtrrrrJrrobjectrrrrrIrr-r(rr=rrrrAr r r r rrrr1s         '"    s&d!$ a