
    2h"U                        U d dl Zd dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZ d dlZd dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ dZ dZ!dZ" ejF                  dejH                        Z%de&defdZ'dede&fdZ( G d d      Z)	 dJde*de
e+   de+de*fdZ,ee-e*e)ee.eee&ef   ee   e&f	   Z/ G d d      Z0de0ddfdZ1de0ddfdZ2de0ddfdZ3de0ddfd Z4de0ddfd!Z5de0ddfd"Z6de0ddfd#Z7de0ddfd$Z8de0ddfd%Z9de0ddfd&Z:de0ddfd'Z;de0ddfd(Z<e1e4d)Z=ee&ee0gdf   f   e>d*<   e2e5e3e6e7e8e9e:e;e<d+
Z?ee&ee0gdf   f   e>d,<   d-e&d.edej                  fd/ZAd-e-d.edej                  fd0ZBd-e+d.edej                  fd1ZCd-e.d.edej                  fd2ZDdee&e/f   d.edej                  fd3ZEd4ee/   d.edej                  fd5ZFd6ed.edej                  fd7ZGde*d.edej                  fd8ZHd9e*d.edej                  fd:ZIed-e/d.edej                  fd;       ZJ eJj                  e&      eA        eJj                  e-      eB        eJj                  e      eC        eJj                  e.      eD        eJj                  ej                  j                        eE        eJj                  eM      eF        eJj                  eN      eF        eJj                  e      eG        eJj                  e*      eI        eJj                  eO      eH        eJj                  e)      d<        	 	 	 	 	 dKd-e/d=e-d>e-d?e
e-   d@e-de+dej                  fdAZPdeQfdBej                  d?e
e-   dCee	e&ef      defdDZRdeQfdEee*   d?e
e-   dCee	e&ef      defdFZSdeQfd-e*d?e
e-   dCee	e&ef      defdGZT	 	 	 	 dLd-e/dEee*   d=e-d>e-d?e
e-   d@e-ddfdHZU	 	 	 	 dLd-e/d=e-d>e-d?e
e-   d@e-de*fdIZVy)M    N)AnyCallableDictListMappingMutableMappingOptionalSequenceTypeUnionIO)BytesIO)datetime)	b64encode	b64decode)Integral)SimpleNamespace)singledispatch)etree)tostrTs&   <?xml version='1.0' encoding='UTF-8'?>sf   <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">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))?)?)?)?)?Zsreturnc                     d}t         j                  |       }|t        d| dd      |j                         }g }|D ],  }||   }|	 t        | S |j	                  t        |             . t        | S )Nyearmonthdayhourminutesecondz(Expected ISO 8601 date string, but got 'rz'.)_date_parsermatch
ValueError	groupdictappendintr   )r   ordermgdlstkeyvals          ED:\jyotish\venv\Lib\site-packages\fontTools/misc/plistlib/__init__.py_date_from_stringr/   A   s    @E1AyCAa5KLL	
B
Cg; S> 	

3s8	  S>    dc                     d| j                   | j                  | j                  | j                  | j                  | j
                  fz  S )Nz%04d-%02d-%02dT%02d:%02d:%02dZr   )r1   s    r.   _date_to_stringr3   Q   s>    +						/  r0   c                   v    e Zd ZdZdeddfdZedeeef   dd fd       Z	dde
de
defd	Zd
edefdZdefdZy)DataaJ  Represents binary data when ``use_builtin_types=False.``

    This class wraps binary data loaded from a plist file when the
    ``use_builtin_types`` argument to the loading function (:py:func:`fromtree`,
    :py:func:`load`, :py:func:`loads`) is false.

    The actual binary data is retrieved using the ``data`` attribute.
    datar   Nc                 t    t        |t              s!t        dt        |      j                  z        || _        y )NzExpected bytes, found %s)
isinstancebytes	TypeErrortype__name__r6   selfr6   s     r.   __init__zData.__init__f   s.    $&6d9L9LLMM	r0   c                 $     | t        |            S N)r   )clsr6   s     r.   
fromBase64zData.fromBase64k   s    9T?##r0   maxlinelengthindent_levelc                 2    t        | j                  ||      S )NrD   rE   )_encode_base64r6   )r>   rD   rE   s      r.   asBase64zData.asBase64o   s    II]
 	
r0   otherc                     t        || j                        r| j                  |j                  k(  S t        |t              r| j                  |k(  S t        S rA   )r8   	__class__r6   r9   NotImplemented)r>   rJ   s     r.   __eq__zData.__eq__t   sB    eT^^,99

**u%99%%!!r0   c                 `    | j                   j                  dt        | j                        dS )N())rL   r<   reprr6   r>   s    r.   __repr__zData.__repr__|   s    >>22DODDr0   L      )r<   
__module____qualname____doc__r9   r?   classmethodr   strrC   r'   rI   r   boolrN   rT    r0   r.   r5   r5   \   s    U t 
 $eE3J/ $F $ $
c 
c 
% 

"C "D "E# Er0   r5   r6   rD   rE   c                 2   t        |       } | r|rdd|z  z   }t        d|t        |      z
        }g }t        dt        |       |      D ]*  }|j	                  |       |j	                  | |||z           , |j	                  |       dj                  |      } | S )N   
s        r   r0   )r   maxlenranger&   join)r6   rD   rE   indent
max_lengthchunksis          r.   rH   rH      s     T?D--]S[89
q#d)Z0AMM&!MM$q1z>23 1 	fxxKr0   c                       e Zd ZdZdefdee   deee	e
f      ddfdZde	dee	e	f   ddfd	Zde	ddfd
Zde	ddfdZdefdZdeddfdZde	fdZy)PlistTargeta  Event handler using the ElementTree Target API that can be
    passed to a XMLParser to produce property list objects from XML.
    It is based on the CPython plistlib module's _PlistParser class,
    but does not use the expat parser.

    >>> from fontTools.misc import etree
    >>> parser = etree.XMLParser(target=PlistTarget())
    >>> result = etree.XML(
    ...     "<dict>"
    ...     "    <key>something</key>"
    ...     "    <string>blah</string>"
    ...     "</dict>",
    ...     parser=parser)
    >>> result == {"something": "blah"}
    True

    Links:
    https://github.com/python/cpython/blob/main/Lib/plistlib.py
    http://lxml.de/parsing.html#the-target-parser-interface
    Nuse_builtin_types	dict_typer   c                     g | _         d | _        d | _        |t        | _        || _        y |du rt        j                  dt               || _        || _        y )NFzJSetting use_builtin_types to False is deprecated and will be removed soon.)	stackcurrent_keyrootUSE_BUILTIN_TYPES_use_builtin_typeswarningswarnDeprecationWarning
_dict_type)r>   rl   rm   s      r.   r?   zPlistTarget.__init__   s`    
 ,.
*..2	$&7D# $ !E)$&
 '8D##r0   tagattribc                 R    g | _         t        j                  |      }|	 ||        y y rA   )_data_TARGET_START_HANDLERSget)r>   rx   ry   handlers       r.   startzPlistTarget.start   s+     "
(,,S1DM r0   c                 D    t         j                  |      }|	 ||        y y rA   )_TARGET_END_HANDLERSr}   )r>   rx   r~   s      r.   endzPlistTarget.end   s$    &**3/DM r0   r6   c                 :    | j                   j                  |       y rA   )r{   r&   r=   s     r.   r6   zPlistTarget.data   s    

$r0   c                 H    | j                   t        d      | j                   S )NzNo root set.)rq   r$   rS   s    r.   closezPlistTarget.close   s!    99^,,yyr0   valuec                 p   | j                   X| j                  d   }t        |t        j                  j
                        st        d|z        ||| j                   <   d | _         y | j                  s|| _        y | j                  d   }t        |t              st        d|z        |j                  |       y )Nzunexpected element: %r)
rp   ro   r8   collectionsabcr   r$   rq   listr&   )r>   r   	stack_tops      r.   
add_objectzPlistTarget.add_object   s    '

2Ii)G)GH !9I!EFF*/Id&&'#DDI

2Ii. !9I!EFFU#r0   c                 J    dj                  | j                        }g | _        |S )N )re   r{   r=   s     r.   get_datazPlistTarget.get_data   s     wwtzz"
r0   )r<   rX   rY   rZ   dictr	   r]   r   r   r\   r   r?   r   r   r   r6   PlistEncodabler   r   r   r^   r0   r.   rk   rk      s    . -148$#D>$ sCx01$ 
	$( gc3h&7 D s t 
     ~ $ $4 $ # r0   rk   r>   c                 |    | j                         }| j                  |       | j                  j                  |       y rA   )rw   r   ro   r&   )r>   r1   s     r.   
start_dictr      s,    AOOAJJar0   c                     | j                   rt        d| j                   z        | j                  j                          y )Nzmissing value for key '%s')rp   r$   ro   poprS   s    r.   end_dictr      s0    58H8HHIIJJNNr0   c                     | j                   s1t        | j                  d   t        j                  j
                        st        d      | j                         | _         y )Nr   zunexpected key)rp   r8   ro   r   r   r   r$   r   rS   s    r.   end_keyr     s@    z$**R.+//:Q:QR)**}}Dr0   c                 `    g }| j                  |       | j                  j                  |       y rA   )r   ro   r&   )r>   as     r.   start_arrayr     s%     AOOAJJar0   c                 8    | j                   j                          y rA   )ro   r   rS   s    r.   	end_arrayr     s    JJNNr0   c                 &    | j                  d       y )NTr   rS   s    r.   end_truer     s    OODr0   c                 &    | j                  d       y )NFr   rS   s    r.   	end_falser     s    OOEr0   c                 T    | j                  t        | j                                      y rA   )r   r'   r   rS   s    r.   end_integerr     s    OOC()r0   c                 T    | j                  t        | j                                      y rA   )r   floatr   rS   s    r.   end_realr   !  s    OOE$--/*+r0   c                 B    | j                  | j                                y rA   )r   r   rS   s    r.   
end_stringr   %  s    OODMMO$r0   c                     | j                   r)| j                  t        | j                                      y | j                  t        j                  | j                                      y rA   )rs   r   r   r   r5   rC   rS   s    r.   end_datar   )  s=    	$--/2389r0   c                 T    | j                  t        | j                                      y rA   )r   r/   r   rS   s    r.   end_dater   0  s    OO%dmmo67r0   )r   arrayr|   )
r   r   r,   truefalseintegerrealstringr6   dater   r   ctxc                 >    t        j                  d      }| |_        |S )Nr   )r   Elementtextr   r   els      r.   _string_elementr   J  s    	x	 BBGIr0   c                 Z    | rt        j                  d      S t        j                  d      S )Nr   r   )r   r   r   r   s     r.   _bool_elementr   P  s#    }}V$$==!!r0   c                     d| cxk  rdk  r.n t        |       t        j                  d      }d| z  |_        |S t        |       )Nl         l            r   z%d)r   r   r   OverflowErrorr   s      r.   _integer_elementr   V  sG    5"7" 
 ]]9%,	

r0   c                 P    t        j                  d      }t        |       |_        |S )Nr   )r   r   rR   r   r   s      r.   _real_elementr   ^  s     	v	B5kBGIr0   c                    t        j                  d      }| j                         }|j                  rt	        |      }|xj
                  dz  c_        |D ]o  \  }}t        |t              s|j                  r#t        d      t        j                  |d      }t        |d      |_        |j                  t        ||             q |xj
                  dz  c_        |S )Nr   rW   zkeys must be stringsr,   utf-8)r   r   items	sort_keyssortedrE   r8   r\   skipkeysr:   
SubElementr   r   r&   _make_element)r1   r   r   r   r,   r   ks          r.   _dict_elementr   d  s     
v	BGGIE
}}u
U#s#||233R'sG$
		-s+,  Ir0   r   c                     t        j                  d      }t        |       dk(  r|S |xj                  dz  c_        | D ]  }|j	                  t        ||              |xj                  dz  c_        |S )Nr   r   rW   )r   r   rc   rE   r&   r   )r   r   r   r   s       r.   _array_elementr   x  sf     
w	B
5zQ	
		-s+, Ir0   r   c                 P    t        j                  d      }t        |       |_        |S )Nr   )r   r   r3   r   )r   r   r   s      r.   _date_elementr     s!    	v	Bd#BGIr0   c                     t        j                  d      }t        | |j                  rdnd |j                        |_        |S )Nr6   rV   rG   )r   r   rH   pretty_printrE   r   )r6   r   r   s      r.   _data_elementr     s<    	v	B --r4%%BG
 Ir0   	raw_bytesc                     |j                   rt        | |      S 	 | j                  dd      }t        ||      S # t        $ r t	        d| z        w xY w)Nasciistrict)encodingerrorsz7invalid non-ASCII bytes; use unicode string instead: %r)rl   r   decodeUnicodeDecodeErrorr$   r   )r   r   r   s      r.   _string_or_data_elementr     sg    
Y,,	%%wx%HF
 vs++	 " 	IIU 	s	   9 Ac                 0    t        dt        |       z        )Nzunsupported type: %s)r:   r;   r   s     r.   r   r     s    
*T%[8
99r0   c                 .    t        | j                  |      S rA   )r   r6   )vr   s     r.   <lambda>r     s    M!&&#,Fr0   r   r   rl   r   c                 P    |t         }n|}t        |||||      }t        | |      S )a  Convert a value derived from a plist into an XML tree.

    Args:
        value: Any kind of value to be serialized to XML.
        sort_keys: Whether keys of dictionaries should be sorted.
        skipkeys (bool): Whether to silently skip non-string dictionary
            keys.
        use_builtin_types (bool): If true, byte strings will be
            encoded in Base-64 and wrapped in a ``data`` tag; if
            false, they will be either stored as ASCII strings or an
            exception raised if they cannot be decoded as such. Defaults
            to ``True`` if not present. Deprecated.
        pretty_print (bool): Whether to indent the output.
        indent_level (int): Level of indentation when serializing.

    Returns: an ``etree`` ``Element`` object.

    Raises:
        ``TypeError``
            if non-string dictionary keys are serialized
            and ``skipkeys`` is false.
        ``ValueError``
            if non-ASCII binary data is present
            and `use_builtin_types` is false.
    )r   r   rl   r   rE   )rr   r   r   )r   r   r   rl   r   rE   contexts          r.   totreer     s?    B  --+!!G ((r0   treerm   c                 h   t        ||      }t        j                  | d      D ]|  \  }}|dk(  r'|j                  |j                  |j
                         2|dk(  s8t        |      s|j                  |j                  xs d       |j                  |j                         ~ |j                         S )a  Convert an XML tree to a plist structure.

    Args:
        tree: An ``etree`` ``Element``.
        use_builtin_types: If True, binary data is deserialized to
            bytes strings. If False, it is wrapped in :py:class:`Data`
            objects. Defaults to True if not provided. Deprecated.
        dict_type: What type to use for dictionaries.

    Returns: An object (usually a dictionary).
    rl   rm   )r   r   )eventsr   r   r   )rk   r   iterwalkr   rx   ry   rc   r6   r   r   r   )r   rl   rm   targetactionelements         r.   fromtreer     s      +<	RF >>$7GHWLLgnn5u_w<GLL.B/JJw{{# I <<>r0   fpc                    t        | d      s!t        dt        |       j                  z        t	        ||      }t        j                  |      }t        j                  | |      }	 |j                         S # t        $ r |cY S w xY w)a  Load a plist file into an object.

    Args:
        fp: An opened file.
        use_builtin_types: If True, binary data is deserialized to
            bytes strings. If False, it is wrapped in :py:class:`Data`
            objects. Defaults to True if not provided. Deprecated.
        dict_type: What type to use for dictionaries.

    Returns:
        An object (usually a dictionary) representing the top level of
        the plist file.
    readz#'%s' object has no attribute 'read'r   )r   )parser)	hasattrAttributeErrorr;   r<   rk   r   	XMLParserparsegetroot)r   rl   rm   r   r   results         r.   loadr     sz    & 2vBT"XEVEVVWW+<	RF__F+F[[F+F~~ s   )A9 9BBc                 4    t        |       }t        |||      S )a  Load a plist file from a string into an object.

    Args:
        value: A bytes string containing a plist.
        use_builtin_types: If True, binary data is deserialized to
            bytes strings. If False, it is wrapped in :py:class:`Data`
            objects. Defaults to True if not provided. Deprecated.
        dict_type: What type to use for dictionaries.

    Returns:
        An object (usually a dictionary) representing the top level of
        the plist file.
    r   )r   r   )r   rl   rm   r   s       r.   loadsr   -  s    & 
B&79MMr0   c                    t        |d      s!t        dt        |      j                  z        t	        j
                  dd      }t        | ||||      }|j                  |       t	        j                  |      }|rdj                  t        t        df      }	nt        t        z   }	|j                  |	       |j                  |d	|d
       y)a  Write a Python object to a plist file.

    Args:
        value: An object to write.
        fp: A file opened for writing.
        sort_keys (bool): Whether keys of dictionaries should be sorted.
        skipkeys (bool): Whether to silently skip non-string dictionary
            keys.
        use_builtin_types (bool): If true, byte strings will be
            encoded in Base-64 and wrapped in a ``data`` tag; if
            false, they will be either stored as ASCII strings or an
            exception raised if they cannot be represented. Defaults
        pretty_print (bool): Whether to indent the output.
        indent_level (int): Level of indentation when serializing.

    Raises:
        ``TypeError``
            if non-string dictionary keys are serialized
            and ``skipkeys`` is false.
        ``ValueError``
            if non-representable binary data is present
            and `use_builtin_types` is false.
    writez$'%s' object has no attribute 'write'plistz1.0)versionr   r   rl   r   r`   r0   r   F)r   r   xml_declarationN)r   r   r;   r<   r   r   r   r&   ElementTreere   XML_DECLARATIONPLIST_DOCTYPEr   )
r   r   r   r   rl   r   rq   r   r   headers
             r.   dumpr  D  s    @ 2wCd2hFWFWWXX==%0D	+!
B 	KKOT"D _mSAB =0HHVJJ
!	  r0   c                 X    t               }t        | |||||       |j                         S )a  Write a Python object to a string in plist format.

    Args:
        value: An object to write.
        sort_keys (bool): Whether keys of dictionaries should be sorted.
        skipkeys (bool): Whether to silently skip non-string dictionary
            keys.
        use_builtin_types (bool): If true, byte strings will be
            encoded in Base-64 and wrapped in a ``data`` tag; if
            false, they will be either stored as strings or an
            exception raised if they cannot be represented. Defaults
        pretty_print (bool): Whether to indent the output.
        indent_level (int): Level of indentation when serializing.

    Returns:
        string: A plist representation of the Python object.

    Raises:
        ``TypeError``
            if non-string dictionary keys are serialized
            and ``skipkeys`` is false.
        ``ValueError``
            if non-representable binary data is present
            and `use_builtin_types` is false.
    r   )r   r  getvalue)r   r   r   rl   r   r   s         r.   dumpsr	    s4    @ 
B
+! ;;=r0   rU   )TFNTrW   )TFNT)Wcollections.abcr   retypingr   r   r   r   r   r   r	   r
   r   r   r   rt   ior   r   base64r   r   numbersr   typesr   	functoolsr   fontTools.miscr   fontTools.misc.textToolsr   rr   r  r  compileASCIIr"   r\   r/   r3   r5   r9   r'   rH   r]   r   r   rk   r   r   r   r   r   r   r   r   r   r   r   r   r|   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   registerr   r   tuple	bytearrayr   r   r   r   r   r  r	  r^   r0   r.   <module>r     s    	       '  ! $   *  ?9  rzz HH	   x C !E !EJ IJ
 (BE
( 		CHSM	
R Rp[ T ; 4 '+ '$ 'k d K D ; 4 K D *k *d *,; ,4 ,%[ %T %:; :4 :8; 84 8
 D S(K=$+>"??@  B d3+)< ==> "3 _  " "O " "C o %--  _  sN"#*9
]](
N#
*9

]]
  5==  O  
,u 
,? 
,u}} 
,$ : :o :%-- : :   s O ,   t ] +    x  !1 2   u m , /  {.. / >   t ^ ,   u n -    x   /   u 5 6 !  y !- 0   t F G (,,),),) ,)  ~	,)
 ,) ,) ]],)b )-04
--~ N38,- 		D )-04
5	~ N38,- 		D )-04NN~N N38,-N 		N4 (,99
5	9 9 	9
  ~9 9 
9| (,))) )  ~	)
 ) )r0   