o
    hB                     @   s  d Z ddlmZ dZg dZz	ddlT dZW d	S  ey   zddlT ddl	m
Z
 W n ey7   ddl	T Y nw dZdd	lZejd
kZzdd	lZW n eyT   d	ZY nw eepYeZ[[erbeZnddlmZ eeerpeZnddl	mZ G dd deZe fddZdd Zd.ddZeZG dd deZdd	lZ									d/ddZdd	l Z ej!dk Z"e"re #dZ$ne #dZ$dd Z%dd	l&Z&e&j'dd  Z(dd!l	m)Z) d"d# Z*d$d% Z+d&d' Z,d(d) Z-d*d+ Z.d0d,d-Z/Y d	S w )1a  Shim module exporting the same ElementTree API for lxml and
xml.etree backends.

When lxml is installed, it is automatically preferred over the built-in
xml.etree module.
On Python 2.7, the cElementTree module is preferred over the pure-python
ElementTree module.

Besides exporting a unified interface, this also defines extra functions
or subclasses built-in ElementTree classes to add features that are
only availble in lxml, like OrderedDict for attributes, pretty_print and
iterwalk.
    )tostrz#<?xml version='1.0' encoding='%s'?>)CommentdumpElementElementTree
fromstringfromstringlist	iselement	iterparseparse
ParseErrorPIProcessingInstructionQName
SubElementtostringtostringlistTreeBuilderXML	XMLParserregister_namespace)*T)r   FN)      )OrderedDict)r   c                       s&   e Zd ZdZe f fdd	Z  ZS )r   z4Element subclass that keeps the order of attributes.c                    s@   t t| | t | _|r| j| |r| j| d S d S )N)superr   __init___Attribattribupdate)selftagr   extra	__class__ h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/misc/etree.pyr   U   s   zElement.__init__)__name__
__module____qualname____doc__r   r   __classcell__r%   r%   r#   r&   r   R   s    r   c                 K   s"   | j ||fi |}| | |S )zMust override SubElement as well otherwise _elementtree.SubElement
        fails if 'parent' is a subclass of Element object.
        )r$   append)parentr!   r   r"   elementr%   r%   r&   r   ]   s   
r   c                 c   sb    |d u p	| j |k}|rd|v rd| fV  | D ]}t|||D ]}|V  qq|r/d| fV  d S d S )Nstartend)r!   	_iterwalk)r.   eventsr!   includeeitemr%   r%   r&   r1   e   s   
r1   r0   c                 c   s@    t | r| }n|  }|dkrd}t|||D ]}|V  qdS )zA tree walker that generates events from an existing tree as
        if it was parsing XML data with iterparse().
        Drop-in replacement for lxml.etree.iterwalk.
        r   N)r	   getrootr1   )element_or_treer2   r!   r.   r5   r%   r%   r&   iterwalko   s   r9   c                       s,   e Zd ZdZ					d fdd	Z  ZS )r   a"  ElementTree subclass that adds 'pretty_print' and 'doctype'
        arguments to the 'write' method.
        Currently these are only supported for the default XML serialization
        'method', and not also for "html" or "text", for these are delegated
        to the base class.
        NFc                    s  |r|dkrt t| j||||d d S |d ur)| dkr)|r$tdd}d}n|d u r8|d uo6| dv}n|}|d u r@d}|rGt| j t||6}|r]|t	|   |r]|d |rk|t
| |rk|d t| j\}	}
t|| j|	|
 W d    d S 1 sw   Y  d S )	Nxml)encodingxml_declarationmethodunicodez<Serialisation to unicode must not request an XML declarationF)ASCIIzUTF-8UTF8zUS-ASCIIr?   
)r   r   writelower
ValueErrorupper_indent_root_get_writerXML_DECLARATION
_tounicode_namespaces_serialize_xml)r    file_or_filenamer;   r<   r=   doctypepretty_printwrite_declarationrB   qnames
namespacesr#   r%   r&   rB      sD   	

"zElementTree.write)NFNNF)r'   r(   r)   r*   rB   r+   r%   r%   r#   r&   r      s    
r   c                 C   s:   |dkrt  nt  }t| j||||||d | S )zjCustom 'tostring' function that uses our ElementTree subclass, with
        pretty_print support.
        r>   )r;   r<   r=   rN   rO   )ioStringIOBytesIOr   rB   getvalue)r.   r;   r<   r=   rN   rO   streamr%   r%   r&   r      s   r   i u   [ ---￾-￿]u   [ ----￾-￿]c                 C   s\   z	t | ddd} W n ty   td ty    t|  Y nw | r,t| r,td| S )a  Test if a string is valid user input and decode it to unicode string
        using ASCII encoding if it's a bytes string.
        Reject all bytes/unicode input that contains non-XML characters.
        Reject all bytes input that contains non-ASCII characters.
        asciistrictr;   errorsz^Bytes strings can only contain ASCII characters. Use unicode strings for non-ASCII characters.zYAll strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters)r   UnicodeDecodeErrorrD   AttributeError_raise_serialization_error_invalid_xml_stringsearch)sr%   r%   r&   rJ      s   rJ   c                 c   sD   z| j }W n0 ty6   t| d|dkrdn|dd}| |j V  W d    Y d S 1 s.w   Y  Y d S w |dkr@|V  d S d}t| tjrK| }n.t| tjrYt| }d}n t }dd	 |_||_ z
| j	|_	| j
|_
W n	 tyx   Y nw tj||dd
d}z|j V  W |  |r|  d S d S |  |r|  w w )Nwr>   zutf-8xmlcharrefreplacerZ   FTc                   S   s   dS )NTr%   r%   r%   r%   r&   <lambda>&  s    z_get_writer.<locals>.<lambda>rA   )r;   r[   newline)rB   r]   open
isinstancerS   BufferedIOBase	RawIOBaseBufferedWriterwritableseekabletellTextIOWrapperdetach)rM   r;   rB   fdetach_bufferbufwrapperr%   r%   r&   rH     s^   

&




rH   )_namespace_mapc                    s  d d ii   fdd}|   D ]m} | j}t|tr&|jvr%||j nt|tr4|vr3|| n|d urD|turD|turDt| | 	 D ]#\}}t|trT|j}|vr\|| t|trk|jvrk||j qH| j}t|tr~|jvr~||j q fS )Nc                    s   zXt | } | d d dkrR| dd  dd\}} |}|d u r>t|}|d u r2dt  }nt |}|dkr>| |< |rKd||f | < W d S || < W d S | | < W d S  tyf   t|  Y d S w )N   {}zns%dr:   z%s:%s)rJ   rsplitgetrt   len	TypeErrorr^   )qnameurir!   prefixrR   rQ   r%   r&   	add_qnameI  s&   

z_namespaces.<locals>.add_qname)
iterr!   rg   r   textstrr   r   r^   items)elemr   r!   keyvaluer   r%   r   r&   rK   @  s8   






rK   c                 K   s  |j }|j}|tu r| dt|  n|tu r | dt|  n||d ur)t|nd  }|d u rE|r8| t| |D ]	}t| ||d  q:n| d|  |rlt| dd dD ]\}}	|	rad|	 }	| d|	t	|f  qW|j
}
|
rt|
d	ks}t|
tu r|
 }nt|
 }|D ].\}}t|trt|j}nt|}t|tr|t|j }nt	|}| d
|| |f  q|d ust|r| d |r| t| |D ]	}t| ||d  q| d| d  n| d |jr| t|j d S d S )Nz	<!--%s-->z<?%s?><c                 S   s   | d S )Nru   r%   )xr%   r%   r&   rd     s    z _serialize_xml.<locals>.<lambda>)r   :z xmlns%s="%s"ru   z %s="%s">z</z/>)r!   r   r   rJ   r   _escape_cdatarL   sortedr   _escape_attribr   rz   typer   rg   r   tail)rB   r   rQ   rR   kwargsr!   r   r4   r}   r~   attrsr   kvr%   r%   r&   rL   x  sZ   


rL   c                 C   s   t d| t| jf )Nzcannot serialize %r (type %s))r{   r   r'   r   r%   r%   r&   r^     s   r^   c              	   C   sl   z%t | } d| v r| dd} d| v r| dd} d| v r#| dd} | W S  ttfy5   t|  Y d S w )N&&amp;r   &lt;r   &gt;rJ   replacer{   r]   r^   r   r%   r%   r&   r     s   r   c              	   C   s   z9t | } d| v r| dd} d| v r| dd} d| v r#| dd} d| v r-| dd} d	| v r7| d	d
} | W S  ttfyI   t|  Y d S w )Nr   r   r   r   r   r   "z&quot;rA   z&#10;r   r   r%   r%   r&   r     s    r   c                 C   s   d|d  }t | r=| jr| j s|d | _| jr| j s"|| _| D ]	} t| |d  q$| jr6| j s;|| _d S d S |rL| jrG| j sN|| _d S d S d S )NrA   z  ru   )rz   r   stripr   rF   )r   levelir%   r%   r&   rF     s   


rF   )r6   N)NNNNF)r   )0r*   fontTools.misc.textToolsr   rI   __all__
lxml.etree
_have_lxmlImportErrorxml.etree.cElementTreexml.etree.ElementTreer   sysversion_infoPY36__pypy__bool_dict_is_ordereddictr   collectionsr   rg   r   r   _Elementr   r1   r9   r   _ElementTreerS   r   re
maxunicodeUCS2compiler_   rJ   
contextlibcontextmanagerrH   rt   rK   rL   r^   r   r   rF   r%   r%   r%   r&   <module>   s    




A

	
885   