AlkantarClanX12

Your IP : 13.59.183.186


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

o

6��fL"�@s�dZgd�ZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZGdd�de�Z
d	d
�ZGdd�d�Zifd
d�Zd^dd�Zd^dd�ZeZGdd�d�ZGdd�d�Ze	jdd��Zd^dd�Zdd�ZdZzee�ZWn	ey~Ynwdd�Zd d!�Zeeed"�Zd#d$�Z d%d&d'd(d)d*d+d,�Z!e!e _!d-d.�Z"d/d0�Z#d1d2�Z$d3d4�Z%d_ddd5d6�d7d8�Z&Gd9d:�d:ej'�Z(d_ddd5d6�d;d<�Z)d=d>�Z*d`d@dA�Z+d^dBdC�Z,d_dDdE�Z-GdFdG�dG�Z.d^dHdI�Z/d^dJdK�Z0e/Z1d^dLdM�Z2GdNdO�dO�Z3GdPdQ�dQ�Z4d^dddR�dSdT�Z5e�6dUej7�j8Z9GdVdW�dW�Z:dXdY�Z;dZd[�Z<zeZ=dd\l>Tdd]l>m?Z?Wne@�y=YdSwe?ee�dS)aaLightweight XML support for Python.

 XML is an inherently hierarchical data format, and the most natural way to
 represent it is with a tree.  This module has two classes for this purpose:

    1. ElementTree represents the whole XML document as a tree and

    2. Element represents a single node in this tree.

 Interactions with the whole document (reading and writing to/from files) are
 usually done on the ElementTree level.  Interactions with a single XML element
 and its sub-elements are done on the Element level.

 Element is a flexible container object designed to store hierarchical data
 structures in memory. It can be described as a cross between a list and a
 dictionary.  Each Element has a number of properties associated with it:

    'tag' - a string containing the element's name.

    'attributes' - a Python dictionary storing the element's attributes.

    'text' - a string containing the element's text content.

    'tail' - an optional string containing text after the element's end tag.

    And a number of child elements stored in a Python sequence.

 To create an element instance, use the Element constructor,
 or the SubElement factory function.

 You can also use the ElementTree class to wrap an element structure
 and convert it to and from XML.

)�Comment�dump�Element�ElementTree�
fromstring�fromstringlist�indent�	iselement�	iterparse�parse�
ParseError�PI�ProcessingInstruction�QName�
SubElement�tostring�tostringlist�TreeBuilder�VERSION�XML�XMLID�	XMLParser�
XMLPullParser�register_namespace�canonicalize�C14NWriterTargetz1.3.0�N�)�ElementPathc@seZdZdZdS)rz�An error when parsing an XML document.

    In addition to its exception value, a ParseError contains
    two extra attributes:
        'code'     - the specific exception code
        'position' - the line and column of the error

    N)�__name__�
__module__�__qualname__�__doc__�r"r"�</opt/alt/python310/lib64/python3.10/xml/etree/ElementTree.pyrjsrcCs
t|d�S)z2Return True if *element* appears to be an Element.�tag)�hasattr)�elementr"r"r#rxs
rc@seZdZdZdZ	dZ	dZ	dZ	ifdd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd7d!d"�Zd8d#d$�Zd7d%d&�Zd7d'd(�Zd)d*�Zd7d+d,�Zd-d.�Zd/d0�Zd1d2�Zd7d3d4�Z d5d6�Z!dS)9rahAn XML element.

    This class is the reference implementation of the Element interface.

    An element's length is its number of subelements.  That means if you
    want to check if an element is truly empty, you should check BOTH
    its length AND its text attribute.

    The element tag, attribute names, and attribute values can be either
    bytes or strings.

    *tag* is the element name.  *attrib* is an optional dictionary containing
    element attributes. *extra* are additional element attributes given as
    keyword arguments.

    Example form:
        <tag attrib>text<child/>...</tag>tail

    NcKs:t|t�std|jjf��||_i|�|�|_g|_dS)Nzattrib must be dict, not %s)�
isinstance�dict�	TypeError�	__class__rr$�attrib�	_children)�selfr$r+�extrar"r"r#�__init__�s
�
zElement.__init__cCsd|jj|jt|�fS)Nz<%s %r at %#x>)r*rr$�id�r-r"r"r#�__repr__��zElement.__repr__cCs|�||�S)z�Create a new element with the same type.

        *tag* is a string containing the element name.
        *attrib* is a dictionary containing the element attributes.

        Do not call this method, use the SubElement factory function instead.

        )r*)r-r$r+r"r"r#�makeelement�s	zElement.makeelementcCst�dt�|��S)z�Return copy of current element.

        This creates a shallow copy. Subelements will be shared with the
        original tree.

        z7elem.copy() is deprecated. Use copy.copy(elem) instead.)�warnings�warn�DeprecationWarning�__copy__r1r"r"r#�copy�s
�zElement.copycCs0|�|j|j�}|j|_|j|_||dd�<|S�N)r4r$r+�text�tail)r-�elemr"r"r#r8�s
zElement.__copy__cC�
t|j�Sr:)�lenr,r1r"r"r#�__len__��
zElement.__len__cCstjdtdd�t|j�dkS)NzyThe behavior of this method will change in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.���
stacklevelr)r5r6�
FutureWarningr?r,r1r"r"r#�__bool__�s
�zElement.__bool__cCs
|j|Sr:�r,�r-�indexr"r"r#�__getitem__�rAzElement.__getitem__cCs8t|t�r|D]}|�|�qn|�|�||j|<dSr:)r'�slice�_assert_is_elementr,)r-rIr&�eltr"r"r#�__setitem__�s
�
zElement.__setitem__cCs|j|=dSr:rGrHr"r"r#�__delitem__�szElement.__delitem__cCs|�|�|j�|�dS)aAdd *subelement* to the end of this element.

        The new element will appear in document order after the last existing
        subelement (or directly after the text, if it's the first subelement),
        but before the end tag for this element.

        N�rLr,�append�r-�
subelementr"r"r#rQ�s
zElement.appendcCs$|D]
}|�|�|j�|�qdS)zkAppend subelements from a sequence.

        *elements* is a sequence with zero or more elements.

        NrP)r-�elementsr&r"r"r#�extend�s
�zElement.extendcCs|�|�|j�||�dS)z(Insert *subelement* at position *index*.N)rLr,�insert)r-rIrSr"r"r#rVs
zElement.insertcCs t|t�stdt|�j��dS)Nzexpected an Element, not %s)r'�_Element_Pyr)�typer)r-�er"r"r#rLs
�zElement._assert_is_elementcC�|j�|�dS)a�Remove matching subelement.

        Unlike the find methods, this method compares elements based on
        identity, NOT ON tag value or contents.  To remove subelements by
        other means, the easiest way is to use a list comprehension to
        select what elements to keep, and then use slice assignment to update
        the parent element.

        ValueError is raised if a matching element could not be found.

        N)r,�removerRr"r"r#r[s
zElement.removecC�t�|||�S)aFind first matching element by tag name or path.

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return the first matching element, or None if no element was found.

        )r�find�r-�path�
namespacesr"r"r#r]�	zElement.findcCst�||||�S)a�Find text for first matching element by tag name or path.

        *path* is a string having either an element tag or an XPath,
        *default* is the value to return if the element was not found,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return text content of first matching element, or default value if
        none was found.  Note that if an element is found having no text
        content, the empty string is returned.

        )r�findtext�r-r_�defaultr`r"r"r#rb&szElement.findtextcCr\)aFind all matching subelements by tag name or path.

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Returns list containing all matching elements in document order.

        )r�findallr^r"r"r#re4razElement.findallcCr\)a Find all matching subelements by tag name or path.

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return an iterable yielding all matching elements in document order.

        )r�iterfindr^r"r"r#rf?razElement.iterfindcCs |j��g|_d|_|_dS)z�Reset element.

        This function removes all subelements, clears all attributes, and sets
        the text and tail attributes to None.

        N)r+�clearr,r;r<r1r"r"r#rgJs
z
Element.clearcCs|j�||�S)agGet element attribute.

        Equivalent to attrib.get, but some implementations may handle this a
        bit more efficiently.  *key* is what attribute to look for, and
        *default* is what to return if the attribute was not found.

        Returns a string containing the attribute value, or the default if
        attribute was not found.

        )r+�get)r-�keyrdr"r"r#rhUszElement.getcCs||j|<dS)z�Set element attribute.

        Equivalent to attrib[key] = value, but some implementations may handle
        this a bit more efficiently.  *key* is what attribute to set, and
        *value* is the attribute value to set it to.

        N)r+)r-ri�valuer"r"r#�setbszElement.setcC�
|j��S)z�Get list of attribute names.

        Names are returned in an arbitrary order, just like an ordinary
        Python dict.  Equivalent to attrib.keys()

        )r+�keysr1r"r"r#rmls
zElement.keyscCrl)z�Get element attributes as a sequence.

        The attributes are returned in arbitrary order.  Equivalent to
        attrib.items().

        Return a list of (name, value) tuples.

        )r+�itemsr1r"r"r#rnus
	z
Element.itemsccsF�|dkrd}|dus|j|kr|V|jD]
}|�|�EdHqdS)aCreate tree iterator.

        The iterator loops over the element and all subelements in document
        order, returning all elements with a matching tag.

        If the tree structure is modified during iteration, new or removed
        elements may or may not be included.  To get a stable set, use the
        list() function on the iterator, and loop over the resulting list.

        *tag* is what tags to look for (default is to return all elements)

        Return an iterator containing all the matching elements.

        �*N)r$r,�iter)r-r$rYr"r"r#rp�s�
�zElement.iterccsZ�|j}t|t�s|durdS|j}|r|V|D]}|��EdH|j}|r*|VqdS)z�Create text iterator.

        The iterator loops over the element and all subelements in document
        order, returning all inner text.

        N)r$r'�strr;�itertextr<)r-r$�trYr"r"r#rr�s���zElement.itertextr:�NN)"rrr r!r$r+r;r<r/r2r4r9r8r@rFrJrNrOrQrUrVrLr[r]rbrerfrgrhrkrmrnrprrr"r"r"r#r}sH








	
rcKs&i|�|�}|�||�}|�|�|S)a�Subelement factory which creates an element instance, and appends it
    to an existing parent.

    The element tag, attribute names, and attribute values can be either
    bytes or Unicode strings.

    *parent* is the parent element, *tag* is the subelements name, *attrib* is
    an optional directory containing element attributes, *extra* are
    additional attributes given as keyword arguments.

    )r4rQ)�parentr$r+r.r&r"r"r#r�s
rcCstt�}||_|S)z�Comment element factory.

    This function creates a special element which the standard serializer
    serializes as an XML comment.

    *text* is a string containing the comment string.

    )rrr;)r;r&r"r"r#r�s	rcCs&tt�}||_|r|jd||_|S)a*Processing Instruction element factory.

    This function creates a special element which the standard serializer
    serializes as an XML comment.

    *target* is a string containing the processing instruction, *text* is a
    string containing the processing instruction contents, if any.

    � )rr
r;)�targetr;r&r"r"r#r
�s

r
c@sZeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)ra�Qualified name wrapper.

    This class can be used to wrap a QName attribute value in order to get
    proper namespace handing on output.

    *text_or_uri* is a string containing the QName value either in the form
    {uri}local, or if the tag argument is given, the URI part of a QName.

    *tag* is an optional argument which if given, will make the first
    argument (text_or_uri) be interpreted as a URI, and this argument (tag)
    be interpreted as a local name.

    NcCs|rd||f}||_dS)Nz{%s}%s�r;)r-Ztext_or_urir$r"r"r#r/�s
zQName.__init__cC�|jSr:rxr1r"r"r#�__str__�sz
QName.__str__cCsd|jj|jfS)Nz<%s %r>)r*rr;r1r"r"r#r2��zQName.__repr__cCr>r:)�hashr;r1r"r"r#�__hash__�rAzQName.__hash__cCs t|t�r|j|jkS|j|kSr:�r'rr;�r-�otherr"r"r#�__le__��

zQName.__le__cCs t|t�r|j|jkS|j|kSr:r~rr"r"r#�__lt__�r�zQName.__lt__cCs t|t�r|j|jkS|j|kSr:r~rr"r"r#�__ge__�r�zQName.__ge__cCs t|t�r|j|jkS|j|kSr:r~rr"r"r#�__gt__r�zQName.__gt__cCs t|t�r|j|jkS|j|kSr:r~rr"r"r#�__eq__r�zQName.__eq__r:)
rrr r!r/rzr2r}r�r�r�r�r�r"r"r"r#r�s

rc@s�eZdZdZddd�Zdd�Zdd�Zdd	d
�Zddd�Zdd
d�Z	ddd�Z
ddd�Zddd�Z				ddd�dd�Z
dd�ZdS)ra%An XML element hierarchy.

    This class also provides support for serialization to and from
    standard XML.

    *element* is an optional root element node,
    *file* is an optional file handle or file name of an XML file whose
    contents will be used to initialize the tree with.

    NcCs||_|r|�|�dSdSr:)�_rootr
)r-r&�filer"r"r#r/s�zElementTree.__init__cCry)z!Return root element of this tree.�r�r1r"r"r#�getrootszElementTree.getrootcCs
||_dS)z�Replace root element of this tree.

        This will discard the current contents of the tree and replace it
        with the given element.  Use with care!

        Nr�)r-r&r"r"r#�_setroot"s
zElementTree._setrootcCs�d}t|d�st|d�}d}z<|dur,t�}t|d�r,|�|�|_|jW|r+|��SS	|�d�}|s5n|�|�q-|��|_|jW|rJ|��SS|rR|��ww)a=Load external XML document into element tree.

        *source* is a file name or file object, *parser* is an optional parser
        instance that defaults to XMLParser.

        ParseError is raised if the parser fails to parse the document.

        Returns the root element of the given source document.

        F�read�rbTN�_parse_wholei)r%�openrr�r��closer��feed)r-�source�parser�close_source�datar"r"r#r
,s4


	
��

�

�
�zElementTree.parsecCs|j�|�S)z�Create and return tree iterator for the root element.

        The iterator loops over all elements in this tree, in document order.

        *tag* is a string with the tag name to iterate over
        (default is to return all elements).

        )r�rp�r-r$r"r"r#rpQs
zElementTree.itercC�:|dd�dkrd|}tjd|tdd�|j�||�S)a\Find first matching element by tag name or path.

        Same as getroot().find(path), which is Element.find()

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return the first matching element, or None if no element was found.

        Nr�/�.��This search is broken in 1.3 and earlier, and will be fixed in a future version.  If you rely on the current behaviour, change it to %rrBrC)r5r6rEr�r]r^r"r"r#r]]���zElementTree.findcCs<|dd�dkrd|}tjd|tdd�|j�|||�S)aeFind first matching element by tag name or path.

        Same as getroot().findtext(path),  which is Element.findtext()

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return the first matching element, or None if no element was found.

        Nrr�r�r�rBrC)r5r6rEr�rbrcr"r"r#rbss��zElementTree.findtextcCr�)aaFind all matching subelements by tag name or path.

        Same as getroot().findall(path), which is Element.findall().

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return list containing all matching elements in document order.

        Nrr�r�r�rBrC)r5r6rEr�rer^r"r"r#re�r�zElementTree.findallcCr�)agFind all matching subelements by tag name or path.

        Same as getroot().iterfind(path), which is element.iterfind()

        *path* is a string having either an element tag or an XPath,
        *namespaces* is an optional mapping from namespace prefix to full name.

        Return an iterable yielding all matching elements in document order.

        Nrr�r�r�rBrC)r5r6rEr�rfr^r"r"r#rf�r�zElementTree.iterfindT��short_empty_elementscCs�|sd}n
|tvrtd|��|s|dkrd}nd}t||��Q\}}|dkr?|s8|dur?|��dkr?|��dvr?|d	|f�|d
krJt||j�nt|j|�\}	}
t|}|||j|	|
|d�Wd�dSWd�dS1sswYdS)a�Write element tree to a file as XML.

        Arguments:
          *file_or_filename* -- file name or a file object opened for writing

          *encoding* -- the output encoding (default: US-ASCII)

          *xml_declaration* -- bool indicating if an XML declaration should be
                               added to the output. If None, an XML declaration
                               is added if encoding IS NOT either of:
                               US-ASCII, UTF-8, or Unicode

          *default_namespace* -- sets the default XML namespace (for "xmlns")

          *method* -- either "xml" (default), "html, "text", or "c14n"

          *short_empty_elements* -- controls the formatting of elements
                                    that contain no content. If True (default)
                                    they are emitted as a single self-closed
                                    tag, otherwise they are emitted as a pair
                                    of start/end tags

        �xmlzunknown method %r�c14n�utf-8�us-asciiN�unicode)r�r�z$<?xml version='1.0' encoding='%s'?>
r;r�)�
_serialize�
ValueError�_get_writer�lower�_serialize_textr��_namespaces)r-�file_or_filename�encoding�xml_declaration�default_namespace�methodr��writeZdeclared_encoding�qnamesr`Z	serializer"r"r#r��s4���"�zElementTree.writecCs|j|dd�S)Nr�)r�)r�)r-r�r"r"r#�
write_c14n�szElementTree.write_c14nrtr:)NNNN)rrr r!r/r�r�r
rpr]rbrerfr�r�r"r"r"r#r
s&




%



��5rccsf�z|j}Wn2ty8|��dkrd}t|d|dd��}|j|fVWd�YdS1s0wYYdSw|��dkrL|t|dd�pGdfVdSt���Y}t|tj	�rZ|}n2t|tj
�rlt�|�}|�|j
�n t�	�}dd�|_||_z
|j|_|j|_Wn	ty�Ynwtj||dd	d
�}|�|j
�|j|fVWd�dS1s�wYdS)Nr�r��w�xmlcharrefreplace)r��errorsr�cS�dS�NTr"r"r"r"r#�<lambda>sz_get_writer.<locals>.<lambda>�
)r�r��newline)r��AttributeErrorr�r��getattr�
contextlib�	ExitStackr'�io�BufferedIOBase�	RawIOBase�BufferedWriter�callback�detach�writable�seekable�tell�
TextIOWrapper)r�r�r�r��stackr"r"r#r��sL�
�&��



��"�r�csddi�i��rd��<���fdd�}|��D]m}|j}t|t�r-|j�vr,||j�nt|t�r;|�vr:||�n|durK|turK|turKt|�|�	�D]#\}}t|t�r[|j}|�vrc||�t|t�rr|j�vrr||j�qO|j}t|t�r�|j�vr�||j�q��fS)N�cs�zU|dd�dkrI|dd��dd�\}}��|�}|dur5t�|�}|dur-dt��}|dkr5|�|<|rBd||f�|<WdS|�|<WdS�rOtd��|�|<WdStyct|�YdSw)Nr�{�}zns%dr�z%s:%sz<cannot use non-qualified names with default_namespace option)�rsplitrh�_namespace_mapr?r�r)�_raise_serialization_error)�qname�urir$�prefix�r�r`r�r"r#�	add_qname.s*

��z_namespaces.<locals>.add_qname)
rpr$r'rr;rqrrr�rn)r=r�r�r$rirjr;r"r�r#r�#s<


�
�

�
�r�cKs�|j}|j}|tur|d|�n�|tur|d|�n�||}|dur;|r,|t|��|D]}t|||d|d�q.n�|d|�t|���}	|	sK|r�|rlt|��dd�d�D]\}
}|rad|}|d	|t	|
�f�qW|	D]%\}}
t
|t�rz|j}t
|
t�r�||
j}
nt	|
�}
|d
|||
f�qn|s�t|�s�|s�|d�|r�|t|��|D]}t|||d|d�q�|d|d�n|d
�|j
r�|t|j
��dSdS)N�	<!--%s-->�<?%s?>r��<cS�|dS�Nrr"��xr"r"r#r�v�z _serialize_xml.<locals>.<lambda>�ri�:�
 xmlns%s="%s"� %s="%s"�>�</z />)r$r;rr
�
_escape_cdata�_serialize_xml�listrn�sorted�_escape_attribr'rr?r<)r�r=r�r`r��kwargsr$r;rYrn�v�kr"r"r#r�`s`
���
�


��r�)
Zarea�baseZbasefont�br�col�frameZhrZimg�inputZisindex�link�metaZparamcKs�|j}|j}|tur|dt|��n�|tur |dt|��n�||}|dur=|r0|t|��|D]	}t|||d�q2n�|d|�t|���}|sM|r�|rnt|��dd�d�D]\}	}
|
rcd|
}
|d|
t	|	�f�qY|D]%\}
}	t
|
t�r||
j}
t
|	t�r�||	j}	nt|	�}	|d	||
|	f�qp|d
�|�
�}|r�|dks�|dkr�||�n|t|��|D]	}t|||d�q�|tvr�|d
|d
�|jr�|t|j��dSdS)Nr�r�r�cSr�r�r"r�r"r"r#r��r�z!_serialize_html.<locals>.<lambda>r�r�r�r�r�ZscriptZstyler�)r$r;rr�r
�_serialize_htmlr�rnr�r�r'r�_escape_attrib_htmlr��
HTML_EMPTYr<)r�r=r�r`r�r$r;rYrnr�r�Zltagr"r"r#r��s\��
�


�r�cCs.|��D]}||�q|jr||j�dSdSr:)rrr<)r�r=�partr"r"r#r��s

�r�)r��htmlr;cCsLt�d|�r
td��tt���D]\}}||ks||krt|=q|t|<dS)atRegister a namespace prefix.

    The registry is global, and any existing mapping for either the
    given prefix or the namespace URI will be removed.

    *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and
    attributes in this namespace will be serialized with prefix if possible.

    ValueError is raised if prefix is reserved or is invalid.

    zns\d+$z'Prefix format reserved for internal useN)�re�matchr�r�r�rn)r�r�r�r�r"r"r#r�s�rr�r�ZrdfZwsdlZxsZxsiZdc)�$http://www.w3.org/XML/1998/namespacezhttp://www.w3.org/1999/xhtmlz+http://www.w3.org/1999/02/22-rdf-syntax-ns#z http://schemas.xmlsoap.org/wsdl/z http://www.w3.org/2001/XMLSchemaz)http://www.w3.org/2001/XMLSchema-instancez http://purl.org/dc/elements/1.1/cCstd|t|�jf��)Nzcannot serialize %r (type %s))r)rXrrxr"r"r#r��s�r�c	C�dz!d|vr|�dd�}d|vr|�dd�}d|vr|�dd�}|WSttfy1t|�YdSw)N�&�&amp;r��&lt;r��&gt;��replacer)r�r�rxr"r"r#r�s�r�c	Cs�zId|vr|�dd�}d|vr|�dd�}d|vr|�dd�}d|vr)|�dd�}d	|vr3|�d	d
�}d|vr=|�dd�}d
|vrG|�d
d�}|WSttfyYt|�YdSw)Nr�r�r�r�r�r��"�&quot;�
z&#13;r�z&#10;�	z&#09;r�rxr"r"r#r�s&�r�c	Cr�)Nr�r�r�r�r�rr�rxr"r"r#r�.s�r�T)r�r�r�cCs:|dkrt��nt��}t|�j||||||d�|��S)a
Generate string representation of XML element.

    All subelements are included.  If encoding is "unicode", a string
    is returned. Otherwise a bytestring is returned.

    *element* is an Element instance, *encoding* is an optional output
    encoding defaulting to US-ASCII, *method* is an optional output which can
    be one of "xml" (default), "html", "text" or "c14n", *default_namespace*
    sets the default XML namespace (for "xmlns").

    Returns an (optionally) encoded string containing the XML data.

    r��r�r�r�r�)r��StringIO�BytesIOrr��getvalue)r&r�r�r�r�r��streamr"r"r#r=s�rc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�_ListDataStreamz7An auxiliary stream accumulating into a list reference.cCs
||_dSr:)�lst)r-r	r"r"r#r/WrAz_ListDataStream.__init__cCr�r�r"r1r"r"r#r�Z�z_ListDataStream.writablecCr�r�r"r1r"r"r#r�]r
z_ListDataStream.seekablecCs|j�|�dSr:)r	rQ)r-�br"r"r#r�`�z_ListDataStream.writecCr>r:)r?r	r1r"r"r#r�crAz_ListDataStream.tellN)	rrr r!r/r�r�r�r�r"r"r"r#rUsrcCs*g}t|�}t|�j||||||d�|S)Nr)rrr�)r&r�r�r�r�r�r	rr"r"r#rfs�rcCsPt|t�s	t|�}|jtjdd�|��j}|r|ddkr&tj�d�dSdS)a#Write element tree or element structure to sys.stdout.

    This function should be used for debugging only.

    *elem* is either an ElementTree, or a single Element.  The exact output
    format is implementation dependent.  In this version, it's written as an
    ordinary XML file.

    r�)r����r�N)r'rr��sys�stdoutr�r<)r=r<r"r"r#rss

�r�  cs`t|t�r	|��}|dkrtd|����t|�sdSd|�g����fdd���|d�dS)a&Indent an XML document by inserting newlines and indentation space
    after elements.

    *tree* is the ElementTree or Element to modify.  The (root) element
    itself will not be changed, but the tail text of all elements in its
    subtree will be adapted.

    *space* is the whitespace to insert for each indentation level, two
    space characters by default.

    *level* is the initial indentation level. Setting this to a higher
    value than 0 can be used for indenting subtrees that are more deeply
    nested inside of a document.
    rz,Initial indentation level must be >= 0, got Nr�cs�|d}z�|}Wnty�|�}��|�Ynw|jr'|j��s*||_|D]}t|�r7�||�|jr?|j��sB||_q,|j��sO�||_dSdSr�)�
IndexErrorrQr;�stripr?r<)r=�levelZchild_levelZchild_indentation�child��_indent_childrenZindentations�spacer"r#r�s$�
�
�z indent.<locals>._indent_children)r'rr�r�r?)�treerrr"rr#r�s
rcCst�}|�||�|S)z�Parse XML document into element tree.

    *source* is a filename or file object containing XML data,
    *parser* is an optional parser instance defaulting to XMLParser.

    Return an ElementTree instance.

    )rr
)r�r�rr"r"r#r
�s	r
csPt||d����fdd��G��fdd�dtjj�}|��d�_�~t���S)aJIncrementally parse XML document into ElementTree.

    This class also reports what's going on to the user based on the
    *events* it is initialized with.  The supported events are the strings
    "start", "end", "start-ns" and "end-ns" (the "ns" events are used to get
    detailed namespace information).  If *events* is omitted, only
    "end" events are reported.

    *source* is a filename or file object containing XML data, *events* is
    a list of events to report back, *parser* is an optional parser instance.

    Returns an iterator providing (event, elem) pairs.

    )�events�_parserc3s��d}z>t|d�st|d�}d}dV	���EdH|�d�}|s#n��|�q���}���EdH|�_W|r@|��dSdS|rI|��ww)NFr�r�Ti@)r%r��read_eventsr�r��_close_and_return_root�rootr�)r�r�r�r)�it�
pullparserr"r#�iterator�s,�



��
�ziterparse.<locals>.iteratorcseZdZ���jZdS)z$iterparse.<locals>.IterParseIteratorN)rrr �__next__r")r r�r"r#�IterParseIterator�sr"N)r�collections�abc�Iteratorr�next)r�rr�r"r")rr rr�r#r	�sr	c@sDeZdZddd�dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�ZdS)rN)rcCs<t��|_|ptt�d�|_|durd}|j�|j|�dS)N�rw)�end)r#�deque�
_events_queuerrr�
_setevents)r-rrr"r"r#r/�s

zXMLPullParser.__init__c
Cs`|jdur	td��|r.z	|j�|�WdSty-}z
|j�|�WYd}~dSd}~wwdS)�Feed encoded data to parser.Nz!feed() called after end of stream)rr�r��SyntaxErrorr*rQ)r-r��excr"r"r#r�
s
���zXMLPullParser.feedcCs|j��}d|_|Sr:)rr�)r-rr"r"r#rs
z$XMLPullParser._close_and_return_rootcCs|��dS)z�Finish feeding data to parser.

        Unlike XMLParser, does not return the root element. Use
        read_events() to consume elements from XMLPullParser.
        N)rr1r"r"r#r�szXMLPullParser.closeccs4�|j}|r|��}t|t�r|�|V|sdSdS)z�Return an iterator over currently available (event, elem) pairs.

        Events are consumed from the internal event queue as they are
        retrieved from the iterator.
        N)r*�popleftr'�	Exception)r-r�eventr"r"r#r"s�
�zXMLPullParser.read_eventscCs |jdur	td��|j��dS)Nz"flush() called after end of stream)rr��flushr1r"r"r#r20s
zXMLPullParser.flushr:)	rrr r/r�rr�rr2r"r"r"r#r�s
rcCs"|stt�d�}|�|�|��S)aParse XML document from string constant.

    This function can be used to embed "XML Literals" in Python code.

    *text* is a string containing XML data, *parser* is an
    optional parser instance, defaulting to the standard XMLParser.

    Returns an Element instance.

    r'�rrr�r�)r;r�r"r"r#r6s
rcCsR|stt�d�}|�|�|��}i}|��D]
}|�d�}|r$|||<q||fS)aParse XML document from string constant for its IDs.

    *text* is a string containing XML data, *parser* is an
    optional parser instance, defaulting to the standard XMLParser.

    Returns an (Element, dict) tuple, in which the
    dict maps element id:s to elements.

    r'r0)rrr�r�rprh)r;r�rZidsr=r0r"r"r#rGs


�rcCs,|stt�d�}|D]}|�|�q
|��S)z�Parse XML document from sequence of string fragments.

    *sequence* is a list of other sequence, *parser* is an optional parser
    instance, defaulting to the standard XMLParser.

    Returns an Element instance.

    r'r3)Zsequencer�r;r"r"r#r_s
	rc@sheZdZdZdddddd�dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
ddd�Zdd�ZdS)ra8Generic element structure builder.

    This builder converts a sequence of start, data, and end method
    calls to a well-formed element structure.

    You can use this class to build an element structure using a custom XML
    parser, or a parser for some other XML-like format.

    *element_factory* is an optional element factory which is called
    to create new Element instances, as necessary.

    *comment_factory* is a factory to create comments to be used instead of
    the standard factory.  If *insert_comments* is false (the default),
    comments will not be inserted into the tree.

    *pi_factory* is a factory to create processing instructions to be used
    instead of the standard factory.  If *insert_pis* is false (the default),
    processing instructions will not be inserted into the tree.
    NF)�comment_factory�
pi_factory�insert_comments�
insert_piscCsdg|_g|_d|_d|_d|_|durt}||_||_|dur!t}||_	||_
|dur-t}||_dSr:)
�_data�_elem�_lastr��_tailr�_comment_factoryr6r
�_pi_factoryr7r�_factory)r-Zelement_factoryr4r5r6r7r"r"r#r/�s 
zTreeBuilder.__init__cCry)z;Flush builder buffers and return toplevel document Element.r�r1r"r"r#r��szTreeBuilder.closecCsB|jr|jdurd�|j�}|jr||j_n||j_g|_dSdS�Nr�)r8r:�joinr;r<r;�r-r;r"r"r#�_flush�s


�zTreeBuilder._flushcCrZ)zAdd text to current element.N)r8rQ�r-r�r"r"r#r��szTreeBuilder.datacCsX|��|�||�|_}|jr|jd�|�n|jdur!||_|j�|�d|_|S)z�Open new element and return it.

        *tag* is the element name, *attrs* is a dict containing element
        attributes.

        r
Nr)rBr>r:r9rQr�r;)r-r$�attrsr=r"r"r#�start�s
zTreeBuilder.startcCs |��|j��|_d|_|jS)zOClose and return current Element.

        *tag* is the element name.

        r)rBr9�popr:r;r�r"r"r#r(�szTreeBuilder.endcCs|�|j|j|�S)z`Create a comment using the comment_factory.

        *text* is the text of the comment.
        )�_handle_singler<r6rAr"r"r#�comment�s
�zTreeBuilder.commentcCs|�|j|j||�S)z�Create a processing instruction using the pi_factory.

        *target* is the target name of the processing instruction.
        *text* is the data of the processing instruction, or ''.
        )rGr=r7)r-rwr;r"r"r#�pi�s�zTreeBuilder.picGs:||�}|r|��||_|jr|jd�|�d|_|S)Nr
r)rBr:r9rQr;)r-�factoryrV�argsr=r"r"r#rG�szTreeBuilder._handle_singler:)
rrr r!r/r�rBr�rEr(rHrIrGr"r"r"r#rqs�
	rc@sxeZdZdZddd�dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)raaElement structure builder for XML source data based on the expat parser.

    *target* is an optional target object which defaults to an instance of the
    standard TreeBuilder class, *encoding* is an optional encoding string
    which if given, overrides the encoding specified in the XML file:
    http://www.iana.org/assignments/character-sets

    N)rwr�cCsNzddlm}Wnty#zddl}Wnty td��wYnw|�|d�}|dur1t�}||_|_||_|_	|j
|_i|_|j
|_t|d�rQ|j|_t|d�rZ|j|_t|d�rc|j|_t|d�rl|j|_t|d	�ru|j|_t|d
�r~|j|_t|d�r�|j|_d|_d|_d|_ i|_!z	d
|j"|_#WdSt$y�YdSw)Nr��expatz7No module named expat; use SimpleXMLTreeBuilder insteadr�rEr(�start_ns�end_nsr�rHrIrzExpat %d.%d.%d)%�xml.parsersrM�ImportErrorZpyexpatZParserCreaterr�rrw�_target�error�_error�_names�_defaultZDefaultHandlerExpandr%�_start�StartElementHandler�_end�EndElementHandler�	_start_ns�StartNamespaceDeclHandler�_end_ns�EndNamespaceDeclHandlerr�ZCharacterDataHandlerrH�CommentHandlerrI�ProcessingInstructionHandlerZbuffer_text�ordered_attributes�_doctype�entity�version_info�versionr�)r-rwr�rMr�r"r"r#r/�sV����






�zXMLParser.__init__cCs*|j}|j}|D]�}|dkrd|_|||jfdd�}||_q|dkr/|||jfdd�}||_q|dkrNt|jd�rC|||j	fd	d�}n||fd
d�}||_
q|dkrmt|jd�rb|||jfd
d�}n||fdd�}||_q|dkr}|||fdd�}||_
q|dkr�|||fdd�}||_qtd|��dS)NrErcS�|||||�f�dSr:r")r$Z	attrib_inr1rQrEr"r"r#�handler.�z%XMLParser._setevents.<locals>.handlerr(cS�||||�f�dSr:r")r$r1rQr(r"r"r#rg3�zstart-nsrNcSrfr:r")r�r�r1rQrNr"r"r#rg:rhcSs|||pd|pdff�dSr?r")r�r�r1rQr"r"r#rg>szend-nsrOcSrir:r")r�r1rQrOr"r"r#rgDrjcSs||df�dSr:r")r�r1rQr"r"r#rgHrrHcSs|||j�|�f�dSr:)rwrH)r;r1rQr-r"r"r#rgLr3rIcSs|||j�||�f�dSr:)rwrI)Z	pi_targetr�r1rQr-r"r"r#rgPszunknown event %r)rrQrarWrXrYrZr%rwr[r\r]r^r_r`r�)r-Zevents_queueZevents_to_reportr�rQZ
event_namergr"r"r#r+"sL
�
���
��zXMLParser._seteventscCs"t|�}|j|_|j|jf|_|�r:)r�code�lineno�offsetZposition)r-rj�errr"r"r#�_raiseerrorWszXMLParser._raiseerrorcCsDz|j|}W|Sty!|}d|vrd|}||j|<Y|Sw)Nr�r�)rU�KeyError)r-ri�namer"r"r#�_fixname]s��zXMLParser._fixnamecCs|j�|pd|p	d�Sr?)rwrN�r-r�r�r"r"r#r[hszXMLParser._start_nscCs|j�|pd�Sr?)rwrO)r-r�r"r"r#r]krzXMLParser._end_nscCsR|j}||�}i}|r"tdt|�d�D]}||d||||�<q|j�||�S)NrrBr)rr�ranger?rwrE)r-r$�	attr_listZfixnamer+�ir"r"r#rWnszXMLParser._startcCs|j�|�|��Sr:)rwr(rrr�r"r"r#rYzr{zXMLParser._endc	Cs�|dd�}|dkrTz|jj}Wn
tyYdSwz||j|dd��WdStySddlm}|�d||jj	|jj
f�}d|_|jj	|_|jj
|_
|�w|dkre|dd	�d
kreg|_dS|jdur�|dkrsd|_dS|��}|s{dS|j�|�t|j�}|dkr�|jd}|d
kr�|dkr�|j\}}}	}
|	r�|	dd�}	n|dkr�|dkr�|j\}}}
d}	ndSt|jd�r�|j�||	|
dd��nt|d�r�t�dt�d|_dSdSdS)Nrr�r
rrLz'undefined entity %s: line %d, column %d�r��	z	<!DOCTYPEr�rBZPUBLIC�ZSYSTEM��doctypezaThe doctype() method of XMLParser is ignored.  Define doctype() method on the TreeBuilder target.)rwr�r�rcrprPrMrSr�ZErrorLineNumberZErrorColumnNumberrkrlrmrbrrQr?r%r{r5r6�RuntimeWarning)r-r;r�Zdata_handlerrMrn�nrXrqZpubid�systemr"r"r#rV}sn����

�



�
�
�
zXMLParser._defaultc
CsHz
|j�|d�WdS|jy#}z|�|�WYd}~dSd}~ww)r,FN)r��ParserTro)r-r�r�r"r"r#r��s��zXMLParser.feedc
Cs�z	|j�dd�Wn|jy!}z|�|�WYd}~nd}~wwz'z|jj}Wn	ty2Yn
w|�W|`|`|`|`SW|`|`|`|`dS|`|`|`|`w)z;Finish feeding data to parser and return element structure.�TN)	r�rrTrorwr�r�rrR)r-r�Z
close_handlerr"r"r#r��s&���
��
zXMLParser.closec
Cs�|j��}z:z|j�d�|j�dd�Wn|jy-}z|�|�WYd}~nd}~wwW|j�|�dSW|j�|�dS|j�|�w)NFr�)r�ZGetReparseDeferralEnabledZSetReparseDeferralEnabledrrTro)r-Zwas_enabledr�r"r"r#r2�s
����zXMLParser.flush)rrr r!r/r+rorrr[r]rWrYrVr�r�r2r"r"r"r#r�s	-56r)�out�	from_filecKs�|dur|durtd��d}|durt��}}tt|jfi|��d�}|dur2|�|�|��n
|dur<t||d�|durD|�	�SdS)a3Convert XML to its C14N 2.0 serialised form.

    If *out* is provided, it must be a file or file-like object that receives
    the serialised canonical XML output (text, not bytes) through its ``.write()``
    method.  To write to a file, open it in text mode with encoding "utf-8".
    If *out* is not provided, this function returns the output as text string.

    Either *xml_data* (an XML string) or *from_file* (a file path or
    file-like object) must be provided as input.

    The configuration options are the same as for the ``C14NWriterTarget``.
    Nz:Either 'xml_data' or 'from_file' must be provided as inputr')r�)
r�r�rrrr�r�r�r
r)Zxml_datar�r�ZoptionsZsior�r"r"r#r�s


rz	^\w+:\w+$c@s�eZdZdZdddddddd�dd�Zefdd�Zd	d
�Zddd�Zd
d�Z	dj
fdd�Zdd�Zdd�Z
ddd�Zdd�Zdd�Zdd�ZdS)ra�
    Canonicalization writer target for the XMLParser.

    Serialises parse events to XML C14N 2.0.

    The *write* function is used for writing out the resulting data stream
    as text (not bytes).  To write to a file, open it in text mode with encoding
    "utf-8" and pass its ``.write`` method.

    Configuration options:

    - *with_comments*: set to true to include comments
    - *strip_text*: set to true to strip whitespace before and after text content
    - *rewrite_prefixes*: set to true to replace namespace prefixes by "n{number}"
    - *qname_aware_tags*: a set of qname aware tag names in which prefixes
                          should be replaced in text content
    - *qname_aware_attrs*: a set of qname aware attribute names in which prefixes
                           should be replaced in text content
    - *exclude_attrs*: a set of attribute names that should not be serialised
    - *exclude_tags*: a set of tag names that should not be serialised
    FN)�
with_comments�
strip_text�rewrite_prefixes�qname_aware_tags�qname_aware_attrs�
exclude_attrs�exclude_tagsc	Cs�||_g|_||_||_|rt|�nd|_|rt|�nd|_||_|r)t|�|_nd|_|r5t|�j	|_
nd|_
dgg|_g|_|sL|j�
tt����|j�
g�i|_dg|_d|_d|_d|_d|_dS)N)r�r�Fr)�_writer8�_with_comments�_strip_textrk�_exclude_attrs�
_exclude_tags�_rewrite_prefixes�_qname_aware_tags�intersection�_find_qname_aware_attrs�_declared_ns_stack�	_ns_stackrQr�r�rn�_prefix_map�_preserve_space�_pending_start�
_root_seen�
_root_done�_ignored_depth)	r-r�r�r�r�r�r�r�r�r"r"r#r/s2�
zC14NWriterTarget.__init__ccs"�||�D]	}|r|EdHqdSr:r")r-Zns_stackZ	_reversedr`r"r"r#�_iter_namespaces4s�
��z!C14NWriterTarget._iter_namespacescCsX|�dd�\}}|�|j�D]\}}||kr d|�d|��Sqtd|�d|�d���)Nr�rr�r�zPrefix z of QName "�" is not declared in scope)�splitr�r�r�)r-Z
prefixed_namer�rqr��pr"r"r#�_resolve_prefix_name9s�z%C14NWriterTarget._resolve_prefix_namecCsx|dur|dd�dkr|dd��dd�nd|f\}}n|}t�}|�|j�D]!\}}||krD||vrD|r=|�d|��n|||fS|�|�q(|jry||jvrX|j|}n
dt|j���}|j|<|jd�||f�|�d|��||fS|s�d|vr�|||fS|�|j	�D]"\}}||kr�|jd�||f�|r�|�d|��n|||fSq�|s�|||fSt
d|�d	���)
Nrr�r�r�r�r}r
zNamespace "r�)r�rkr�r��addr�r�r?rQr�r�)r-r�r�r$Z
prefixes_seen�ur�r"r"r#�_qname@s02 

 �
zC14NWriterTarget._qnamecCs|js|j�|�dSdSr:)r�r8rQrCr"r"r#r�es�zC14NWriterTarget.datar�cCs�||j�}|jdd�=|jr|jds|��}|jdur=|jd}|_|r+t|�r+|nd}|jg|�|�R�|dur=dS|rK|jrM|�t	|��dSdSdS�Nr
)
r8r�r�rr��_looks_like_prefix_namerWr�r��_escape_cdata_c14n)r-Z
_join_textr�rK�
qname_textr"r"r#rBis


�zC14NWriterTarget._flushcCs0|jrdS|jr|��|jd�||f�dSr�)r�r8rBr�rQrsr"r"r#rNws
zC14NWriterTarget.start_nscCs�|jdur|js
||jvr|jd7_dS|jr|��g}|j�|�|jdur7||jvr7|||f|_dS|�|||�dSr�)	r�r�r8rBr�rQr�r�rW)r-r$rD�new_namespacesr"r"r#rEs
�
zC14NWriterTarget.startcs��jdur|r�fdd�|��D�}|h|�}i}|dur+��|�}||<|�|��jdurX|rX��|�}|rU|D]}	||	}
t|
�rS��|
�}||
<|�|�q;nd}nd}�j��fdd�t|dd�d�D�}|rzdd�|D�}|��ng}|r�t|���D]*\}
}|dur�|
|vr�||vr�|||d	}||
\}}	}|�	|r�|n|	|f�q�|�
d
�}�j�	|r�|dkn�jd��j}|d
||d	�|r�|d�
dd�|D���|d�|dur�|t|||d	��d�_�j�	g�dS)Ncs i|]\}}|�jvr||�qSr")r���.0r�r�r1r"r#�
<dictcomp>�s z+C14NWriterTarget._start.<locals>.<dictcomp>csi|]}|�|��qSr"r")r�r})�parse_qnamer"r#r��scSs|�dd�S)Nr�r)r�)r}r"r"r#r��sz)C14NWriterTarget._start.<locals>.<lambda>r�cSs$g|]\}}|rd|nd|f�qS)zxmlns:Zxmlnsr")r�r�r�r"r"r#�
<listcomp>�s��z+C14NWriterTarget._start.<locals>.<listcomp>rz+{http://www.w3.org/XML/1998/namespace}spaceZpreserver
r�r�cSs&g|]\}}d|�dt|��d��qS)rvz="r�)�_escape_attrib_c14nr�r"r"r#r��s&r�T)r�rnr�r�r�r�r�r��sortrQrhr�r�r@r�r�r�)r-r$rDr�r�r�Zresolved_namesr�ZqattrsZ	attr_namerjZ
parsed_qnamesrur�r�Z
attr_qnamer�Zspace_behaviourr�r")r�r-r#rW�sb



��
��

�zC14NWriterTarget._startcCst|jr|jd8_dS|jr|��|�d|�|�d�d��|j��t|j�dk|_|j	��|j
��dS)Nrr�rr�)r�r8rBr�r�r�rFr?r�r�r�r�r"r"r#r(�s

zC14NWriterTarget.endcCsh|jsdS|jr
dS|jr|�d�n
|jr|jr|��|�dt|��d��|js2|�d�dSdS)Nr�z<!--z-->)r�r�r�r�r�r8rBr�rAr"r"r#rH�s�zC14NWriterTarget.commentcCst|jrdS|jr|�d�n
|jr|jr|��|�|r'd|�dt|��d�nd|�d��|js8|�d�dSdS)Nr�z<?rvz?>)r�r�r�r�r8rBr�)r-rwr�r"r"r#rI�s$��zC14NWriterTarget.pir:)rrr r!r/�reversedr�r�r�r�r@rBrNrErWr(rHrIr"r"r"r#r�s"�%
%
E
rc	Csxz+d|vr|�dd�}d|vr|�dd�}d|vr|�dd�}d|vr)|�dd�}|WSttfy;t|�YdSw)	Nr�r�r�r�r�r�r�&#xD;r�rxr"r"r#r��s�r�c	Cs�z?d|vr|�dd�}d|vr|�dd�}d|vr|�dd�}d|vr)|�dd�}d	|vr3|�d	d
�}d|vr=|�dd�}|WSttfyOt|�YdSw)
Nr�r�r�r�r�rrz&#x9;r�z&#xA;rr�r�rxr"r"r#r�s"�r�)ro)�_set_factoriesr:rt)rr)Ar!�__all__rrr�r5r�r#Zcollections.abcr�r�rr-rrrrrr
rrr�contextmanagerr�r�r�r�rk�	NameErrorr�r�r�rr�r�r�r�r�rr�rrrrr
r	rrrrrrrr�compile�UNICODEr�r�rr�r�rWZ_elementtreer�rQr"r"r"r#�<module>s�H/

0e

1=2�2�	�
��

6
2
:

zn�