a �DOgXn�@s�dZgd�ZddlZddlZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl m Z ejdded�Ze��ej�Gd d �d �Zd Ze �d �Zd>dd�Zdd�Ze �de j�Zdd�Zdd�Zdd�ZGdd�d�ZGdd�d�Z Gdd�de �Z!dd �Z"Gd!d"�d"e#�Z$d#d$d%d&d'�Z%e&�Z'Gd(d)�d)�Z(d*d+�Z)e*e+e,eje-fZ.Gd,d-�d-e&�Z/d.d/�Z0e1e2e"ee!d0�e3e2e0e(e/d0�iZ4de2d1�d2d3�Z5de2d1�d4d5�Z6e1d6d7d8�d9d:�Z7e1d7d6d;�d", 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"]) )�InvalidFileException�FMT_XML� FMT_BINARY�load�dump�loads�dumps�UID�N)�BytesIO)� ParserCreate� PlistFormatzFMT_XML FMT_BINARY)�modulec@s<eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd S)rcCs<t|t�std��|dkr"td��|dkr2td��||_dS)Nzdata must be an int�zUIDs cannot be >= 2**64r �UIDs must be positive)� isinstance�int� TypeError� ValueError�data��selfr�r� /usr/lib64/python3.9/plistlib.py�__init__Es z UID.__init__cCs|jS�N)r�rrrr� __index__Nsz UID.__index__cCsd|jjt|j�fS)Nz%s(%s))� __class__�__name__�reprrrrrr�__repr__Qsz UID.__repr__cCs|j|jffSr)rrrrrr� __reduce__TszUID.__reduce__cCst|t�stS|j|jkSr)rr�NotImplementedr)r�otherrrr�__eq__Ws z UID.__eq__cCs t|j�Sr)�hashrrrrr�__hash__\sz UID.__hash__N) r� __module__� __qualname__rrr r!r$r&rrrrrDs  rs� 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]�LcCsP|dd}g}tdt|�|�D]$}||||�}|�t�|��q d�|�S)N��r �)�range�len�append�binasciiZ b2a_base64�join)�s� maxlinelengthZ maxbinsize�pieces�i�chunkrrr�_encode_base64ps  r7cCs(t|t�rt�|�d��St�|�SdS)N�utf-8)r�strr0Z a2b_base64�encode)r2rrr�_decode_base64ys 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]&}||}|dur2qB|�t|��qtj|�S)N�ZyearZmonthZdayZhourZminute�second)� _dateParser�match� groupdictr/r�datetime)r2�order�gdZlst�key�valrrr�_date_from_string�srFcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZr<)�drrr�_date_to_string�s  �rHcCsZt�|�}|durtd��|�dd�}|�dd�}|�dd�}|�dd�}|�d d �}|S) Nzz>)�_controlCharPat�searchr�replace)�text�mrrr�_escape�s      rSc@s�eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*� _PlistParsercCsg|_d|_d|_||_dSr)�stack� current_key�root� _dict_type�r� dict_typerrrr�sz_PlistParser.__init__cCsBt�|_|j|j_|j|j_|j|j_|j|j_ |j� |�|j Sr) r �parser�handle_begin_elementZStartElementHandler�handle_end_elementZEndElementHandler� handle_dataZCharacterDataHandler�handle_entity_declZEntityDeclHandlerZ ParseFilerW)r�fileobjrrr�parse�s     z_PlistParser.parsecCs td��dS)Nz8XML entity declarations are not supported in plist files)r)rZ entity_nameZis_parameter_entity�value�baseZ system_idZ public_idZ notation_namerrrr_�sz_PlistParser.handle_entity_declcCs*g|_t|d|d�}|dur&||�dS)NZbegin_)r�getattr)r�element�attrs�handlerrrrr\�sz!_PlistParser.handle_begin_elementcCs"t|d|d�}|dur|�dS)NZend_)rd)rrergrrrr]�sz_PlistParser.handle_end_elementcCs|j�|�dSr)rr/rrrrr^�sz_PlistParser.handle_datacCs�|jdurFt|jdti��s.td|jj��||jd|j<d|_nB|jsT||_n4t|jdtg��sxtd|jj��|jd�|�dS)N�����zunexpected element at line %d) rVrrU�typerr[�CurrentLineNumberrWr/�rrbrrr� add_object�s ��z_PlistParser.add_objectcCsd�|j�}g|_|S)N�)r1rrrrr�get_data�s z_PlistParser.get_datacCs"|��}|�|�|j�|�dSr)rXrlrUr/)rrfrGrrr� begin_dict�s z_PlistParser.begin_dictcCs*|jrtd|j|jjf��|j��dS)Nz%missing value for key '%s' at line %d)rVrr[rjrU�poprrrr�end_dict�s  �z_PlistParser.end_dictcCs8|jst|jdti��s*td|jj��|��|_dS)Nrhzunexpected key at line %d)rVrrUrirr[rjrnrrrr�end_key�s �z_PlistParser.end_keycCsg}|�|�|j�|�dSr)rlrUr/)rrf�arrr� begin_array�s z_PlistParser.begin_arraycCs|j��dSr)rUrprrrr� end_array�sz_PlistParser.end_arraycCs|�d�dS)NT�rlrrrr�end_true�sz_PlistParser.end_truecCs|�d�dS)NFrvrrrr� end_false�sz_PlistParser.end_falsecCs@|��}|�d�s|�d�r.|�t|d��n|�t|��dS)N�0xZ0X�)rn� startswithrlr)r�rawrrr� end_integer�sz_PlistParser.end_integercCs|�t|����dSr)rl�floatrnrrrr�end_realsz_PlistParser.end_realcCs|�|���dSr)rlrnrrrr� end_stringsz_PlistParser.end_stringcCs|�t|����dSr)rlr;rnrrrr�end_data sz_PlistParser.end_datacCs|�t|����dSr)rlrFrnrrrr�end_datesz_PlistParser.end_dateN)rr'r(rrar_r\r]r^rlrnrorqrrrtrurwrxr}rr�r�r�rrrrrT�s( rTc@s8eZdZddd�Zdd�Zdd�Zdd d �Zd d �Zd S)�_DumbXMLWriterr � cCs||_g|_||_||_dSr)�filerU� _indent_level�indent)rr�� indent_levelr�rrrrsz_DumbXMLWriter.__init__cCs,|j�|�|�d|�|jd7_dS)Nz<%s>�)rUr/�writelnr��rrerrr� begin_elements z_DumbXMLWriter.begin_elementcCs@|jdksJ�|j��|ks J�|jd8_|�d|�dS)Nr r�z)r�rUrpr�r�rrr� end_elementsz_DumbXMLWriter.end_elementNcCs8|dur&t|�}|�d|||f�n|�d|�dS)Nz <%s>%sz<%s/>)rSr�)rrerbrrr�simple_element$sz_DumbXMLWriter.simple_elementcCsH|r8t|t�r|�d�}|j�|j|j�|j�|�|j�d�dS)Nr8� )rr9r:r��writer�r�)r�linerrrr�,s    z_DumbXMLWriter.writeln)r r�)N)rr'r(rr�r�r�r�rrrrr�s   r�c@s>eZdZddd�Zdd �Zd d �Zd d �Zdd�Zdd�ZdS)� _PlistWriterr � r�TFcCs.|r|�t�t�||||�||_||_dSr)r�� PLISTHEADERr�r� _sort_keys� _skipkeys)rr�r�r�Z writeHeader� sort_keys�skipkeysrrrr9s  z_PlistWriter.__init__cCs"|�d�|�|�|�d�dS)Nzz)r�� write_valuerkrrrr�Cs  z_PlistWriter.writecCst|t�r|�d|�n�|dur,|�d�n�|dur@|�d�n�t|t�r~d|kr^dkrtnn|�dd |�nt|��n�t|t�r�|�d t|��nzt|t�r�|�|�ndt|t t f�r�|� |�nJt|t j �r�|�d t |��n,t|ttf��r|�|�ntd t|���dS) N�stringT�trueFZfalsel����rZintegerz%d�real�datezunsupported type: %s)rr9r�r� OverflowErrorr~r�dict� write_dict�bytes� bytearray� write_bytesrArH�tuple�list� write_arrayrrirkrrrr�Hs*           z_PlistWriter.write_valuecCsz|�d�|jd8_tddt|j�dd�|j��}t||��d�D]}|rJ|�|�qJ|jd7_|� d�dS)Nrr�rzr)r�s r�) r�r��maxr.r�rPr7�splitr�r�)rrr3r�rrrr�js � z_PlistWriter.write_bytescCs�|rt|�d�|jr"t|���}n|��}|D]8\}}t|t�sP|jrHq.td��|�d|�|� |�q.|� d�n |�d�dS)Nr��keys must be stringsrD) r�r��sorted�itemsrr9r�rr�r�r�)rrGr�rDrbrrrr�ws      z_PlistWriter.write_dictcCs<|r.|�d�|D]}|�|�q|�d�n |�d�dS)N�array)r�r�r�r�)rr�rbrrrr��s    z_PlistWriter.write_arrayN)r r�r�TF) rr'r(rr�r�r�r�r�rrrrr�8s� " r�cCs�d}|D]}|�|�rdSqtjdftjdftjdffD]N\}}|�|�sNq:|D]4}||�d��|�}|dt|��|krRdSqRq:dS)N)s6xBBQQQ)�_fp�seek�os�SEEK_END�readr.r�struct�unpack� _ref_size� _read_ints�_object_offsets� _undefined�_objects� _read_object�OSError� IndexError�errorr�r)r�fp�trailer� offset_size� num_objects� top_object�offset_table_offsetrrrra�s$   �     � z_BinaryPlistParser.parsecCsL|dkrH|j�d�dd@}d|>}dt|}t�||j�|��dS|S)z$ return the size of the next object.�r�r r+rM)r�r��_BINARY_FORMATr�r�)r�tokenLrRr2�frrr� _get_size�s  z_BinaryPlistParser._get_sizecst|j��|���tvr2t�d|�t�����S�rFt���|krLt��t��fdd�td�|��D��SdS)NrMc3s&|]}t��||��d�VqdS)�bigN)r� from_bytes)�.0r5�r�sizerr� �s�z0_BinaryPlistParser._read_ints..r ) r�r�r�r�r�r.rr�r-)r�nr�rr�rr��s�z_BinaryPlistParser._read_intscCs|�||j�Sr)r�r�)rr�rrr� _read_refs�sz_BinaryPlistParser._read_refscs �j|}|tur|S�j|}�j�|��j�d�d}|d@|d@}}|dkr^d}�n�|dkrnd}�n�|dkr~d }�n~|dkr�d }�nn|d kr�tj�j�d|>�d |d kd�}�nB|dkr�t� d�j�d��d}�n|dk�rt� d�j�d��d}�n�|dk�rDt� d�j�d��d}t � ddd�t j |d�}�n�|dk�r|�� |�}�j�|�}t |�|k�r�t���n�|dk�r��� |�}�j�|�} t | �|k�r�t��| �d�}�n>|dk�r�� |�d}�j�|�} t | �|k�r�t��| �d�}n�|dk�r*tt��j�d|�d ��}n�|dk�rp�� |�}��|�} g}|�j|<|��fdd �| D��n�|d!k�r��� |�}��|�} ��|�} ���}|�j|<z.t| | �D]\} } ��| �|��| �<�q�Wnt�y�t��Yn0nt��|�j|<|S)"zx read the object by reference. May recursively read sub-objects (content of an array/dict/set) r�r ��r�Nr�F� Tr,rzr�r+��signed�"z>fr*�#z>d�3��)Zseconds�@�Pr��`r��utf-16be��c3s|]}��|�VqdSr)r�)r��xrrrr�Fr,z2_BinaryPlistParser._read_object..��)r�r�r�r�r�r�rr�r�r�rAZ timedeltar�r.rr�rr��extendrX�zipr�r)r�ref�result�offset�tokenZtokenHr�r�r2rZobj_refsZkey_refs�k�orrrr��s�   �     �                     z_BinaryPlistParser._read_objectN) rr'r(�__doc__rrar�r�r�r�rrrrr��s  r�cCs,|dkr dS|dkrdS|dkr$dSdSdS)N�r��r��r*r�r)�countrrr�_count_to_size_src@s<eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd S)�_BinaryPlistWritercCs||_||_||_dSr)r�r�r�)rr�r�r�rrrrosz_BinaryPlistWriter.__init__c Cs�g|_i|_i|_|�|�t|j�}dg||_t|�|_t|j|_ |j � d�|jD]}|� |�qZ|� |�}|j ��}t|�}dt||}|j � tj|g|j�R��d}|||j|||f} |j � tjdg| �R��dS)Nr �bplist00rMz >5xBBBQQQ)�_objlist� _objtable� _objidtable�_flattenr.r�rr�r�� _ref_formatr�r�� _write_object� _getrefnum�tellr��pack) rrbr��objr�r�r�Z offset_formatZ sort_versionr�rrrr�ts*           �z_BinaryPlistWriter.writec Cs"t|t�r"t|�|f|jvr4dSnt|�|jvr4dSt|j�}|j�|�t|t�rh||jt|�|f<n||jt|�<t|t �r�g}g}|� �}|j r�t |�}|D]6\}}t|t �s�|jr�q�td��|�|�|�|�q�t�||�D]}|�|�q�n&t|ttf��r|D]}|�|��q dS)Nr�)r�_scalarsrir�idrr.rr/r�r�r�r�r9r�r� itertools�chainr r�r�) rrbZrefnum�keys�valuesr�r��vr�rrrr �s8         z_BinaryPlistWriter._flattencCs.t|t�r|jt|�|fS|jt|�SdSr)rrrrirrrkrrrr �s z_BinaryPlistWriter._getrefnumcCs�|dkr"|j�t�d||B��n�|dkrH|j�t�d|dBd|��nh|dkrn|j�t�d|dBd|��nB|d kr�|j�t�d |dBd |��n|j�t�d |dBd |��dS)Nr�z>Br�z>BBBrzrz>BBH�rz>BBL�z>BBQ�)r�r�r�r)rr�r�rrr� _write_size�sz_BinaryPlistWriter._write_sizec st��|�}�j���j|<|dur2�j�d��n>|durJ�j�d��n&|durb�j�d��nt|t��rj|dkr�z�j�t�dd|��Wntj y�t |�d�Yn0n�|d kr҈j�t�d d |��n�|d kr�j�t�d d|��nt|dk�r�j�t�dd|��nR|dk�r6�j�t�dd|��n0|dk�r^�j�d|j d ddd��nt |���nt|t ��r��j�t�dd|���n�t|t j ��r�|t � ddd���}�j�t�dd|���n�t|ttf��r���dt|���j�|��nrt|t��rlz|�d�}��dt|��Wn2t�yZ|�d �}��d!t|�d"�Yn0�j�|��nt|t��r*|jdk�r�td#��n�|jd k�r��j�t�d d$|��nt|jd k�rֈj�t�d d%|��nP|jdk�r��j�t�dd&|��n,|jdk�r�j�t�dd'|��nt |���nFt|ttf��r��fd(d)�|D�}t|�}��d*|��j�tjd+�j|g|�R��n�t|t��rhgg}}�j�r�t|���} n|��} | D]J\} } t| t��s�j �rސq�t!d,��|�"��| ��|�"��| ���q�t|�}��d-|��j�tjd+�j|g|�R���j�tjd+�j|g|�R��nt!|��dS).N�F�Tr�r z>Bqrr�z>BBrzrz>BHrrz>BLrlz>BQr�r�r�z>Bdr�r�r�r�r�r�r�r�r�r�rr����csg|]}��|��qSr)r )r�r�rrr� $r,z4_BinaryPlistWriter._write_object..r�rMr�r�)#r r�r r�r�rrr�rr�r��to_bytesr~rAZ total_secondsr�r�rr.r9r:�UnicodeEncodeErrorrrrr�r�r r�r�r�r�r�rr/) rrbr�r��tZrefsr2ZkeyRefsZvalRefsZ rootItemsr�rrrrr �s�                   &     $&z _BinaryPlistWriter._write_objectN) rr'r(rr�r r rr rrrrrns -*rcCs|dd�dkS)Nr�rr)r�rrr�_is_fmt_binaryBsr%)�detectr[�writer��fmtrZcCsj|durJ|�d�}|�d�t��D]}|d|�r$|d}qVq$t��n t|d}||d�}|�|�S)z�Read a .plist file. 'fp' should be a readable and binary file object. Return the unpacked root object (which usually is a dictionary). Nr�r r&r[)rZ)r�r��_FORMATSrrra)r�r)rZr��info�P�prrrrXs      rcCst|�}t|||d�S)zqRead a .plist file from a bytes object. Return the unpacked root object (which usually is a dictionary). r()r r)rbr)rZr�rrrrnsrTF)r)r�r�cCs:|tvrtd|f��t|d|||d�}|�|�dS)zWWrite 'value' to a .plist file. 'fp' should be a writable, binary file object. zUnsupported format: %rr')r�r�N)r*rr�)rbr�r)r�r�r'rrrrvsr�r)r�r�cCs t�}t|||||d�|��S)z?Return a bytes object with the contents for a .plist file. r.)r r�getvalue)rbr)r�r�r�rrrr�sr)r))9r��__all__r0r�rA�enum�ior rr��rer�Zxml.parsers.expatr �Enumrr �globals�update� __members__rr��compilerNr7r;�ASCIIr>rFrHrSrTr�r�r�rrr��objectr�r�rr9rr~r�rrr%rr�rr*rrrrrrrr�sj/  !�    n&^!! U ���