a
    ãzeXn  ã                   @   sÔ  d Z g d¢ZddlZddlZddlZddlZddlmZ ddlZddl	Z	ddl
Z
ddlZddlmZ ejddedZeƒ  ej¡ G d	d
„ d
ƒZdZe
 d¡Zd>dd„Zdd„ Ze
 de
j¡Zdd„ Zdd„ Zdd„ ZG dd„ dƒZG dd„ dƒZ G dd„ de ƒZ!dd „ Z"G d!d"„ d"e#ƒZ$d#d$d%d&d'œZ%e&ƒ Z'G d(d)„ d)ƒZ(d*d+„ Z)e*e+e,eje-fZ.G d,d-„ d-e&ƒZ/d.d/„ Z0e1e2e"ee!d0e3e2e0e(e/d0iZ4de2d1œd2d3„Z5de2d1œd4d5„Z6e1d6d7d8œd9d:„Z7e1d7d6d;œd<d=„Z8dS )?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:

    pl = dict(
        aString = "Doodah",
        aList = ["A", "B", 12, 32.1, [1, 2, 3]],
        aFloat = 0.1,
        anInt = 728,
        aDict = dict(
            anotherString = "<hello & hi there!>",
            aUnicodeValue = "M\xe4ssig, Ma\xdf",
            aTrueValue = True,
            aFalseValue = False,
        ),
        someData = b"<binary gunk>",
        someMoreData = b"<lots of binary gunk>" * 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ÚPlistFormatzFMT_XML FMT_BINARY)Úmodulec                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )r   c                 C   s<   t |tƒstdƒ‚|dkr"tdƒ‚|dk r2tdƒ‚|| _d S )Nzdata must be an intì            zUIDs cannot be >= 2**64r	   úUIDs must be positive)Ú
isinstanceÚintÚ	TypeErrorÚ
ValueErrorÚdata©Úselfr   © r   ú/usr/lib/python3.9/plistlib.pyÚ__init__E   s    
zUID.__init__c                 C   s   | j S ©N)r   ©r   r   r   r   Ú	__index__N   s    zUID.__index__c                 C   s   d| j jt| jƒf S )Nz%s(%s))Ú	__class__Ú__name__Úreprr   r   r   r   r   Ú__repr__Q   s    zUID.__repr__c                 C   s   | j | jffS r   )r   r   r   r   r   r   Ú
__reduce__T   s    zUID.__reduce__c                 C   s   t |tƒstS | j|jkS r   )r   r   ÚNotImplementedr   )r   Úotherr   r   r   Ú__eq__W   s    
z
UID.__eq__c                 C   s
   t | jƒS r   )Úhashr   r   r   r   r   Ú__hash__\   s    zUID.__hash__N)	r   Ú
__module__Ú__qualname__r   r   r    r!   r$   r&   r   r   r   r   r   D   s   	r   sŽ   <?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]éL   c                 C   sP   |d d }g }t dt| ƒ|ƒD ]$}| ||| … }| t |¡¡ q d |¡S )Né   é   r	   ó    )ÚrangeÚlenÚappendÚbinasciiZ
b2a_base64Újoin)ÚsÚmaxlinelengthZ
maxbinsizeÚpiecesÚiÚchunkr   r   r   Ú_encode_base64p   s    r7   c                 C   s(   t | tƒrt |  d¡¡S t | ¡S d S )Núutf-8)r   Ústrr0   Z
a2b_base64Úencode)r2   r   r   r   Ú_decode_base64y   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))?)?)?)?)?Zc                 C   sL   d}t  | ¡ ¡ }g }|D ]&}|| }|d u r2 qB| t|ƒ¡ qtj|Ž S )N©ZyearZmonthZdayZhourZminuteÚsecond)Ú_dateParserÚmatchÚ	groupdictr/   r   Údatetime)r2   ÚorderÚgdZlstÚkeyÚvalr   r   r   Ú_date_from_string†   s    rF   c                 C   s    d| j | j| j| j| j| jf S )Nz%04d-%02d-%02dT%02d:%02d:%02dZr<   )Údr   r   r   Ú_date_to_string’   s    þrH   c                 C   sZ   t  | ¡}|d urtdƒ‚|  dd¡} |  dd¡} |  dd¡} |  dd¡} |  d	d
¡} | S )Nz<strings can't contains control characters; use bytes insteadz
Ú
úú&z&amp;ú<z&lt;ú>z&gt;)Ú_controlCharPatÚsearchr   Úreplace)ÚtextÚmr   r   r   Ú_escape˜   s    
rS   c                   @   s¬   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)S )*Ú_PlistParserc                 C   s   g | _ d | _d | _|| _d S r   )ÚstackÚcurrent_keyÚrootÚ
_dict_type©r   Ú	dict_typer   r   r   r   ¥   s    z_PlistParser.__init__c                 C   sB   t ƒ | _| j| j_| j| j_| j| j_| j| j_	| j 
|¡ | jS r   )r   ÚparserÚhandle_begin_elementZStartElementHandlerÚhandle_end_elementZEndElementHandlerÚhandle_dataZCharacterDataHandlerÚhandle_entity_declZEntityDeclHandlerZ	ParseFilerW   )r   Úfileobjr   r   r   Úparse«   s    



z_PlistParser.parsec                 C   s   t dƒ‚d S )Nz8XML entity declarations are not supported in plist files)r   )r   Zentity_nameZis_parameter_entityÚvalueÚbaseZ	system_idZ	public_idZnotation_namer   r   r   r_   ´   s    z_PlistParser.handle_entity_declc                 C   s*   g | _ t| d| d ƒ}|d ur&||ƒ d S )NZbegin_)r   Úgetattr)r   ÚelementÚattrsÚhandlerr   r   r   r\   º   s    z!_PlistParser.handle_begin_elementc                 C   s"   t | d| d ƒ}|d ur|ƒ  d S )NZend_)rd   )r   re   rg   r   r   r   r]   À   s    z_PlistParser.handle_end_elementc                 C   s   | j  |¡ d S r   )r   r/   r   r   r   r   r^   Å   s    z_PlistParser.handle_datac                 C   sŒ   | j d urFt| jd ti ƒƒs.td| jj ƒ‚|| jd | j < d | _ nB| jsT|| _n4t| jd tg ƒƒsxtd| jj ƒ‚| jd  |¡ d S )Néÿÿÿÿzunexpected element at line %d)	rV   r   rU   Útyper   r[   ÚCurrentLineNumberrW   r/   ©r   rb   r   r   r   Ú
add_objectÈ   s    
ÿÿz_PlistParser.add_objectc                 C   s   d  | j¡}g | _|S )NÚ )r1   r   r   r   r   r   Úget_dataØ   s    z_PlistParser.get_datac                 C   s"   |   ¡ }|  |¡ | j |¡ d S r   )rX   rl   rU   r/   )r   rf   rG   r   r   r   Ú
begin_dictß   s    
z_PlistParser.begin_dictc                 C   s*   | j rtd| j | jjf ƒ‚| j ¡  d S )Nz%missing value for key '%s' at line %d)rV   r   r[   rj   rU   Úpopr   r   r   r   Úend_dictä   s
    ÿz_PlistParser.end_dictc                 C   s8   | j st| jd ti ƒƒs*td| jj ƒ‚|  ¡ | _ d S )Nrh   zunexpected key at line %d)rV   r   rU   ri   r   r[   rj   rn   r   r   r   r   Úend_keyê   s
    ÿz_PlistParser.end_keyc                 C   s   g }|   |¡ | j |¡ d S r   )rl   rU   r/   )r   rf   Úar   r   r   Úbegin_arrayð   s    
z_PlistParser.begin_arrayc                 C   s   | j  ¡  d S r   )rU   rp   r   r   r   r   Ú	end_arrayõ   s    z_PlistParser.end_arrayc                 C   s   |   d¡ d S )NT©rl   r   r   r   r   Úend_trueø   s    z_PlistParser.end_truec                 C   s   |   d¡ d S )NFrv   r   r   r   r   Ú	end_falseû   s    z_PlistParser.end_falsec                 C   s@   |   ¡ }| d¡s| d¡r.|  t|dƒ¡ n|  t|ƒ¡ d S )NÚ0xZ0Xé   )rn   Ú
startswithrl   r   )r   Úrawr   r   r   Úend_integerþ   s    z_PlistParser.end_integerc                 C   s   |   t|  ¡ ƒ¡ d S r   )rl   Úfloatrn   r   r   r   r   Úend_real  s    z_PlistParser.end_realc                 C   s   |   |  ¡ ¡ d S r   )rl   rn   r   r   r   r   Ú
end_string  s    z_PlistParser.end_stringc                 C   s   |   t|  ¡ ƒ¡ d S r   )rl   r;   rn   r   r   r   r   Úend_data  s    z_PlistParser.end_datac                 C   s   |   t|  ¡ ƒ¡ d S r   )rl   rF   rn   r   r   r   r   Úend_date  s    z_PlistParser.end_dateN)r   r'   r(   r   ra   r_   r\   r]   r^   rl   rn   ro   rq   rr   rt   ru   rw   rx   r}   r   r€   r   r‚   r   r   r   r   rT   ¤   s(   	rT   c                   @   s8   e Zd Zddd„Zdd„ Zdd„ Zdd
d„Zdd„ Zd	S )Ú_DumbXMLWriterr	   ú	c                 C   s   || _ g | _|| _|| _d S r   )ÚfilerU   Ú_indent_levelÚindent)r   r…   Úindent_levelr‡   r   r   r   r     s    z_DumbXMLWriter.__init__c                 C   s,   | j  |¡ |  d| ¡ |  jd7  _d S )Nz<%s>é   )rU   r/   Úwritelnr†   ©r   re   r   r   r   Úbegin_element  s    z_DumbXMLWriter.begin_elementc                 C   s@   | j dksJ ‚| j ¡ |ks J ‚|  j d8  _ |  d| ¡ d S )Nr	   r‰   z</%s>)r†   rU   rp   rŠ   r‹   r   r   r   Úend_element  s    z_DumbXMLWriter.end_elementNc                 C   s8   |d ur&t |ƒ}|  d|||f ¡ n|  d| ¡ d S )Nz<%s>%s</%s>z<%s/>)rS   rŠ   )r   re   rb   r   r   r   Úsimple_element$  s    z_DumbXMLWriter.simple_elementc                 C   sH   |r8t |tƒr| d¡}| j | j| j ¡ | j |¡ | j d¡ d S )Nr8   ó   
)r   r9   r:   r…   Úwriter†   r‡   )r   Úliner   r   r   rŠ   ,  s    

z_DumbXMLWriter.writeln)r	   r„   )N)r   r'   r(   r   rŒ   r   rŽ   rŠ   r   r   r   r   rƒ     s
   

rƒ   c                   @   s>   e Zd Zddd„Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ ZdS )Ú_PlistWriterr	   ó   	r‰   TFc                 C   s.   |r|  t¡ t | |||¡ || _|| _d S r   )r   ÚPLISTHEADERrƒ   r   Ú
_sort_keysÚ	_skipkeys)r   r…   rˆ   r‡   ZwriteHeaderÚ	sort_keysÚskipkeysr   r   r   r   9  s
    
z_PlistWriter.__init__c                 C   s"   |   d¡ |  |¡ |   d¡ d S )Nz<plist version="1.0">z</plist>)rŠ   Úwrite_valuerk   r   r   r   r   C  s    

z_PlistWriter.writec                 C   s  t |tƒr|  d|¡ nü|du r,|  d¡ nè|du r@|  d¡ nÔt |tƒr~d|  kr^dk rtn n|  dd	| ¡ nt|ƒ‚n–t |tƒrš|  d
t|ƒ¡ nzt |tƒr°|  |¡ ndt |t	t
fƒrÊ|  |¡ nJt |tjƒrè|  dt|ƒ¡ n,t |ttfƒr|  |¡ ntdt|ƒ ƒ‚d S )NÚstringTÚtrueFZfalselûÿÿÿ         r   Zintegerz%dÚrealÚdatezunsupported type: %s)r   r9   rŽ   r   ÚOverflowErrorr~   r   ÚdictÚ
write_dictÚbytesÚ	bytearrayÚwrite_bytesrA   rH   ÚtupleÚlistÚwrite_arrayr   ri   rk   r   r   r   r™   H  s*    




z_PlistWriter.write_valuec                 C   sz   |   d¡ |  jd8  _tddt| j dd¡| j ƒ ƒ}t||ƒ d¡D ]}|rJ|  |¡ qJ|  jd7  _|  	d¡ d S )Nr   r‰   rz   r)   r“   s           r   )
rŒ   r†   Úmaxr.   r‡   rP   r7   ÚsplitrŠ   r   )r   r   r3   r‘   r   r   r   r£   j  s    
þz_PlistWriter.write_bytesc                 C   s‚   |rt|   d¡ | jr"t| ¡ ƒ}n| ¡ }|D ]8\}}t|tƒsP| jrHq.tdƒ‚|  d|¡ |  	|¡ q.|  
d¡ n
|  d¡ d S )NrŸ   úkeys must be stringsrD   )rŒ   r•   ÚsortedÚitemsr   r9   r–   r   rŽ   r™   r   )r   rG   r«   rD   rb   r   r   r   r    w  s    

z_PlistWriter.write_dictc                 C   s<   |r.|   d¡ |D ]}|  |¡ q|  d¡ n
|  d¡ d S )NÚarray)rŒ   r™   r   rŽ   )r   r¬   rb   r   r   r   r¦   ‹  s    
z_PlistWriter.write_arrayN)r	   r“   r‰   TF)	r   r'   r(   r   r   r™   r£   r    r¦   r   r   r   r   r’   8  s     þ

"r’   c                 C   sŽ   d}|D ]}|   |¡r dS qtjdftjdftjdffD ]N\}}|   |¡sNq:|D ]4}|| d¡ |¡ }| d t|ƒ… |krR  dS qRq:dS )N)s   <?xmls   <plistTr8   z	utf-16-bez	utf-16-leÚasciiF)r{   ÚcodecsÚBOM_UTF8ÚBOM_UTF16_BEÚBOM_UTF16_LEÚdecoder:   r.   )ÚheaderÚprefixesZpfxZbomÚencodingÚstartÚprefixr   r   r   Ú_is_fmt_xml–  s    
ý
r¸   c                   @   s   e Zd Zddd„ZdS )r   úInvalid filec                 C   s   t  | |¡ d S r   )r   r   )r   Úmessager   r   r   r   ¸  s    zInvalidFileException.__init__N)r¹   )r   r'   r(   r   r   r   r   r   r   ·  s   r   ÚBÚHÚLÚQ)r‰   é   r*   é   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú_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
    c                 C   s
   || _ d S r   )rX   rY   r   r   r   r   Ç  s    z_BinaryPlistParser.__init__c                 C   s¨   z~|| _ | j  dtj¡ | j  d¡}t|ƒdkr6tƒ ‚t d|¡\}| _	}}}| j  |¡ |  
||¡| _tg| | _|  |¡W S  tttjttfy¢   tƒ ‚Y n0 d S )Niàÿÿÿé    z>6xBBQQQ)Ú_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_offsetr   r   r   ra   Ê  s$    
ý
ÿ
z_BinaryPlistParser.parsec                 C   sL   |dkrH| j  d¡d d@ }d|> }dt|  }t || j  |¡¡d S |S )z$ return the size of the next object.é   r‰   r	   r+   rM   )rÃ   rÇ   Ú_BINARY_FORMATrÈ   rÉ   )r   ÚtokenLrR   r2   Úfr   r   r   Ú	_get_sizeã  s    z_BinaryPlistParser._get_sizec                    st   | j  ˆ| ¡‰ ˆtv r2t d|› tˆ › ˆ ¡S ˆrFtˆ ƒˆ| krLtƒ ‚t‡ ‡fdd„tdˆ| ˆƒD ƒƒS d S )NrM   c                 3   s&   | ]}t  ˆ ||ˆ … d ¡V  qdS )ÚbigN)r   Ú
from_bytes)Ú.0r5   ©r   Úsizer   r   Ú	<genexpr>ô  s   ÿz0_BinaryPlistParser._read_ints.<locals>.<genexpr>r	   )	rÃ   rÇ   rÚ   rÈ   rÉ   r.   r   r¤   r-   )r   Únrâ   r   rá   r   rË   í  s    ÿz_BinaryPlistParser._read_intsc                 C   s   |   || j¡S r   )rË   rÊ   )r   rä   r   r   r   Ú
_read_refs÷  s    z_BinaryPlistParser._read_refsc                    s
  ˆ j | }|tur|S ˆ j| }ˆ j |¡ ˆ j d¡d }|d@ |d@  }}|dkr^d}nž|dkrnd}nŽ|dkr~d	}n~|dkrŽd
}nn|dkrºtjˆ j d|> ¡d|dkd}nB|dkrÞt 	dˆ j d¡¡d }n|dkrt 	dˆ j d¡¡d }nø|dkrDt 	dˆ j d¡¡d }t
 
ddd¡t
j|d }n¸|dkr|ˆ  |¡}ˆ j |¡}t|ƒ|krütƒ ‚n€|dkr¾ˆ  |¡}ˆ j |¡}	t|	ƒ|kr°tƒ ‚|	 d¡}n>|dkrˆ  |¡d }ˆ j |¡}	t|	ƒ|krötƒ ‚|	 d¡}nú|dkr*tt ˆ j d| ¡d¡ƒ}nÒ|dkrpˆ  |¡}ˆ  |¡}
g }|ˆ j |< | ‡ fdd „|
D ƒ¡ nŒ|d!kröˆ  |¡}ˆ  |¡}ˆ  |¡}
ˆ  ¡ }|ˆ j |< z.t||
ƒD ]\}}ˆ  |¡|ˆ  |¡< q¶W n tyò   tƒ ‚Y n0 ntƒ ‚|ˆ 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,   rz   rÞ   r+   ©Úsignedé"   z>fr*   é#   z>dé3   éÑ  )Zsecondsé@   éP   r­   é`   r¿   úutf-16beé€   é    c                 3   s   | ]}ˆ   |¡V  qd S r   )rÏ   )rà   Úxr   r   r   rã   F  r,   z2_BinaryPlistParser._read_object.<locals>.<genexpr>éÐ   )rÎ   rÍ   rÌ   rÃ   rÄ   rÇ   r   rß   rÈ   rÉ   rA   Z	timedeltarÝ   r.   r   r²   r   rå   ÚextendrX   ÚziprÏ   r   )r   ÚrefÚresultÚoffsetÚtokenZtokenHrÛ   rÜ   r2   r   Zobj_refsZkey_refsÚkÚor   r   r   rÏ   ú  s†    

ÿ



ÿ
















z_BinaryPlistParser._read_objectN)
r   r'   r(   Ú__doc__r   ra   rÝ   rË   rå   rÏ   r   r   r   r   rÁ   ¿  s   

rÁ   c                 C   s,   | dk rdS | dk rdS | dk r$dS dS d S )Né   r‰   é   r¿   ì        r*   rÀ   r   )Úcountr   r   r   Ú_count_to_size_  s    r  c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )Ú_BinaryPlistWriterc                 C   s   || _ || _|| _d S r   )rÃ   r•   r–   )r   rÓ   r—   r˜   r   r   r   r   o  s    z_BinaryPlistWriter.__init__c           
      C   sæ   g | _ i | _i | _|  |¡ t| j ƒ}dg| | _t|ƒ| _t| j | _	| j
 d¡ | j D ]}|  |¡ qZ|  |¡}| j
 ¡ }t|ƒ}dt| |  }| j
 tj|g| j¢R Ž ¡ d}||| j|||f}	| j
 tjdg|	¢R Ž ¡ d S )Nr	   ó   bplist00rM   z	>5xBBBQQQ)Ú_objlistÚ	_objtableÚ_objidtableÚ_flattenr.   rÌ   r  rÊ   rÚ   Ú_ref_formatrÃ   r   Ú_write_objectÚ
_getrefnumÚtellrÈ   Úpack)
r   rb   rÖ   Úobjr×   rØ   rÕ   Zoffset_formatZsort_versionrÔ   r   r   r   r   t  s*    






þz_BinaryPlistWriter.writec           	      C   s"  t |tƒr"t|ƒ|f| jv r4d S nt|ƒ| jv r4d S t| jƒ}| j |¡ t |tƒrh|| jt|ƒ|f< n|| jt|ƒ< t |t	ƒrøg }g }| 
¡ }| jržt|ƒ}|D ]6\}}t |tƒsÄ| jr¼q¢tdƒ‚| |¡ | |¡ q¢t ||¡D ]}|  |¡ qæn&t |ttfƒr|D ]}|  |¡ qd S )Nr©   )r   Ú_scalarsri   r  Úidr  r.   r  r/   rŸ   r«   r•   rª   r9   r–   r   Ú	itertoolsÚchainr	  r¥   r¤   )	r   rb   ZrefnumÚkeysÚvaluesr«   rü   Úvrý   r   r   r   r	  ¡  s8    





z_BinaryPlistWriter._flattenc                 C   s.   t |tƒr| jt|ƒ|f S | jt|ƒ S d S r   )r   r  r  ri   r  r  rk   r   r   r   r  Ë  s    
z_BinaryPlistWriter._getrefnumc                 C   s´   |dk r"| j  t d||B ¡¡ nŽ|dk rH| j  t d|dB d|¡¡ nh|dk rn| j  t d|dB d|¡¡ nB|d	k r”| j  t d
|dB d|¡¡ n| j  t d|dB d|¡¡ d S )NrÙ   z>Brÿ   z>BBBrz   r   z>BBHé   r  z>BBLé   z>BBQé   )rÃ   r   rÈ   r  )r   rû   râ   r   r   r   Ú_write_sizeÑ  s    z_BinaryPlistWriter._write_sizec                    st  ˆ   |¡}ˆ j ¡ ˆ j|< |d u r2ˆ j d¡ n>|du rJˆ j d¡ n&|du rbˆ j d¡ nt|tƒrj|dk r²zˆ j t dd|¡¡ W n tj	y®   t
|ƒd ‚Y n0 n´|d	k rÒˆ j t d
d|¡¡ n”|dk ròˆ j t dd|¡¡ nt|dk rˆ j t dd|¡¡ nR|dk r6ˆ j t dd|¡¡ n0|dk r^ˆ j d|jdddd ¡ nt
|ƒ‚nt|tƒrˆ j t dd|¡¡ nàt|tjƒrÎ|t ddd¡  ¡ }ˆ j t dd|¡¡ n¢t|ttfƒrþˆ  dt|ƒ¡ ˆ j |¡ nrt|tƒrlz| d¡}ˆ  dt|ƒ¡ W n2 tyZ   | d ¡}ˆ  d!t|ƒd" ¡ Y n0 ˆ j |¡ nt|tƒr*|jdk rŽtd#ƒ‚n˜|jd	k r²ˆ j t d
d$|¡¡ nt|jdk rÖˆ j t dd%|¡¡ nP|jdk rúˆ j t dd&|¡¡ n,|jdk rˆ j t dd'|¡¡ nt
|ƒ‚nFt|ttfƒr†‡ fd(d)„|D ƒ}t|ƒ}ˆ  d*|¡ ˆ j tjd+ˆ j|  g|¢R Ž ¡ nêt|tƒrhg g  }}ˆ jr²t| ¡ ƒ}	n| ¡ }	|	D ]J\}
}t|
tƒsæˆ j rÞq¾t!d,ƒ‚| "ˆ   |
¡¡ | "ˆ   |¡¡ q¾t|ƒ}ˆ  d-|¡ ˆ j tjd+ˆ j|  g|¢R Ž ¡ ˆ j tjd+ˆ j|  g|¢R Ž ¡ nt!|ƒ‚d S ).Nó    Fó   Tr“   r	   z>Bqr  rÿ   z>BBrz   r   z>BHr  r  z>BLr  l            z>BQr   ó   rÞ   rè   z>Bdrë   rí   r‰   rì   rî   r­   rï   rñ   rð   r¿   r   rò   é   éƒ   é‡   c                    s   g | ]}ˆ   |¡‘qS r   )r  )rà   rý   r   r   r   Ú
<listcomp>$  r,   z4_BinaryPlistWriter._write_object.<locals>.<listcomp>ró   rM   r©   rõ   )#r  rÃ   r  rÌ   r   r   r   rÈ   r  rÒ   rž   Úto_bytesr~   rA   Ztotal_secondsr¡   r¢   r  r.   r9   r:   ÚUnicodeEncodeErrorr   r   r   r¥   r¤   r
  rŸ   r•   rª   r«   r–   r   r/   )r   rb   rø   rÜ   ÚtZrefsr2   ZkeyRefsZvalRefsZ	rootItemsrü   r  r   r   r   r  á  s–    






&
$&z _BinaryPlistWriter._write_objectN)	r   r'   r(   r   r   r	  r  r  r  r   r   r   r   r  n  s   -*r  c                 C   s   | d d… dkS )NrÀ   r  r   )r³   r   r   r   Ú_is_fmt_binaryB  s    r%  )Údetectr[   Úwriter©ÚfmtrZ   c                C   sj   |du rJ|   d¡}|  d¡ t ¡ D ]}|d |ƒr$|d } qVq$tƒ ‚nt| d }||d}| | ¡S )zRead 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Ä   Ú_FORMATSr  r   ra   )rÓ   r)  rZ   r³   ÚinfoÚPÚpr   r   r   r   X  s    


r   c                C   s   t | ƒ}t|||dS )zqRead a .plist file from a bytes object.
    Return the unpacked root object (which usually is a dictionary).
    r(  )r
   r   )rb   r)  rZ   rÓ   r   r   r   r   n  s    r   TF)r)  r—   r˜   c                C   s:   |t vrtd|f ƒ‚t | d |||d}| | ¡ dS )zWWrite 'value' to a .plist file. 'fp' should be a writable,
    binary file object.
    zUnsupported format: %rr'  )r—   r˜   N)r*  r   r   )rb   rÓ   r)  r—   r˜   r'  r   r   r   r   v  s    r   ©r)  r˜   r—   c                C   s    t ƒ }t| ||||d | ¡ S )z?Return a bytes object with the contents for a .plist file.
    r.  )r
   r   Úgetvalue)rb   r)  r˜   r—   rÓ   r   r   r   r     s    r   )r)   )9rþ   Ú__all__r0   r®   rA   ÚenumÚior
   r  rÅ   ÚrerÈ   Zxml.parsers.expatr   ÚEnumr   r   ÚglobalsÚupdateÚ__members__r   r”   ÚcompilerN   r7   r;   ÚASCIIr>   rF   rH   rS   rT   rƒ   r’   r¸   r   r   rÚ   ÚobjectrÍ   rÁ   r  r9   r   r~   r¡   r  r  r%  r   rŸ   r   r*  r   r   r   r   r   r   r   r   Ú<module>   sj   /!ÿ
	
n&^! ! U	ýýú