Your IP : 18.117.93.183


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/plistlib.cpython-310.opt-1.pyc

o

6��f�n�@s�dZgd�ZddlZddlZddlZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlm
Z
ejdded�Ze��ej�Gd	d
�d
�ZdZe
�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<d=�Z8dS)?a>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 = "<hello & hi there!>",
            aThirdString = "M\xe4ssig, Ma\xdf",
            aTrueValue = True,
            aFalseValue = False,
        ),
        someData = b"<binary gunk>",
        someMoreData = b"<lots of binary gunk>" * 10,
        aDate = datetime.datetime.now()
    )
    print(plistlib.dumps(pl).decode())

Parse Plist example:

    import plistlib

    plist = b'''<plist version="1.0">
    <dict>
        <key>foo</key>
        <string>bar</string>
    </dict>
    </plist>'''
    pl = plistlib.loads(plist)
    print(pl["foo"])
)�InvalidFileException�FMT_XML�
FMT_BINARY�load�dump�loads�dumps�UID�N)�BytesIO)�ParserCreate�PlistFormatzFMT_XML FMT_BINARY)�modulec@�<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)rcCs<t|t�s	td��|dkrtd��|dkrtd��||_dS)Nzdata must be an int�zUIDs cannot be >= 2**64r	�UIDs must be positive)�
isinstance�int�	TypeError�
ValueError�data��selfr�r�//opt/alt/python310/lib64/python3.10/plistlib.py�__init__Ns

zUID.__init__cCs|jS�N)r�rrrr�	__index__Wsz
UID.__index__cCsd|jjt|j�fS)Nz%s(%s))�	__class__�__name__�reprrrrrr�__repr__Z�zUID.__repr__cCs|j|jffSr)rrrrrr�
__reduce__]�zUID.__reduce__cCst|t�stS|j|jkSr)rr�NotImplementedr)r�otherrrr�__eq__`s
z
UID.__eq__cCs
t|j�Sr)�hashrrrrr�__hash__e�
zUID.__hash__N)	r�
__module__�__qualname__rrr!r#r'r)rrrrrMs	rs�<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
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�|��qd�|�S)N��r	�)�range�len�append�binasciiZ
b2a_base64�join)�s�
maxlinelengthZ
maxbinsize�pieces�i�chunkrrr�_encode_base64ys
r;cCs$t|t�r
t�|�d��St�|�S)N�utf-8)r�strr4Z
a2b_base64�encode)r6rrr�_decode_base64�s

r?z{(?P<year>\d\d\d\d)(?:-(?P<month>\d\d)(?:-(?P<day>\d\d)(?:T(?P<hour>\d\d)(?::(?P<minute>\d\d)(?::(?P<second>\d\d))?)?)?)?)?ZcCsLd}t�|���}g}|D]}||}|durn|�t|��q
tj|�S)N�ZyearZmonthZdayZhourZminute�second)�_dateParser�match�	groupdictr3r�datetime)r6ZorderZgdZlst�key�valrrr�_date_from_string�s
rHcCs d|j|j|j|j|j|jfS)Nz%04d-%02d-%02dT%02d:%02d:%02dZr@)�drrr�_date_to_string�s�rJcCsZt�|�}|dur
td��|�dd�}|�dd�}|�dd�}|�dd�}|�d	d
�}|S)Nz;strings can't contain control characters; use bytes insteadz
�
�
�&z&amp;�<z&lt;�>z&gt;)�_controlCharPat�searchr�replace)�text�mrrr�_escape�s
rUc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�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��
z_PlistParser.__init__cCsBt�|_|j|j_|j|j_|j|j_|j|j_	|j�
|�|jSr)r�parser�handle_begin_elementZStartElementHandler�handle_end_elementZEndElementHandler�handle_dataZCharacterDataHandler�handle_entity_declZEntityDeclHandlerZ	ParseFilerY)rZfileobjrrr�parse�s



z_PlistParser.parsecCstd��)Nz8XML entity declarations are not supported in plist files)r)rZentity_nameZis_parameter_entity�value�baseZ	system_idZ	public_idZ
notation_namerrrrb�sz_PlistParser.handle_entity_declcCs.g|_t|d|d�}|dur||�dSdS)NZbegin_)r�getattr)r�element�attrs�handlerrrrr_�s
�z!_PlistParser.handle_begin_elementcCs&t|d|d�}|dur|�dSdS)NZend_)rf)rrgrirrrr`�s
�z_PlistParser.handle_end_elementcCs|j�|�dSr)rr3rrrrra��z_PlistParser.handle_datacCs�|jdur$t|jdti��std|jj��||jd|j<d|_dS|js,||_dSt|jdtg��s>td|jj��|jd�|�dS)N���zunexpected element at line %d)	rXrrW�typerr^�CurrentLineNumberrYr3�rrdrrr�
add_object�s
�

�z_PlistParser.add_objectcCsd�|j�}g|_|S)N�)r5rrrrr�get_data�sz_PlistParser.get_datacCs"|��}|�|�|j�|�dSr)rZrorWr3)rrhrIrrr�
begin_dict�s
z_PlistParser.begin_dictcCs*|jrtd|j|jjf��|j��dS)Nz%missing value for key '%s' at line %d)rXrr^rmrW�poprrrr�end_dict�s
�z_PlistParser.end_dictcCs8|js
t|jdti��std|jj��|��|_dS)Nrkzunexpected key at line %d)rXrrWrlrr^rmrqrrrr�end_key�s
�z_PlistParser.end_keycCsg}|�|�|j�|�dSr)rorWr3)rrh�arrr�begin_array�s
z_PlistParser.begin_arraycCs|j��dSr)rWrsrrrr�	end_array�r$z_PlistParser.end_arraycC�|�d�dS)NT�rorrrr�end_truer$z_PlistParser.end_truecCry)NFrzrrrr�	end_falser$z_PlistParser.end_falsecCsB|��}|�d�s|�d�r|�t|d��dS|�t|��dS)NZ0xZ0X�)rq�
startswithror)r�rawrrr�end_integersz_PlistParser.end_integercC�|�t|����dSr)ro�floatrqrrrr�end_realr"z_PlistParser.end_realcCs|�|���dSr)rorqrrrr�
end_stringsz_PlistParser.end_stringcCr�r)ror?rqrrrr�end_datar"z_PlistParser.end_datacCr�r)rorHrqrrrr�end_dater"z_PlistParser.end_dateN)rr+r,rrcrbr_r`rarorqrrrtrurwrxr{r|r�r�r�r�r�rrrrrV�s*	rVc@s8eZdZddd�Zdd�Zdd�Zdd
d�Zdd
�Zd	S)�_DumbXMLWriterr	�	cCs||_g|_||_||_dSr)�filerW�
_indent_level�indent)rr��indent_levelr�rrrrr]z_DumbXMLWriter.__init__cCs,|j�|�|�d|�|jd7_dS)Nz<%s>�)rWr3�writelnr��rrgrrr�
begin_element"sz_DumbXMLWriter.begin_elementcCs |jd8_|�d|�dS)Nr�z</%s>)r�r�r�rrr�end_element'sz_DumbXMLWriter.end_elementNcCs:|durt|�}|�d|||f�dS|�d|�dS)Nz<%s>%s</%s>z<%s/>)rUr�)rrgrdrrr�simple_element-sz_DumbXMLWriter.simple_elementcCsH|rt|t�r|�d�}|j�|j|j�|j�|�|j�d�dS)Nr<�
)rr=r>r��writer�r�)r�linerrrr�5s

z_DumbXMLWriter.writeln)r	r�r)rr+r,rr�r�r�r�rrrrr�s

r�c@sBeZdZ		ddd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�ZdS)�_PlistWriterr	�	r�TFcCs.|r|�t�t�||||�||_||_dSr)r��PLISTHEADERr�r�
_sort_keys�	_skipkeys)rr�r�r�ZwriteHeader�	sort_keys�skipkeysrrrrBs


z_PlistWriter.__init__cCs"|�d�|�|�|�d�dS)Nz<plist version="1.0">z</plist>)r��write_valuernrrrr�Ls

z_PlistWriter.writecCs(t|t�r
|�d|�dS|dur|�d�dS|dur#|�d�dSt|t�rEd|kr2dkrAnt|��|�dd	|�dSt|��t|t�rT|�d
t|��dSt|t�r`|�|�dSt|t	t
f�rn|�|�dSt|tj�r~|�dt
|��dSt|ttf�r�|�|�dStdt|���)
N�stringT�trueFZfalsel����rZintegerz%d�real�datezunsupported type: %s)rr=r�r�
OverflowErrorr�r �dict�
write_dict�bytes�	bytearray�write_bytesrErJ�tuple�list�write_arrayrrlrnrrrr�Qs,

�

z_PlistWriter.write_valuecCsz|�d�|jd8_tddt|j�dd�|j��}t||��d�D]	}|r.|�|�q%|jd7_|�	d�dS)Nrr�r}r-r�s        r�)
r�r��maxr2r�rRr;�splitr�r�)rrr7r�rrrr�ss
�
�z_PlistWriter.write_bytescCs�|r;|�d�|jrt|���}n|��}|D]\}}t|t�s(|jr$qtd��|�d|�|�	|�q|�
d�dS|�d�dS)Nr��keys must be stringsrF)r�r��sorted�itemsrr=r�rr�r�r�)rrIr�rFrdrrrr��s

z_PlistWriter.write_dictcCs>|r|�d�|D]}|�|�q	|�d�dS|�d�dS)N�array)r�r�r�r�)rr�rdrrrr��s
z_PlistWriter.write_arrayN)r	r�r�TF)	rr+r,rr�r�r�r�r�rrrrr�As
�
"
r�cCs�d}|D]
}|�|�rdSqtjdftjdftjdffD]'\}}|�|�s'q|D]}||�d��|�}|dt|��|krCdSq)qdS)N)s<?xmls<plistTr<z	utf-16-bez	utf-16-le�asciiF)r~�codecs�BOM_UTF8�BOM_UTF16_BE�BOM_UTF16_LE�decoder>r2)�header�prefixesZpfxZbom�encoding�start�prefixrrr�_is_fmt_xml�s$
��
��r�c@seZdZddd�ZdS)r�Invalid filecCst�||�dSr)rr)r�messagerrrr�rjzInvalidFileException.__init__N)r�)rr+r,rrrrrr�sr�B�H�L�Q)r��r.�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�_BinaryPlistParsera
    Read or write a binary plist file, following the description of the binary
    format.  Raise InvalidFileException in case of error, otherwise return the
    root object.

    see also: http://opensource.apple.com/source/CF/CF-744.18/CFBinaryPList.c
    cCs
||_dSr)rZr[rrrr�r*z_BinaryPlistParser.__init__cCs�z?||_|j�dtj�|j�d�}t|�dkrt��t�d|�\}|_	}}}|j�|�|�
||�|_tg||_
|�|�WStttjttfyOt��w)Ni��� z>6xBBQQQ)�_fp�seek�os�SEEK_END�readr2r�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_offsetrrrrc�s&
�

��z_BinaryPlistParser.parsecCsL|dkr$|j�d�dd@}d|>}dt|}t�||j�|��dS|S)z$ return the size of the next object.�r�r	r/rO)r�r��_BINARY_FORMATr�r�)r�tokenLrTr6�frrr�	_get_size�sz_BinaryPlistParser._get_sizecsp|j��|���tvrt�d|�t�����S�r#t���|kr&t��t��fdd�td�|��D��S)NrOc3s(�|]}t��||��d�VqdS)�bigN)r�
from_bytes)�.0r9�r�sizerr�	<genexpr>�s� �z0_BinaryPlistParser._read_ints.<locals>.<genexpr>r	)	r�r�r�r�r�r2rr�r1)r�nr�rr�rr��s�z_BinaryPlistParser._read_intscCs|�||j�Sr)r�r�)rr�rrr�
_read_refsr$z_BinaryPlistParser._read_refscs��j|}|tur|S�j|}�j�|��j�d�d}|d@|d@}}|dkr/d}�n@|dkr7d}�n8|dkr?d	}�n0|dkrGd
}�n(|dkr]tj�j�d|>�d|d
kd�}�n|dkrot�	d�j�d��d}�n|dkr�t�	d�j�d��d}n�|dkr�t�	d�j�d��d}t
�
ddd�t
j|d�}n�|dkr���|�}�j�|�}t
|�|kr�t��n�|dkrՈ�|�}�j�|�}	t
|	�|kr�t��|	�d�}n�|dkr���|�d}�j�|�}	t
|	�|kr�t��|	�d�}nz|dk�r	tt��j�d|�d��}nf|dk�r,��|�}��|�}
g}|�j|<|��fdd �|
D��nC|d!k�rl��|�}��|�}��|�}
���}|�j|<zt||
�D]\}}
��|
�|��|�<�qOWnt�ykt��wt��|�j|<|S)"zx
        read the object by reference.

        May recursively read sub-objects (content of an array/dict/set)
        r�r	��r�Nr�F�	Tr0r}r�r/�Zsigned�"z>fr.�#z>d�3��)Zseconds�@�Pr��`r��utf-16be��c3s�|]}��|�VqdSr)r�)r��xrrrr�Os�z2_BinaryPlistParser._read_object.<locals>.<genexpr>��)r�r�r�r�r�r�rr�r�r�rEZ	timedeltar�r2rr�rr��extendrZ�zipr�r)r�ref�result�offset�tokenZtokenHr�r�r6rZobj_refsZkey_refs�k�orrrr�s�


�
�
�










��
z_BinaryPlistParser._read_objectN)
rr+r,�__doc__rrcr�r�r�r�rrrrr��s

r�cCs(|dkrdS|dkrdS|dkrdSdS)N�r��r��r.r�r)�countrrr�_count_to_sizehsrc@r)�_BinaryPlistWritercCs||_||_||_dSr)r�r�r�)rr�r�r�rrrrxs
z_BinaryPlistWriter.__init__c
Cs�g|_i|_i|_|�|�t|j�}dg||_t|�|_t|j|_	|j
�d�|jD]}|�|�q-|�
|�}|j
��}t|�}dt||}|j
�tj|g|j�R��d}|||j|||f}	|j
�tjdg|	�R��dS)Nr	�bplist00rOz	>5xBBBQQQ)�_objlist�	_objtable�_objidtable�_flattenr2r�rr�r��_ref_formatr�r��
_write_object�
_getrefnum�tellr��pack)
rrdr��objr�r�r�Z
offset_formatZsort_versionr�rrrr�}s*






�z_BinaryPlistWriter.writec	Cs$t|t�rt|�|f|jvrdSn	t|�|jvrdSt|j�}|j�|�t|t�r4||jt|�|f<n||jt|�<t|t	�r}g}g}|�
�}|jrOt|�}|D]\}}t|t
�sb|jr^qQtd��|�|�|�|�qQt�||�D]}|�|�qsdSt|ttf�r�|D]	}|�|�q�dSdS)Nr�)r�_scalarsrlr
�idrr2r	r3r�r�r�r�r=r�r�	itertools�chainrr�r�)	rrdZrefnum�keys�valuesr�r��vrrrrr�s@
�




��z_BinaryPlistWriter._flattencCs*t|t�r|jt|�|fS|jt|�Sr)rrr
rlrrrnrrrr�s
z_BinaryPlistWriter._getrefnumcCs�|dkr|j�t�d||B��dS|dkr&|j�t�d|dBd|��dS|dkr:|j�t�d|dBd|��dS|d	krN|j�t�d
|dBd|��dS|j�t�d|dBd
|��dS)Nr�z>Brz>BBBr}rz>BBH�rz>BBL�z>BBQ�)r�r�r�r)rr�r�rrr�_write_size�s    z_BinaryPlistWriter._write_sizecsj��|�}�j���j|<|dur�j�d�dS|dur%�j�d�dS|dur1�j�d�dSt|t�r�|dkrVz�j�t�dd|��WdStj	yUt
|�d�w|d	krg�j�t�d
d|��dS|dkrx�j�t�d
d|��dS|dkr��j�t�dd|��dS|dkr��j�t�dd|��dS|dkr��j�d|jdddd��dSt
|��t|t�rĈj�t�dd|��dSt|t
j
�r�|t
�
ddd���}�j�t�dd|��dSt|ttf�r���dt|���j�|�dSt|t��r0z|�d�}��dt|��Wnt�y'|�d �}��d!t|�d"�Ynw�j�|�dSt|t��r�|jdk�r@td#��|jd	k�rS�j�t�d
d$|��dS|jdk�rf�j�t�d
d%|��dS|jdk�ry�j�t�dd&|��dS|jdk�r��j�t�dd'|��dSt
|��t|ttf��r��fd(d)�|D�}t|�}��d*|��j�tjd+�j|g|�R��dSt|t��r1gg}}�j�r�t|���}	n|��}	|	D]%\}
}t|
t��s�j �r�q�t!d,��|�"��|
��|�"��|���q�t|�}��d-|��j�tjd+�j|g|�R���j�tjd+�j|g|�R��dSt!|��).N�F�Tr�r	z>Bqrrz>BBr}rz>BHrrz>BLrlz>BQr�r�r�z>Bdr�r�r�r�r�r�r�r�r�r�rr����csg|]}��|��qSr)r)r�rrrr�
<listcomp>-sz4_BinaryPlistWriter._write_object.<locals>.<listcomp>r�rOr�r�)#rr�rr�r�rrr�rr�r��to_bytesr�rEZ
total_secondsr�r�rr2r=r>�UnicodeEncodeErrorrrrr�r�r
r�r�r�r�r�rr3)rrdr�r��tZrefsr6ZkeyRefsZvalRefsZ	rootItemsr�rrrrr�s�


� 


�(
$(z _BinaryPlistWriter._write_objectN)	rr+r,rr�rrrrrrrrrws-*rcCs|dd�dkS)Nr�rr)r�rrr�_is_fmt_binaryKrjr()�detectr^�writer��fmtr\cCsj|dur%|�d�}|�d�t��D]}|d|�r |d}nqt��nt|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^)r\)r�r��_FORMATSrrrc)r�r,r\r��info�P�prrrras

��

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)rdr,r\r�rrrrwsrTF)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�)rdr�r,r�r�r*rrrrsr�r,r�r�cCs t�}t|||||d�|��S)z?Return a bytes object with the contents for a .plist file.
    r1)r
r�getvalue)rdr,r�r�r�rrrr�sr)r-)9r�__all__r4r�rE�enum�ior
rr��rer�Zxml.parsers.expatr�Enumrr�globals�update�__members__rr��compilerPr;r?�ASCIIrBrHrJrUrVr�r�r�rrr��objectr�r�rr=rr�r�rrr(rr�rr-rrrrrrrr�<module>sl8!�
	
n&^!!
U	���

?>