QfndZgdZddlZddlZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl m Z ejddeZej%ej&Gd d Zd Ze j,d Zd1d ZdZe j,de j4ZdZdZdZGddZGddZ Gdde Z!dZ"Gdde#Z$ddddd Z%e&Z'Gd!d"Z(d#Z)e*e+e,eje-fZ.Gd$d%e&Z/d&Z0e1e2e"ee!'e3e2e0e(e/'iZ4de2d(d)Z5de2d(d*Z6e1d+d,d-d.Z7e1d,d+d/d0Z8y)2a>plistlib.py -- a tool to generate and parse MacOSX .plist files. The property list (.plist) file format is a simple XML pickle supporting basic object types, like dictionaries, lists, numbers and strings. Usually the top level object is a dictionary. To write out a plist file, use the dump(value, file) function. 'value' is the top level object, 'file' is a (writable) file object. To parse a plist from a file, use the load(file) function, with a (readable) file object as the only argument. It returns the top level object (again, usually a dictionary). To work with plist data in bytes objects, you can use loads() and dumps(). Values can be strings, integers, floats, booleans, tuples, lists, dictionaries (but only with string keys), Data, bytes, bytearray, or datetime.datetime objects. Generate Plist example: import datetime import plistlib pl = dict( aString = "Doodah", aList = ["A", "B", 12, 32.1, [1, 2, 3]], aFloat = 0.1, anInt = 728, aDict = dict( anotherString = "", aThirdString = "M\xe4ssig, Ma\xdf", aTrueValue = True, aFalseValue = False, ), someData = b"", someMoreData = b"" * 10, aDate = datetime.datetime.now() ) print(plistlib.dumps(pl).decode()) Parse Plist example: import plistlib plist = b''' foo bar ''' pl = plistlib.loads(plist) print(pl["foo"]) )InvalidFileExceptionFMT_XML FMT_BINARYloaddumploadsdumpsUIDN)BytesIO) ParserCreate PlistFormatzFMT_XML FMT_BINARY)modulec0eZdZdZdZdZdZdZdZy)r ct|ts td|dk\r td|dkr td||_y)Nzdata must be an intzUIDs cannot be >= 2**64r UIDs must be positive) isinstanceint TypeError ValueErrordataselfrs //opt/alt/python312/lib64/python3.12/plistlib.py__init__z UID.__init__NsE$$12 2 7?67 7 !845 5 c|jSN)rrs r __index__z UID.__index__Ws yyrc`|jjdt|jdS)N()) __class____name__reprrrs r__repr__z UID.__repr__Zs>>22DODDrc4|j|jffSr)r$rrs r __reduce__zUID.__reduce__]s~~ |++rc`t|tstS|j|jk(Sr)rr NotImplementedr)rothers r__eq__z UID.__eq__`s%%%! !yyEJJ&&rc,t|jSr)hashrrs r__hash__z UID.__hash__esDIIrN) r% __module__ __qualname__rr r'r)r-r0rrr r Ms!E,' rr 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]c|dzdz}g}tdt||D].}||||z}|jtj|0dj |S)Nr r)rangelenappendbinascii b2a_base64join)s maxlinelength maxbinsizepiecesichunks r_encode_base64rCyse"A%J F 1c!fj )!a*n% h))%01* 88F rct|tr$tj|j dStj|S)Nutf-8)rstrr: a2b_base64encode)r=s r_decode_base64rIs9!S""188G#455""1%%rz{(?P\d\d\d\d)(?:-(?P\d\d)(?:-(?P\d\d)(?:T(?P\d\d)(?::(?P\d\d)(?::(?P\d\d))?)?)?)?)?Zcd}tj|j}g}|D]%}||}|n|jt |'t j |S)Nyearmonthdayhourminutesecond) _dateParsermatch groupdictr9rdatetime)r=ordergdlstkeyvals r_date_from_stringr[sc @E   1  ' ' )B Cg ;  3s8    c ""rcd|j|j|j|j|j|j fzS)Nz%04d-%02d-%02dT%02d:%02d:%02dZrK)ds r_date_to_stringr^s: +  !((/ rctj|}| td|jdd}|jdd}|jdd}|jdd}|jd d }|S) Nz;strings can't contain control characters; use bytes insteadz   &z&z>)_controlCharPatsearchrreplace)textms r_escaperjs~t$A}-. . << %D <<d #D <<W %D <<V $D <<V $D KrceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZy) _PlistParserc<g|_d|_d|_||_yr)stack current_keyroot _dict_typer dict_types rrz_PlistParser.__init__s  #rcFt|_|j|j_|j|j_|j |j_|j|j_ |jj||jSr) r parserhandle_begin_elementStartElementHandlerhandle_end_elementEndElementHandler handle_dataCharacterDataHandlerhandle_entity_declEntityDeclHandler ParseFilerp)rfileobjs rparsez_PlistParser.parseso"n *.*C*C '(,(?(? %+/+;+; ((,(?(? % g&yyrctd)Nz8XML entity declarations are not supported in plist files)r)r entity_nameis_parameter_entityvaluebase system_id public_id notation_names rr|z_PlistParser.handle_entity_decls##]^^rcHg|_t|d|zd}| ||yy)Nbegin_)rgetattr)relementattrshandlers rrvz!_PlistParser.handle_begin_elements. $7 2D9   EN rc8t|d|zd}||yy)Nend_)r)rrrs rrxz_PlistParser.handle_end_elements%$ 0$7   I rc:|jj|yr)rr9rs rrzz_PlistParser.handle_datas rc|jct|jdts"t d|j j z||jd|j<d|_y|js||_yt|jdts"t d|j j z|jdj|y)Nzunexpected element at line %d) rorrndictrruCurrentLineNumberrplistr9rrs r add_objectz_PlistParser.add_objects    'djjnd3 !@!%!>!>"?@@/4DJJrN4++ ,#D DIdjjnd3 !@!%!>!>"?@@ JJrN ! !% (rcJdj|j}g|_|S)N)r<rrs rget_dataz_PlistParser.get_datas wwtyy!  rc||j}|j||jj|yr)rqrrnr9)rrr]s r begin_dictz_PlistParser.begin_dicts, OO   !rc|jr.td|j|jjfz|jj y)Nz%missing value for key '%s' at line %d)rorrurrnpoprs rend_dictz_PlistParser.end_dictsI   D"..t{{/L/LMNO O rc|jst|jdts"t d|j j z|j|_y)Nrzunexpected key at line %d)rorrnrrrurrrs rend_keyz_PlistParser.end_keysL   :djjnd#C8![[::;< <==?rc`g}|j||jj|yr)rrnr9)rras r begin_arrayz_PlistParser.begin_arrays%   !rc8|jjyr)rnrrs r end_arrayz_PlistParser.end_arrays rc&|jdy)NTrrs rend_truez_PlistParser.end_trues rc&|jdy)NFrrs r end_falsez_PlistParser.end_falses rc|j}|jds|jdr|jt|dy|jt|y)N0x0X)r startswithrr)rraws r end_integerz_PlistParser.end_integersFmmo >>$ 3>>$#7 OOCRL ) OOCH %rcT|jt|jyr)rfloatrrs rend_realz_PlistParser.end_reals dmmo./rcB|j|jyr)rrrs r end_stringz_PlistParser.end_strings  (rcT|jt|jyr)rrIrrs rend_dataz_PlistParser.end_datas t}}78rcT|jt|jyr)rr[rrs rend_datez_PlistParser.end_dates )$--/:;rN)r%r1r2rrr|rvrxrzrrrrrrrrrrrrrrr3rrrlrlsg$ _   )   +  &0)9)rnr9writelnrrrs r begin_elementz_DumbXMLWriter.begin_element"s6 '" Vg%& arcV|xjdzc_|jd|zy)Nrz)rrrs r end_elementz_DumbXMLWriter.end_element's& a Ww&'rNc ~|'t|}|jd|d|d|dy|jd|zy)Nrcrdz)rjr)rrrs rsimple_elementz_DumbXMLWriter.simple_element-s7  ENE LL'5'B C LL7* +rc|rnt|tr|jd}|jj |j |j z|jj ||jj dy)NrE )rrFrHrwriterr)rlines rrz_DumbXMLWriter.writeln5s^ $${{7+ IIOOD..< = IIOOD ! r)r  r)r%r1r2rrrrrr3rrrrs  ( , rrc6eZdZ ddZdZdZdZdZdZy) _PlistWriterc~|r|jttj||||||_||_yr)r PLISTHEADERrr _sort_keys _skipkeys)rrrr writeHeader sort_keysskipkeyss rrz_PlistWriter.__init__Bs5  JJ{ #dL&A#!rcj|jd|j||jdy)Nzz)r write_valuers rrz_PlistWriter.writeLs) ./  Z rct|tr|jd|y|dur|jdy|dur|jdyt|tr9d|cxkrdkr#n t ||jdd |zyt |t|t r|jd t |yt|tr|j|yt|ttfr|j|yt|tjr|jd t|yt|ttfr|j!|yt#d t%|z) NstringTtrueFfalselrintegerz%drealdatezunsupported type: %s)rrFrr OverflowErrorrr&r write_dictbytes bytearray write_bytesrUr^tupler write_arrayrtypers rrz_PlistWriter.write_valueQs4 eS !   % 0 d]    ' e^    ( s #5*7*$E**##Ite|<#E** u %   U 4 t $ OOE " y1 2   U # x00 1   (> ? t} -   U #2T%[@A Arc |jd|xjdzc_tddt|jj dd|jzz }t ||jdD]}|s|j||xjdz c_|jdy)NrrrL s r) rrmaxr8rrgrCsplitrr)rrr>rs rrz_PlistWriter.write_bytesss 6" a  T[[((9D6xBBQQQ)_fpseekosSEEK_ENDreadr8rstructunpack _ref_size _read_ints_object_offsets _undefined_objects _read_objectOSError IndexErrorerrorrr)rfptrailer offset_size num_objects top_objectoffset_table_offsets rrz_BinaryPlistParser.parses ) DH HHMM#r{{ +hhmmB'G7|r!*,, j'2 T^[*# HHMM- .#'??; #LD 'L;6DM$$Z0 0V\\= )&( ( )s CC3D c|dk(rd|jjdddz}d|z}dt|z}tj||jj|dS|S)z$ return the size of the next object.rr r6rd)rr_BINARY_FORMATrr)rtokenLrir=fs r _get_sizez_BinaryPlistParser._get_sizese S= a #c)AQAnQ''A==DHHMM!$45a8 8 rc|jj|ztvr"tjd|tSrt |zk7r t tfdtd|zDS)Nrdc3VK|] }tj||zd"yw)bigN)r from_bytes).0rArsizes r z0_BinaryPlistParser._read_ints..s/<":QQD(95A":s&)r ) rrr,rrr8rrr7)rnr5rs `@rrz_BinaryPlistParser._read_intssxx}}TAX& > !==1QCt(<'=!>E E3t9q0*,,<"'4!8T":<< fr5#z>d3)seconds@Pr`r utf-16bec3@K|]}j|ywr)r )r4xrs rr6z2_BinaryPlistParser._read_object..OsA1$++A.s)rrrrrrrr3rrrU timedeltar/r8rrr r9extendrqzipr r)rrefresultoffsettokentokenHr-r.r=robj_refskey_refskos` rr z_BinaryPlistParser._read_objects s#  #M%%c*  f a #ut| D=F d]F d]F d]F t^^^DHHMM!v+$>$)&A+$?Fd]]]4q)9:1=F d]]]4q)9:1=F d] dDHHMM!$45a8A''a3((34Ft^v&AXX]]1%F6{a*,, t^v&A88==#D4yA~*,,[[)F t^v&*A88==#D4yA~*,,[[,F t^ a&j(A5IJF t^v&Aq)HF!'DMM#  MMAA At^v&Aq)Hq)H__&F!'DMM#  -(3DAq373D3DQ3GF4,,Q/04 '( (# c  -*,, -s 7O,,PN) r%r1r2__doc__rrr/rr9r r3rrrrs&$)2<2crrc(|dkry|dkry|dkryy)Nrr r5rr3)counts r_count_to_sizer_hs% v~  rc0eZdZdZdZdZdZdZdZy)_BinaryPlistWriterc.||_||_||_yr)rrr)rr$rrs rrz_BinaryPlistWriter.__init__xs#!rcg|_i|_i|_|j|t |j}dg|z|_t ||_t|j|_ |jjd|jD]}|j||j|}|jj}t |}dt||zz}|jjtj |g|j d}|||j|||f} |jjtj dg| y)Nr bplist00rdz >5xBBBQQQ)_objlist _objtable _objidtable_flattenr8rr_rr, _ref_formatrr _write_object _getrefnumtellrpack) rrr'objr(r)r& offset_format sort_versionr%s rrz_BinaryPlistWriter.write}s9  e$--( !s;' 4)$..9 {#==C   s #!__U+ "hhmmo$%89 n[9KGG  v{{=H43G3GHI +t~~{ +  v{{;99:rcDt|trt||f|jvryt ||j vryt |j}|jj|t|tr||jt||f<n||j t |<t|trg}g}|j}|jr t|}|D]O\}}t|ts|jr#td|j||j|Qt!j"||D]}|j%|yt|t&t(fr|D]}|j%|yy)Nr)r_scalarsrrfidrgr8rer9rrrrrFrr itertoolschainrhrr) rrrefnumkeysvaluesrrWvrXs rrhz_BinaryPlistWriter._flattensV eX &U U#t~~5 Y$** * T]]# U# eX &39DNNDK/ 0*0D  RY ' eT "DFKKMEu 1!!S)~~ #$:;; A a __T62 a 3e} - a .rct|tr|jt||fS|jt |Sr)rrrrfrrgrsrs rrkz_BinaryPlistWriter._getrefnums9 eX &>>4;"67 7##BuI. .rc8|dkr3|jjtjd||zy|dkr5|jjtjd|dzd|y|dkr5|jjtjd|dzd|y|d kr5|jjtjd |dzd |y|jjtjd |dzd |y)Nr+z>Br[z>BBBrr\z>BBHr]z>BBLz>BBQ)rrrrm)rrSr5s r _write_sizez_BinaryPlistWriter._write_sizes "9 HHNN6;;tUT\: ; F] HHNN6;;vus{D$G H G^ HHNN6;;vus{D$G H G^ HHNN6;;vus{D$G H HHNN6;;vus{D$G Hrc |j|}|jj|j|<||jj dy|dur|jj dy|dur|jj dyt |t rP|dkr2 |jj tjdd|y|d kr1|jj tjd d |y|d kr1|jj tjd d|y|dkr1|jj tjdd|y|dkr1|jj tjdd|y|dkr1|jj d|jd ddzyt|t |tr1|jj tjdd|yt |tjrY|tjdddz j}|jj tjdd|yt |tt fr7|j#dt%||jj |yt |t&rI |j)d}|j#dt%||jj |yt |t,r%|j.dkr t1d#|j.d kr1|jj tjd d$|y|j.d kr1|jj tjd d%|y|j.dkr1|jj tjdd&|y|j.dkr1|jj tjdd'|yt|t |t2t4fr{|Dcgc]}|j|}}t%|}|j#d(||jj tjd)|j6|zzg|yt |t8rHgg} }|j:rt=|j?} n|j?} | D]m\} } t | t&s|j@r#tCd*|jE|j| | jE|j| ot%|}|j#d+||jj tjd)|j6|zzg||jj tjd)|j6|zzg| ytC|#tj$r t|dwxYw#t*$r3|j)d }|j#d!t%|d"zYwxYwcc}w),NFTrr z>Bqr~r[z>BBrr\z>BHr|r]z>BLr}lz>BQrr2r=z>Bdr@rBrrArDrrErGrFr rrHrIrdrrL)#rkrrlrrrrrrmr#rto_bytesrrU total_secondsrrrr8rFrHUnicodeEncodeErrorr rrrrrirrrrrrr9) rrrPr.trXrefsr=keyRefsvalRefs rootItemsrWrys rrjz _BinaryPlistWriter._write_objectsooe$$(HHMMOS! = HHNN7 # e^ HHNN7 # d] HHNN7 # s #qy9HHNN6;;udE#BCv{{5$>?v{{5$>?v{{5$>?v{{5$>?wE$)OOP#E** u % HHNN6;;udE: ; x00 1**4A66EEGA HHNN6;;udA6 7 y1 2   T3u: . HHNN5 ! s # 4LL)  s5z2 HHNN1  s #zzA~ !899f$v{{5$>?g%v{{5$>?g%v{{5$>?g%v{{5$>?#E** e} -0561DOOA&D6D A   T1 % HHNN6;;sT-=-=-A'AIDI J t $!2WG"5;;=1 !KKM !1!!S)~~ #$:;;tq12tq12 "G A   T1 % HHNN6;;sT-=-=-A'ALGL M HHNN6;;sT-=-=-A'ALGL ME" "]||9'.D89<& 4LL,  s1v{3 4*7s$.0Y= ,Z "[= Z 8[[N) r%r1r2rrrhrkrrjr3rrraraws$" +;Z(!T/ I ^#rrac|dddk(S)Nrrdr3)rs r_is_fmt_binaryrKs "1: $$r)detectruwriterfmtrsc|W|jd}|jdtjD]}|d|s|d}nt t|d}||}|j |S)zRead a .plist file. 'fp' should be a readable and binary file object. Return the unpacked root object (which usually is a dictionary). rr rru)rs)rr_FORMATSrxrr)r$rrsrinfoPps rrras {  OO%DtH~f%N& '( ( SM( # IA 772;rc4t|}t|||S)zqRead a .plist file from a bytes object. Return the unpacked root object (which usually is a dictionary). r)r r)rrrsr$s rrrws B y 11rTF)rrrcz|tvrtd|t|d|||}|j|y)zWWrite 'value' to a .plist file. 'fp' should be a writable, binary file object. zUnsupported format: r)rrN)rrr)rr$rrrrs rrrs= (3899 c]8 $R9x PF LLrrrrcVt}t||||||jS)z?Return a bytes object with the contents for a .plist file. r)r rgetvalue)rrrrr$s rrrs' Bh)D ;;=r)r)9rY__all__r:rrUenumior rtrrerxml.parsers.expatr Enumr%r globalsupdate __members__r rcompilererCrIASCIIrRr[r^rjrlrrrrrr,objectrrr_rFrrrrrrarrrrrrrrrr3rrrs7p    *dii ';HM  (()B "**IJ&bjjXZ\ZbZbc  # k<k<\##L[)>[)|B+J+SSS1 X ^^@  eX.. 6Q#&Q#h% T !! D,2#dU %4r