AlkantarClanX12

Your IP : 3.23.103.216


Current Path : /proc/self/root/usr/lib64/python3.8/xml/etree/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.8/xml/etree/__pycache__/ElementTree.cpython-38.pyc

U

e5d��@s�dZddddddddd	d
ddd
ddddddddddddgZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZGdd
�d
e�Z
d d�ZGd!d�d�Zifd"d�Zd]d#d�Zd^d$d�ZeZGd%d
�d
�ZGd&d�d�Ze	jd'd(��Zd_d)d*�Zd+d,�Zd-Zzee�ZWnek
�r.YnXd.d/�Zd0d1�Zeeed2�Zd3d�Z d4d5d6d7d8d9d:d;�Z!e!e _!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%d`dddDdE�dFd�Z&GdGdH�dHej'�Z(dadddDdE�dId�Z)dJd�Z*dbdKd	�Z+dcdLd�Z,GdMd�d�Z-dddNd�Z.dedOd�Z/e.Z0dfdPd�Z1GdQd�d�Z2GdRd�d�Z3dgdddS�dTd�Z4e�5dUej6�j7Z8GdVd�d�Z9dWdX�Z:dYdZ�Z;zeZ<dd[l=Tdd\l=m>Z>Wne?k
�r�YnXe>ee�dS)haLightweight 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�	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)r
z�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!�-/usr/lib64/python3.8/xml/etree/ElementTree.pyr
jscCs
t|d�S)z2Return True if *element* appears to be an Element.�tag)�hasattr)�elementr!r!r"rxsc@s
eZdZdZdZdZdZdZifdd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd9d!d"�Zd:d#d$�Zd;d%d&�Zd<d'd(�Zd)d*�Zd=d+d,�Zd-d.�Zd/d0�Zd1d2�Zd>d3d4�Z d?d5d6�Z!d7d8�Z"dS)@rahAn 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

    NcKs6t|t�std|jjf��||_||�|_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__�szElement.__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.makeelementcCs0|�|j|j�}|j|_|j|_||dd�<|S)z�Return copy of current element.

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

        N)r2r#r*�text�tail)r,�elemr!r!r"�copy�s
zElement.copycCs
t|j�S�N)�lenr+r0r!r!r"�__len__�szElement.__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)�warnings�warn�
FutureWarningr8r+r0r!r!r"�__bool__�s�zElement.__bool__cCs
|j|Sr7�r+�r,�indexr!r!r"�__getitem__�szElement.__getitem__cCs8t|t�r |D]}|�|�qn
|�|�||j|<dSr7)r&�slice�_assert_is_elementr+)r,rCr%Zeltr!r!r"�__setitem__�s


zElement.__setitem__cCs|j|=dSr7rArBr!r!r"�__delitem__�szElement.__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�rFr+�append�r,�
subelementr!r!r"rJ�s
zElement.appendcCs$|D]}|�|�|j�|�qdS)zkAppend subelements from a sequence.

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

        NrI)r,�elementsr%r!r!r"�extend�s
zElement.extendcCs|�|�|j�||�dS)z(Insert *subelement* at position *index*.N)rFr+�insert)r,rCrLr!r!r"rO�s
zElement.insertcCs t|t�stdt|�j��dS)Nzexpected an Element, not %s)r&�_Element_Pyr(�typer)r,�er!r!r"rF�s
zElement._assert_is_elementcCs|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+�removerKr!r!r"rSs
zElement.removecCstjdtdd�|jS)z`(Deprecated) Return all subelements.

        Elements are returned in document order.

        zaThis method will be removed in future versions.  Use 'list(elem)' or iteration over elem instead.r:r;)r=r>�DeprecationWarningr+r0r!r!r"�getchildrens�zElement.getchildrencCst�|||�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"rV!s	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,rX�defaultrYr!r!r"rZ,szElement.findtextcCst�|||�S)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�findallrWr!r!r"r]:s	zElement.findallcCst�|||�S)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�iterfindrWr!r!r"r^Es	zElement.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+r3r4r0r!r!r"r_Ps
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,�keyr\r!r!r"r`[szElement.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,ra�valuer!r!r"�sethszElement.setcCs
|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*�keysr0r!r!r"rdrszElement.keyscCs
|j��S)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*�itemsr0r!r!r"re{s	z
Element.itemsccsD|dkrd}|dks|j|kr$|V|jD]}|�|�EdHq*dS)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#rRr!r!r"rg�s
zElement.itercCstjdtdd�t|�|��S)NzbThis method will be removed in future versions.  Use 'elem.iter()' or 'list(elem.iter())' instead.r:r;�r=r>rT�listrg�r,r#r!r!r"�getiterator�s�zElement.getiteratorccsX|j}t|t�s|dk	rdS|j}|r,|V|D]"}|��EdH|j}|r0|Vq0dS)z�Create text iterator.

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

        N)r#r&�strr3�itertextr4)r,r#�trRr!r!r"rm�szElement.itertext)N)NN)N)N)N)N)N)#rrrr r#r*r3r4r.r1r2r6r9r@rDrGrHrJrNrOrFrSrUrVrZr]r^r_r`rcrdrergrkrmr!r!r!r"r}s@	








	

cKs"||�}|�||�}|�|�|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.

    )r2rJ)�parentr#r*r-r%r!r!r"r�s
cCstt�}||_|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.

    )rrr3)r3r%r!r!r"r�s	cCs&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r3)�targetr3r%r!r!r"r�s

c@sZeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)r
a�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�r3)r,Ztext_or_urir#r!r!r"r.�szQName.__init__cCs|jSr7rrr0r!r!r"�__str__�sz
QName.__str__cCsd|jj|jfS)Nz<%s %r>)r)rr3r0r!r!r"r1szQName.__repr__cCs
t|j�Sr7)�hashr3r0r!r!r"�__hash__szQName.__hash__cCs t|t�r|j|jkS|j|kSr7�r&r
r3�r,�otherr!r!r"�__le__s
zQName.__le__cCs t|t�r|j|jkS|j|kSr7rvrwr!r!r"�__lt__s
zQName.__lt__cCs t|t�r|j|jkS|j|kSr7rvrwr!r!r"�__ge__s
zQName.__ge__cCs t|t�r|j|jkS|j|kSr7rvrwr!r!r"�__gt__s
zQName.__gt__cCs t|t�r|j|jkS|j|kSr7rvrwr!r!r"�__eq__s
zQName.__eq__)N)
rrrr r.rsr1ruryrzr{r|r}r!r!r!r"r
�s
c@s�eZdZdZddd�Zdd�Zdd�Zdd	d
�Zddd�Zd d
d�Z	d!dd�Z
d"dd�Zd#dd�Zd$dd�Z
d%dd�dd�Zdd�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|�|�dSr7)�_rootr	)r,r%�filer!r!r"r.'szElementTree.__init__cCs|jS)z!Return root element of this tree.�r~r0r!r!r"�getroot-szElementTree.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"�_setroot1szElementTree._setrootcCs�d}t|d�st|d�}d}z^|dkrLt�}t|d�rL|�|�|_|jW�2S|�d�}|s\qh|�|�qL|��|_|jW�S|r�|��XdS)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$�open�closerr�r~r��feed)r,�source�parser�close_source�datar!r!r"r	;s$






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~rgrjr!r!r"rg`s
zElementTree.itercCstjdtdd�t|�|��S)NzbThis method will be removed in future versions.  Use 'tree.iter()' or 'list(tree.iter())' instead.r:r;rhrjr!r!r"rkms�zElementTree.getiteratorcCs:|dd�dkr,d|}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 %rr:r;)r=r>r?r~rVrWr!r!r"rVus��zElementTree.findcCs<|dd�dkr,d|}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�r:r;)r=r>r?r~rZr[r!r!r"rZ�s��zElementTree.findtextcCs:|dd�dkr,d|}tjd|tdd�|j�||�S)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�r:r;)r=r>r?r~r]rWr!r!r"r]�s��zElementTree.findallcCs:|dd�dkr,d|}tjd|tdd�|j�||�S)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�r:r;)r=r>r?r~r^rWr!r!r"r^�s��zElementTree.iterfindT��short_empty_elementsc	Cs�|s
d}n|tkrtd|��|s4|dkr0d}nd}|��}t||���}|dkr�|sd|dkr�|dkr�|}	|dkr�d	dl}
|
��}	|d
|	f�|dkr�t||j�n,t|j|�\}}t|}
|
||j|||d�W5QRXdS)
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)r�r��unicoder�rz$<?xml version='1.0' encoding='%s'?>
r3r�)	�
_serialize�
ValueError�lower�_get_writer�localeZgetpreferredencoding�_serialize_textr~�_namespaces)r,�file_or_filename�encoding�xml_declaration�default_namespace�methodr�Z	enc_lower�writeZdeclared_encodingr��qnamesrYZ	serializer!r!r"r��s:����zElementTree.writecCs|j|dd�S)Nr�)r�)r�)r,rr!r!r"�
write_c14nszElementTree.write_c14n)NN)N)N)N)N)NN)N)N)NNNN)rrrr r.r�r�r	rgrkrVrZr]r^r�r�r!r!r!r"rs&



%





��:ccs"z
|j}WnPtk
rZ|dkr.t|d�}nt|d|dd�}|�|jVW5QRXYn�X|dkrl|Vn�t����}t|tj�r�|}nft|tj�r�t�	|�}|�
|j�nBt��}dd�|_||_z|j
|_
|j|_Wntk
r�YnXtj||ddd�}|�
|j�|jVW5QRXdS)	Nr��w�xmlcharrefreplace)r��errorscSsdS�NTr!r!r!r!r"�<lambda>0�z_get_writer.<locals>.<lambda>�
)r�r��newline)r��AttributeErrorr��
contextlib�	ExitStackr&�io�BufferedIOBase�	RawIOBase�BufferedWriter�callback�detach�writable�seekable�tell�
TextIOWrapper)r�r�r�r�stackr!r!r"r�sB
�


�r�csddi�i��rd��<���fdd�}|��D]�}|j}t|t�rZ|j�kr�||j�n<t|t�rv|�kr�||�n |dk	r�|tk	r�|tk	r�t|�|�	�D]F\}}t|t�r�|j}|�kr�||�t|t�r�|j�kr�||j�q�|j}t|t�r0|j�kr0||j�q0��fS)N�cs�z�|dd�dkr�|dd��dd�\}}��|�}|dkrjt�|�}|dkrZdt��}|dkrj|�|<|r�d||f�|<q�|�|<n�r�td��|�|<Wntk
r�t|�YnXdS)Nr�{�}zns%dr�z%s:%sz<cannot use non-qualified names with default_namespace option)�rsplitr`�_namespace_mapr8r�r(�_raise_serialization_error)�qname�urir#�prefix�r�rYr�r!r"�	add_qnameMs(


�z_namespaces.<locals>.add_qname)
rgr#r&r
r3rlrrr�re)r5r�r�r#rarbr3r!r�r"r�Bs4




r�cKs�|j}|j}|tkr$|d|��nv|tkr<|d|��n^||}|dkr||r\|t|��|D]}t|||d|d�q`�n|d|�t|���}	|	s�|�r2|r�t|��dd�d�D](\}
}|r�d|}|d	|t	|
�f�q�|	D]L\}}
t
|t�r�|j}t
|
t��r||
j}
nt	|
�}
|d
|||
f�q�|�sHt|��sH|�s�|d�|�rb|t|��|D]}t|||d|d��qf|d|d�n|d
�|j
�r�|t|j
��dS)N�	<!--%s-->�<?%s?>r��<cSs|dS�Nrr!��xr!r!r"r��r�z _serialize_xml.<locals>.<lambda>�ra�:�
 xmlns%s="%s"� %s="%s"�>�</z />)r#r3rr�
_escape_cdata�_serialize_xmlrire�sorted�_escape_attribr&r
r8r4)r�r5r�rYr��kwargsr#r3rRre�v�kr!r!r"r�s\
�
��


�
r�)
Zarea�baseZbasefont�br�col�frameZhrZimg�inputZisindex�link�metaZparamcKs�|j}|j}|tkr(|dt|���n�|tkrD|dt|���nh||}|dkr�|rd|t|��|D]}t|||d�qh�n,|d|�t|���}|s�|�r8|r�t|��dd�d�D](\}	}
|
r�d|
}
|d|
t	|	�f�q�|D]N\}
}	t
|
t��r|
j}
t
|	t��r||	j}	nt|	�}	|d	||
|	f�q�|d
�|�
�}|�rx|dk�sb|dk�rl||�n|t|��|D]}t|||d��q||tk�r�|d
|d
�|j�r�|t|j��dS)Nr�r�r�cSs|dSr�r!r�r!r!r"r��r�z!_serialize_html.<locals>.<lambda>r�r�r�r�r�ZscriptZstyler�)r#r3rr�r�_serialize_htmlrirer�r�r&r
�_escape_attrib_htmlr��
HTML_EMPTYr4)r�r5r�rYr�r#r3rRrer�r�Zltagr!r!r"r��sX
��


r�cCs*|��D]}||�q|jr&||j�dSr7)rmr4)r�r5�partr!r!r"r��s
r�)r��htmlr3cCsLt�d|�rtd��tt���D]\}}||ks8||kr t|=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�rir�re)r�r�r�r�r!r!r"r�sr�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��dS)Nzcannot serialize %r (type %s))r(rQrrrr!r!r"r�s�r�c	CshzBd|kr|�dd�}d|kr*|�dd�}d|kr>|�dd�}|WSttfk
rbt|�YnXdS)N�&�&amp;r��&lt;r��&gt;��replacer(r�r�rrr!r!r"r�!sr�c	Cs�z�d|kr|�dd�}d|kr*|�dd�}d|kr>|�dd�}d|krR|�dd�}d	|krf|�d	d
�}d|krz|�dd
�}d
|kr�|�d
d�}d
|kr�|�d
d�}|WSttfk
r�t|�YnXdS)Nr�r�r�r�r�r��"�&quot;z
r��
z&#10;�	z&#09;r�rrr!r!r"r�1s(r�c	CshzBd|kr|�dd�}d|kr*|�dd�}d|kr>|�dd�}|WSttfk
rbt|�YnXdS)Nr�r�r�r�r�r�r�rrr!r!r"r�Ms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�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�_ListDataStreamz7An auxiliary stream accumulating into a list reference.cCs
||_dSr7)�lst)r,r�r!r!r"r.vsz_ListDataStream.__init__cCsdSr�r!r0r!r!r"r�ysz_ListDataStream.writablecCsdSr�r!r0r!r!r"r�|sz_ListDataStream.seekablecCs|j�|�dSr7)r�rJ)r,�br!r!r"r�sz_ListDataStream.writecCs
t|j�Sr7)r8r�r0r!r!r"r��sz_ListDataStream.tellN)	rrrr r.r�r�r�r�r!r!r!r"r�tsr�cCs*g}t|�}t|�j||||||d�|S)Nr�)r�rr�)r%r�r�r�r�r�r�r�r!r!r"r�s�cCsLt|t�st|�}|jtjdd�|��j}|r<|ddkrHtj�d�dS)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�r4)r5r4r!r!r"r�s

cCst�}|�||�|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��treer!r!r"r	�s	csft||d������fdd��G�fdd�dtjj�}|��d�_�~d�t�d�sbt�d	��d
��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^zJ���EdH��d�}|s q,��|�q���}���EdH|�_W5�rX���XdS)Ni@)r��read_eventsr�r��_close_and_return_root�root)r�r)r��it�
pullparserr�r!r"�iterator�s

ziterparse.<locals>.iteratorcseZdZ��jZdS)z$iterparse.<locals>.IterParseIteratorN)rrr�__next__r!)rr!r"�IterParseIterator�srNFr�r�T)r�collections�abc�Iteratorrr$r�)r�r�r�rr!)r�rrrr�r"r�s

c@s<eZdZd
dd�dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)rN)rcCs<t��|_|ptt�d�|_|dkr(d}|j�|j|�dS)N�rq)�end)r	�deque�
_events_queuerrr�
_setevents)r,r�rr!r!r"r.�s

zXMLPullParser.__init__c
CsZ|jdkrtd��|rVz|j�|�Wn.tk
rT}z|j�|�W5d}~XYnXdS)�Feed encoded data to parser.Nz!feed() called after end of stream)rr�r��SyntaxErrorrrJ)r,r��excr!r!r"r��s
zXMLPullParser.feedcCs|j��}d|_|Sr7)rr�)r,rr!r!r"r�s
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)rr0r!r!r"r�szXMLPullParser.closeccs.|j}|r*|��}t|t�r"|�q|VqdS)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_events)N)rrrr.r�rr�rr!r!r!r"r�s

cCs"|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�)r3r�r!r!r"rs
cCsR|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r/)rrr�r�rgr`)r3r�r�Zidsr5r/r!r!r"r,s



cCs,|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r)Zsequencer�r3r!r!r"rDs
	c@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|_|dkr*t}||_||_|dkrBt}||_	||_
|dkrZt}||_dSr7)
�_data�_elem�_lastr~�_tailr�_comment_factoryrr�_pi_factoryrr�_factory)r,Zelement_factoryrrrrr!r!r"r.js zTreeBuilder.__init__cCs.t|j�dkstd��|jdk	s(td��|jS)z;Flush builder buffers and return toplevel document Element.rzmissing end tagsNzmissing toplevel element)r8r�AssertionErrorr~r0r!r!r"r�~szTreeBuilder.closecCsf|jrb|jdk	r\d�|j�}|jr@|jjdks6td��||j_n|jjdksTtd��||j_g|_dS)Nr�zinternal error (tail)zinternal error (text))rr�joinrr4r#r3�r,r3r!r!r"�_flush�s

zTreeBuilder._flushcCs|j�|�dS)zAdd text to current element.N)rrJ�r,r�r!r!r"r��szTreeBuilder.datacCsX|��|�||�|_}|jr2|jd�|�n|jdkrB||_|j�|�d|_|S)z�Open new element and return it.

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

        r�Nr)r&r"rrrJr~r)r,r#�attrsr5r!r!r"�start�s
zTreeBuilder.startcCs@|��|j��|_|jj|ks4td|jj|f��d|_|jS)zOClose and return current Element.

        *tag* is the element name.

        z&end tag mismatch (expected %s, got %s)r)r&r�poprr#r#rrjr!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 rr%r!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 ''.
        )r+r!r)r,rqr3r!r!r"�pi�s�zTreeBuilder.picGs:||�}|r6|��||_|jr0|jd�|�d|_|S)Nr�r)r&rrrJr)r,�factoryrO�argsr5r!r!r"r+�szTreeBuilder._handle_single)N)N)
rrrr r.r�r&r�r)r
r,r-r+r!r!r!r"rVs�
	c@speZdZdZddd�dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�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)rqr�cCsdzddlm}Wn>tk
rNzddl}Wntk
rHtd��YnXYnX|�|d�}|dkrjt�}||_|_||_|_	|j
|_i|_|j
|_t|d�r�|j|_t|d�r�|j|_t|d�r�|j|_t|d�r�|j|_t|d	�r�|j|_t|d
��r|j|_t|d��r|j|_d|_d|_d|_ d|_!i|_"zd
|j#|_$Wnt%k
�r^YnXdS)Nr��expatz7No module named expat; use SimpleXMLTreeBuilder insteadr�r)r
�start_ns�end_nsr�r,r-rzExpat %d.%d.%d)&�xml.parsersr1�ImportErrorZpyexpatZParserCreaterr�rrq�_target�error�_error�_names�_defaultZDefaultHandlerExpandr$�_start�StartElementHandler�_end�EndElementHandler�	_start_ns�StartNamespaceDeclHandler�_end_ns�EndNamespaceDeclHandlerr�ZCharacterDataHandlerr,�CommentHandlerr-�ProcessingInstructionHandlerZbuffer_text�ordered_attributes�specified_attributes�_doctype�entity�version_info�versionr�)r,rqr�r1r�r!r!r"r.�sP�




zXMLParser.__init__cCs8|j}|j}|D�] }|dkrDd|_d|_|||jfdd�}||_q|dkrf|||jfdd�}||_q|dkr�t|j	d�r�|||j
fd	d�}n||fd
d�}||_q|dkr�t|j	d�r�|||jfd
d�}n||fdd�}||_
q|dk�r|||fdd�}||_q|dk�r&|||fdd�}||_qtd|��qdS)Nr)rcSs|||||�f�dSr7r!)r#Z	attrib_inrrJr)r!r!r"�handlersz%XMLParser._setevents.<locals>.handlerr
cSs||||�f�dSr7r!)r#rrJr
r!r!r"rKszstart-nsr2cSs|||||�f�dSr7r!)r�r�rrJr2r!r!r"rK!scSs|||p
d|pdff�dS�Nr�r!)r�r�rrJr!r!r"rK%szend-nsr3cSs||||�f�dSr7r!)r�rrJr3r!r!r"rK+scSs||df�dSr7r!)r�rrJr!r!r"rK/sr,cSs|||j�|�f�dSr7)rqr,)r3rrJr,r!r!r"rK3sr-cSs|||j�||�f�dSr7)rqr-)Z	pi_targetr�rrJr,r!r!r"rK7szunknown event %r)rrJrErFr;r<r=r>r$rqr?r@rArBrCrDr�)r,Zevents_queueZevents_to_reportr�rJZ
event_namerKr!r!r"rsL
�
�
��

�
zXMLParser._seteventscCs&t|�}|j|_|j|jf|_|�dSr7)r
�code�lineno�offsetZposition)r,rb�errr!r!r"�_raiseerror>szXMLParser._raiseerrorcCsFz|j|}Wn2tk
r@|}d|kr2d|}||j|<YnX|S)Nr�r�)r9�KeyError)r,ra�namer!r!r"�_fixnameDszXMLParser._fixnamecCs|j�|pd|pd�SrL)rqr2�r,r�r�r!r!r"r?OszXMLParser._start_nscCs|j�|pd�SrL)rqr3)r,r�r!r!r"rARszXMLParser._end_nscCsR|j}||�}i}|rDtdt|�d�D]}||d||||�<q&|j�||�S)Nrr:r)rT�ranger8rqr))r,r#�	attr_listZfixnamer*�ir!r!r"r;UszXMLParser._startcCs|j�|�|��Sr7)rqr
rTrjr!r!r"r=aszXMLParser._endc	Cs�|dd�}|dkr�z|jj}Wntk
r6YdSXz||j|dd��WnZtk
r�ddlm}|�d||jj	|jj
f�}d|_|jj	|_|jj
|_
|�YnX�n"|dkr�|dd	�d
kr�g|_�n|jdk	�r�|dkr�d|_dS|��}|�sdS|j�|�t|j�}|dk�r�|jd}|d
k�rd|dk�rd|j\}}}	}
|	�r�|	dd�}	n*|dk�r�|dk�r�|j\}}}
d}	ndSt|jd��r�|j�||	|
dd��nt|d��r�t�dt�d|_dS)Nrr�r�rr0z'undefined entity %s: line %d, column %d�r��	z	<!DOCTYPEr�r:ZPUBLIC�ZSYSTEM��doctypezaThe doctype() method of XMLParser is ignored.  Define doctype() method on the TreeBuilder target.)rqr�r�rHrRr4r1r7r�ZErrorLineNumberZErrorColumnNumberrMrNrOrG�striprJr8r$r]r=r>�RuntimeWarning)r,r3r�Zdata_handlerr1rP�nrQrSZpubid�systemr!r!r"r:dsd���





�zXMLParser._defaultc
CsFz|j�|d�Wn.|jk
r@}z|�|�W5d}~XYnXdS)rrN)r��Parser8rQ)r,r�r�r!r!r"r��szXMLParser.feedc
Cs�z|j�dd�Wn.|jk
r@}z|�|�W5d}~XYnXz0z|jj}Wntk
rdYnX|�W�SW5|`|`|`|`XdS)z;Finish feeding data to parser and return element structure.r�rN)	r�rbr8rQrrqr6r�r�)r,r�Z
close_handlerr!r!r"r��szXMLParser.close)rrrr r.rrQrTr?rAr;r=r:r�r�r!r!r!r"r�s	.66)�out�	from_filecKs�|dkr|dkrtd��d}|dkr0t��}}tt|jf|�d�}|dk	r`|�|�|��n|dk	rtt||d�|dk	r�|�	�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�r�rrr�r�r�r	r�)Zxml_datarcrdZoptionsZsior�r!r!r"r�s


z	^\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|_||_||_|r$t|�nd|_|r6t|�nd|_||_|rRt|�|_nd|_|rjt|�j	|_
nd|_
dgg|_g|_|s�|j�
tt����|j�
g�i|_dg|_d|_d|_d|_d|_dS)N)r�r�Fr)�_writer�_with_comments�_strip_textrc�_exclude_attrs�
_exclude_tags�_rewrite_prefixes�_qname_aware_tags�intersection�_find_qname_aware_attrs�_declared_ns_stack�	_ns_stackrJrir�re�_prefix_map�_preserve_space�_pending_start�
_root_seen�
_root_done�_ignored_depth)	r,r�rerfrgrhrirjrkr!r!r"r.�s2�zC14NWriterTarget.__init__ccs ||�D]}|r|EdHqdSr7r!)r,Zns_stackZ	_reversedrYr!r!r"�_iter_namespacessz!C14NWriterTarget._iter_namespacescCs\|�dd�\}}|�|j�D]$\}}||krd|�d|��Sqtd|�d|�d���dS)Nr�rr�r�zPrefix z of QName "�" is not declared in scope)�splitr}rvr�)r,Z
prefixed_namer�rSr��pr!r!r"�_resolve_prefix_names
z%C14NWriterTarget._resolve_prefix_namecCs�|dkr:|dd�dkr,|dd��dd�nd|f\}}n|}t�}|�|j�D]B\}}||kr�||kr�|rz|�d|��n|||fS|�|�qP|jr�||jkr�|j|}ndt|j���}|j|<|jd�||f�|�d|��||fS|�sd|k�r|||fS|�|j	�D]J\}}||k�r|jd�||f�|�rR|�d|��n|||fS�q|�st|||fSt
d|�d	���dS)
Nrr�r�r�r�r`r�zNamespace "r~)r�rcr}ru�addrqrwr8rJrvr�)r,r�r�r#Z
prefixes_seen�ur�r!r!r"�_qnames.2 


&
zC14NWriterTarget._qnamecCs|js|j�|�dSr7)r|rrJr'r!r!r"r�CszC14NWriterTarget.datar�cCs�||j�}|jdd�=|jr.|jds.|��}|jdk	rv|jd}|_|rVt|�rV|nd}|j||f��|dk	rvdS|r�|jr�|�t	|��dS�Nr�)
rrnrxr^ry�_looks_like_prefix_namer;rzrl�_escape_cdata_c14n)r,Z
_join_textr�r/�
qname_textr!r!r"r&Gs


zC14NWriterTarget._flushcCs0|jr
dS|jr|��|jd�||f�dSr�)r|rr&rvrJrUr!r!r"r2Us
zC14NWriterTarget.start_nscCs�|jdk	r,|js||jkr,|jd7_dS|jr:|��g}|j�|�|jdk	rn||jkrn|||f|_dS|�|||�dSr�)	rpr|rr&rurJrrryr;)r,r#r(�new_namespacesr!r!r"r)]s
��zC14NWriterTarget.startcs�jdk	r$|r$�fdd�|��D�}|h|�}i}|dk	rV��|�}||<|�|��jdk	r�|r���|�}|r�|D]0}	||	}
t|
�rv��|
�}||
<|�|�qvq�d}nd}�j��fdd�t|dd�d�D�}|r�dd�|D�}|��ng}|�rjt|���D]^\}
}|dk	�r@|
|k�r@||k�r@|||d	}||
\}}	}|�	|�r\|n|	|f��q
|�
d
�}�j�	|�r�|dkn�jd��j}|d
||d	�|�r�|d�
dd�|D���|d�|dk	�r�|t|||d	��d�_�j�	g�dS)Ncs i|]\}}|�jkr||�qSr!)ro��.0r�r�r0r!r"�
<dictcomp>ps
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��r�z)C14NWriterTarget._start.<locals>.<lambda>r�cSs$g|]\}}|rd|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)rpz="r�)�_escape_attrib_c14nr�r!r!r"r��sr�T)rorer�r�rtr�r�r��sortrJr`rxrlr$r�rzrv)r,r#r(r�r�r�Zresolved_namesr�ZqattrsZ	attr_namerbZ
parsed_qnamesrWr�r�Z
attr_qnamer�Zspace_behaviourr�r!)r�r,r"r;ns`


�
�

�
zC14NWriterTarget._startcCst|jr|jd8_dS|jr&|��|�d|�|�d�d��|j��t|j�dk|_|j	��|j
��dS)Nrr�rr�)r|rr&rlr�rxr*r8r{rurvrjr!r!r"r
�s

zC14NWriterTarget.endcCsd|js
dS|jrdS|jr&|�d�n|jr:|jr:|��|�dt|��d��|js`|�d�dS)Nr�z<!--z-->)rmr|r{rlrzrr&r�r%r!r!r"r,�szC14NWriterTarget.commentcCsp|jr
dS|jr|�d�n|jr0|jr0|��|�|rNd|�dt|��d�n
d|�d��|jsl|�d�dS)Nr�z<?rpz?>)r|r{rlrzrr&r�)r,rqr�r!r!r"r-�s$�zC14NWriterTarget.pi)N)N)rrrr r.�reversedr}r�r�r�r$r&r2r)r;r
r,r-r!r!r!r"r�s(�%
%
E
c	Cs|zVd|kr|�dd�}d|kr*|�dd�}d|kr>|�dd�}d|krR|�dd�}|WSttfk
rvt|�YnXdS)	Nr�r�r�r�r�r�r��&#xD;r�rrr!r!r"r��sr�c	Cs�z~d|kr|�dd�}d|kr*|�dd�}d|kr>|�dd�}d|krR|�dd�}d	|krf|�d	d
�}d|krz|�dd�}|WSttfk
r�t|�YnXdS)
Nr�r�r�r�r�r�r�z&#x9;r�z&#xA;r�r�r�rrr!r!r"r��s r�)rf)�_set_factories)N)N)N)NN)NN)N)NN)N)N)N)N)@r �__all__rr�r�r=r�r	Zcollections.abcr�r�rrr
rrrrrrr
r�contextmanagerr�r�r�r�rc�	NameErrorr�r�r�rr�r�r�r�r�rr�r�rrr	rrrrrrrrr�compile�UNICODEr�r�rr�r�rPZ_elementtreer�r5r!r!r!r"�<module>s�J�>

0s
3
=22�	�
��


05


zg