AlkantarClanX12

Your IP : 13.59.134.65


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/xml/etree/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/xml/etree/__pycache__/ElementTree.cpython-35.pyc



��Yf���@swdZddddddddd	d
ddd
dddddddddgZdZddlZddlZddlZddlZddlZddlm	Z	Gdd
�d
e
�Zdd�ZGdd�d�Z
idd�Zdd d�Zdd!d�ZeZGd"d
�d
�ZGd#d�d�Zejd$d%��Zdd&d'�Zd(d)�Zd*d+d,d-d.d/d0d1d2d3d4d5d6f
Zyee�ZWnek
r�YnXd7d8�Zd9d:�Zd;ed<ed=eiZd>d�Zd?d;d@d<dAdBdCdDdEdFdGdHdIdJiZee_dKdL�Z dMdN�Z!dOdP�Z"dQdR�Z#dddSdTdUd�Z$GdVdW�dWej%�Z&dddSdTdXd�Z'dYd�Z(ddZd	�Z)ddd[d�Z*Gd\d]�d]�Z+Gd^d_�d_�Z,dd`d�Z-ddad�Z.e-Z/ddbd�Z0Gdcd�d�Z1Gddd�d�Z2ye
Z3ddel4TWne5k
rrYnXdS)faLightweight 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�register_namespacez1.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__�rr�:/opt/alt/python35/lib64/python3.5/xml/etree/ElementTree.pyr
gscCs
t|d�S)z2Return True if *element* appears to be an Element.�tag)�hasattr)�elementrrrrusc@s�eZdZdZdZdZdZdZidd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zdd!d"�Zddd#d$�Zdd%d&�Zdd'd(�Zd)d*�Zdd+d,�Zd-d.�Zd/d0�Zd1d2�Zdd3d4�Z dd5d6�Z!d7d8�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�s(td|jjf��|j�}|j|�||_||_g|_	dS)Nzattrib must be dict, not %s)
�
isinstance�dict�	TypeError�	__class__r�copy�updater �attrib�	_children)�selfr r)�extrarrr�__init__�s
		zElement.__init__cCs d|jj|jt|�fS)Nz<%s %r at %#x>)r&rr �id)r+rrr�__repr__�szElement.__repr__cCs|j||�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)rrr�makeelement�s	zElement.makeelementcCsD|j|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)r0r r)�text�tail)r+�elemrrrr'�s
zElement.copycCs
t|j�S)N)�lenr*)r+rrr�__len__�szElement.__len__cCs)tjdtdd�t|j�dkS)NzyThe behavior of this method will change in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.�
stacklevel�r)�warnings�warn�
FutureWarningr4r*)r+rrr�__bool__�s
zElement.__bool__cCs|j|S)N)r*)r+�indexrrr�__getitem__�szElement.__getitem__cCs||j|<dS)N)r*)r+r<r"rrr�__setitem__�szElement.__setitem__cCs|j|=dS)N)r*)r+r<rrr�__delitem__�szElement.__delitem__cCs!|j|�|jj|�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)�_assert_is_elementr*�append)r+�
subelementrrrrA�s
zElement.appendcCs2x|D]}|j|�qW|jj|�dS)zkAppend subelements from a sequence.

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

        N)r@r*�extend)r+�elementsr"rrrrC�s
zElement.extendcCs$|j|�|jj||�dS)z(Insert *subelement* at position *index*.N)r@r*�insert)r+r<rBrrrrE�s
zElement.insertcCs,t|t�s(tdt|�j��dS)Nzexpected an Element, not %s)r#�_Element_Pyr%�typer)r+�errrr@�szElement._assert_is_elementcCs|jj|�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*�remove)r+rBrrrrIs
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.r6r7)r8r9�DeprecationWarningr*)r+rrr�getchildrens
zElement.getchildrencCstj|||�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�
namespacesrrrrL s	zElement.findcCstj||||�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+rM�defaultrNrrrrO+szElement.findtextcCstj|||�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�findall)r+rMrNrrrrQ9s	zElement.findallcCstj|||�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�iterfind)r+rMrNrrrrRDs	zElement.iterfindcCs*|jj�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*r1r2)r+rrrrSOs
	z
Element.clearcCs|jj||�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+�keyrPrrrrTZszElement.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+rU�valuerrr�setgszElement.setcCs
|jj�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)�keys)r+rrrrXqszElement.keyscCs
|jj�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)�items)r+rrrrYzs	z
Element.itemsccs\|dkrd}|dks-|j|kr2|Vx#|jD]}|j|�EdHq<WdS)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 rHrrrr[�szElement.itercCs)tjdtdd�t|j|��S)NzbThis method will be removed in future versions.  Use 'elem.iter()' or 'list(elem.iter())' instead.r6r7)r8r9�PendingDeprecationWarning�listr[)r+r rrr�getiterator�s
zElement.getiteratorccsu|j}t|t�r)|dk	r)dS|j}|r=|Vx1|D])}|j�EdH|j}|rD|VqDWdS)z�Create text iterator.

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

        N)r r#�strr1�itertextr2)r+r �trHrrrr`�s		
	zElement.itertext)#rrrrr r)r1r2r-r/r0r'r5r;r=r>r?rArCrEr@rIrKrLrOrQrRrSrTrWrXrYr[r^r`rrrrrzs@	





		cKs<|j�}|j|�|j||�}|j|�|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.

    )r'r(r0rA)�parentr r)r,r"rrrr�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.

    )rrr1)r1r"rrrr�s		cCs3tt�}||_|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r1)�targetr1r"rrrr�s

	c@s�eZdZdZddd�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)r1)r+Ztext_or_urir rrrr-�szQName.__init__cCs|jS)N)r1)r+rrr�__str__�sz
QName.__str__cCsd|jj|jfS)Nz<%s %r>)r&rr1)r+rrrr/szQName.__repr__cCs
t|j�S)N)�hashr1)r+rrr�__hash__szQName.__hash__cCs,t|t�r|j|jkS|j|kS)N)r#r
r1)r+�otherrrr�__le__szQName.__le__cCs,t|t�r|j|jkS|j|kS)N)r#r
r1)r+rhrrr�__lt__	szQName.__lt__cCs,t|t�r|j|jkS|j|kS)N)r#r
r1)r+rhrrr�__ge__
szQName.__ge__cCs,t|t�r|j|jkS|j|kS)N)r#r
r1)r+rhrrr�__gt__szQName.__gt__cCs,t|t�r|j|jkS|j|kS)N)r#r
r1)r+rhrrr�__eq__szQName.__eq__)
rrrrr-rer/rgrirjrkrlrmrrrrr
�s
c@s�eZdZdZdddd�Zdd�Zdd�Zdd	d
�Zddd�Zdd
d�Z	ddd�Z
dddd�Zddd�Zddd�Z
dddddddd�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|j|�dS)N)�_rootr	)r+r"�filerrrr-(s	zElementTree.__init__cCs|jS)z!Return root element of this tree.)rn)r+rrr�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!

        N)rn)r+r"rrr�_setroot2szElementTree._setrootc
Cs�d}t|d�s*t|d�}d}z�|dkrjt�}t|d�rj|j|�|_|jSx'|jd�}|s�P|j|�qmW|j�|_|jSWd|r�|j�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!�openrrtrnrr�feed�close)r+�source�parser�close_source�datarrrr	<s&	zElementTree.parsecCs|jj|�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).

        )rnr[)r+r rrrr[as
zElementTree.itercCs)tjdtdd�t|j|��S)NzbThis method will be removed in future versions.  Use 'tree.iter()' or 'list(tree.iter())' instead.r6r7)r8r9r\r]r[)r+r rrrr^ns
zElementTree.getiteratorcCsM|dd�dkr:d|}tjd|tdd�|jj||�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�/�.z�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 %rr6r7)r8r9r:rnrL)r+rMrNrrrrLws

zElementTree.findcCsP|dd�dkr:d|}tjd|tdd�|jj|||�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}z�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 %rr6r7)r8r9r:rnrO)r+rMrPrNrrrrO�s

zElementTree.findtextcCsM|dd�dkr:d|}tjd|tdd�|jj||�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}z�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 %rr6r7)r8r9r:rnrQ)r+rMrNrrrrQ�s

zElementTree.findallcCsM|dd�dkr:d|}tjd|tdd�|jj||�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}z�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 %rr6r7)r8r9r:rnrR)r+rMrNrrrrR�s

zElementTree.iterfind�short_empty_elementsTcCs7|sd}n|tkr+td|��|sL|dkrFd}nd}|j�}t||���}|dkr�|s�|dkr�|dkr�|}	|dkr�ddl}
|
j�}	|d	|	f�|d
kr�t||j�n>t|j|�\}}t|}
|
||j||d|�WdQRXdS)
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�unicoderz$<?xml version='1.0' encoding='%s'?>
r1r~)r�r�r�)	�
_serialize�
ValueError�lower�_get_writer�locale�getpreferredencoding�_serialize_textrn�_namespaces)r+�file_or_filename�encodingZxml_declaration�default_namespace�methodr~Z	enc_lower�writeZdeclared_encodingr��qnamesrNZ	serializerrrr��s2		
zElementTree.writecCs|j|dd�S)Nr�r�)r�)r+rorrr�
write_c14n	szElementTree.write_c14n)rrrrr-rprqr	r[r^rLrOrQrRr�r�rrrrrs"

%
	5ccs|y
|j}Wnatk
rp|dkr;t|d�}nt|dd|dd�}|�
|jVWdQRXYnX|dkr�|Vn�tj���}t|tj�r�|}n�t|tj�r�tj	|�}|j
|j�nUtj�}dd�|_||_y|j
|_
|j|_Wntk
r7YnXtj|d|dddd	�}|j
|j�|jVWdQRXdS)
Nr��wr��errors�xmlcharrefreplacecSsdS)NTrrrrr�<lambda>2sz_get_writer.<locals>.<lambda>�newline�
)r��AttributeErrorru�
contextlib�	ExitStackr#�io�BufferedIOBase�	RawIOBase�BufferedWriter�callback�detach�writable�seekable�tell�
TextIOWrapper)r�r�r�ro�stackrrrr�s>

			
	r�cs�ddi�i��r"d��<���fdd�}xK|j�D]=}|j}t|t�r�|j�kr�||j�nVt|t�r�|�kr�||�n.|dk	r�|tk	r�|tk	r�t|�xs|j	�D]e\}}t|t�r|j}|�kr!||�t|t�r�|j�kr�||j�q�W|j}t|t�rG|j�krG||j�qGW��fS)N�csy�|dd�dkr�|dd�jdd�\}}�j|�}|dkr�tj|�}|dkr�dt��}|dkr�|�|<|r�d||f�|<q�|�|<n�r�td��|�|<Wntk
r�t|�YnXdS)Nr�{�}zns%drz%s:%sz<cannot use non-qualified names with default_namespace option)�rsplitrT�_namespace_mapr4r�r%�_raise_serialization_error)Zqname�urir �prefix)r�rNr�rr�	add_qnameOs&"

	
z_namespaces.<locals>.add_qname)
r[r r#r
r1r_rrr�rY)r3r�r�r rUrVr1r)r�rNr�rr�Ds4
	
$
	
	r�cKsJ|j}|j}|tkr/|d|�n�|tkrL|d|�n�||}|dkr�|rx|t|��x�|D]}t|||dd|�qWn�|d|�t|j��}	|	s�|r�|r0xVt|j�ddd��D]6\}
}|rd|}|d	|t	|
�f�q�Wxut|	�D]g\}}
t
|t�ra|j}t
|
t�r�||
j}
nt	|
�}
|d
|||
f�q=W|s�t|�s�|r |d�|r�|t|��x'|D]}t|||dd|�q�W|d|d�n
|d
�|j
rF|t|j
��dS)Nz	<!--%s-->z<?%s?>r~�<rUcSs|dS)Nrr)�xrrrr��sz _serialize_xml.<locals>.<lambda>�:z
 xmlns%s="%s"z %s="%s"�>z</z />)r r1rr�
_escape_cdata�_serialize_xmlr]rY�sorted�_escape_attribr#r
r4r2)r�r3r�rNr~�kwargsr r1rHrY�v�krrrr��sT		


	


	r�Zarea�baseZbasefontZbr�col�frameZhrZimg�inputZisindex�link�metaZparamcKsa|j}|j}|tkr5|dt|��n|tkrX|dt|��n�||}|dkr�|r�|t|��x�|D]}t|||d�q�Wn�|d|�t|j��}|s�|r�|r6xVt|j�ddd��D]6\}	}
|
rd|
}
|d|
t	|	�f�q�Wxut|�D]g\}
}	t
|
t�rg|
j}
t
|	t�r�||	j}	nt|	�}	|d	||
|	f�qCW|d
�|j
�}|r�|dks�|dkr�||�n|t|��x!|D]}t|||d�qW|tkrA|d
|d
�|jr]|t|j��dS)Nz	<!--%s-->z<?%s?>r�rUcSs|dS)Nrr)r�rrrr��sz!_serialize_html.<locals>.<lambda>r�z
 xmlns%s="%s"z %s="%s"r�ZscriptZstylez</)r r1rr�r�_serialize_htmlr]rYr�r�r#r
�_escape_attrib_htmlr��
HTML_EMPTYr2)r�r3r�rNr�r r1rHrYr�r�Zltagrrrr��sT		


	


	r�cCs;x|j�D]}||�q
W|jr7||j�dS)N)r`r2)r�r3�partrrrr��s	r�r�htmlr1cCsntjd|�rtd��x?ttj��D]+\}}||ksU||kr1t|=q1W|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�rY)r�r�r�r�rrrr�sz$http://www.w3.org/XML/1998/namespacezhttp://www.w3.org/1999/xhtmlz+http://www.w3.org/1999/02/22-rdf-syntax-ns#Zrdfz http://schemas.xmlsoap.org/wsdl/Zwsdlz http://www.w3.org/2001/XMLSchemaZxsz)http://www.w3.org/2001/XMLSchema-instanceZxsiz http://purl.org/dc/elements/1.1/ZdccCs#td|t|�jf��dS)Nzcannot serialize %r (type %s))r%rGr)r1rrrr�sr�cCs�ybd|kr!|jdd�}d|kr?|jdd�}d|kr]|jdd�}|SWn"ttfk
r�t|�YnXdS)N�&z&amp;r�z&lt;r�z&gt;)�replacer%r�r�)r1rrrr�#sr�cCs!y�d|kr!|jdd�}d|kr?|jdd�}d|kr]|jdd�}d|kr{|jdd�}d	|kr�|jd	d
�}d|kr�|jdd
�}d
|kr�|jd
d�}d
|kr�|jd
d�}|SWn"ttfk
rt|�YnXdS)Nr�z&amp;r�z&lt;r�z&gt;�"z&quot;z
r��
z&#10;�	z&#09;)r�r%r�r�)r1rrrr�3s(r�cCs�ybd|kr!|jdd�}d|kr?|jdd�}d|kr]|jdd�}|SWn"ttfk
r�t|�YnXdS)Nr�z&amp;r�z&gt;r�z&quot;)r�r%r�r�)r1rrrr�Osr�r~TcCsP|dkrtj�n	tj�}t|�j||d|d|�|j�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".

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

    r�r�r~)r��StringIO�BytesIOrr��getvalue)r"r�r�r~�streamrrrr^s$c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�_ListDataStreamz7An auxiliary stream accumulating into a list reference.cCs
||_dS)N)�lst)r+r�rrrr-ssz_ListDataStream.__init__cCsdS)NTr)r+rrrr�vsz_ListDataStream.writablecCsdS)NTr)r+rrrr�ysz_ListDataStream.seekablecCs|jj|�dS)N)r�rA)r+�brrrr�|sz_ListDataStream.writecCs
t|j�S)N)r4r�)r+rrrr�sz_ListDataStream.tellN)	rrrrr-r�r�r�r�rrrrr�qsr�cCs8g}t|�}t|�j||d|d|�|S)Nr�r~)r�rr�)r"r�r�r~r�r�rrrr�s
cCskt|t�st|�}|jtjdd�|j�j}|sW|ddkrgtjjd�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�rr�N���)r#rr��sys�stdoutrpr2)r3r2rrrr�scCst�}|j||�|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	)rxry�treerrrr	�s		cCscd}t|d�s*t|d�}d}yt||||�SWn|rW|j��YnXdS)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.

    FrrrsTN)r!ru�_IterParseIteratorrw)rx�eventsryrzrrrr�s
c@sUeZdZddddd�Zdd�Zdd�Zd	d
�Zdd�ZdS)
�
XMLPullParserN�_parsercCsYg|_d|_|p'tdt��|_|dkr?d}|jj|j|�dS)Nrrd�end)r�)�
_events_queue�_indexrrr��
_setevents)r+r�r�rrrr-�s		zXMLPullParser.__init__cCsq|jdkrtd��|rmy|jj|�Wn5tk
rl}z|jj|�WYdd}~XnXdS)zFeed encoded data to parser.Nz!feed() called after end of stream)r�r�rv�SyntaxErrorr�rA)r+r{�excrrrrv�szXMLPullParser.feedcCs|jj�}d|_|S)N)r�rw)r+�rootrrr�_close_and_return_root�s	z$XMLPullParser._close_and_return_rootcCs|j�dS)z�Finish feeding data to parser.

        Unlike XMLParser, does not return the root element. Use
        read_events() to consume elements from XMLPullParser.
        N)r�)r+rrrrw�szXMLPullParser.closeccs�|j}x�|j}y||j}d||j<Wntk
rHPYnX|d7}|dt|�kr�g|d|�<d|_n	||_t|t�r�|�q|VqWdS)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.
        Nrr7r)r�r��
IndexErrorr4r#�	Exception)r+r�r<�eventrrr�read_events�s 		


		zXMLPullParser.read_events)rrrr-rvr�rwr�rrrrr��s

r�c@s7eZdZddd�Zdd�Zdd�ZdS)	r�FcCs>td|d|�|_||_||_d|_|_dS)Nr�r�)r�r��_file�_close_filer�rn)r+rxr�ryrzrrrr-s		z_IterParseIterator.__init__c	Cs�y�xox|jj�D]}|SW|jjdkr4P|jjd�}|r_|jj|�q|jj�|_qW|j|_Wn!|jr�|jj	��YnX|jr�|jj	�t
�dS)N�ii@)r�r�r�rrrvr�rnr�r�rw�
StopIteration)r+r�r{rrr�__next__s$	
	
z_IterParseIterator.__next__cCs|S)Nr)r+rrr�__iter__/sz_IterParseIterator.__iter__N)rrrr-r�r�rrrrr�sr�cCs/|stdt��}|j|�|j�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.

    rd)rrrvrw)r1ryrrrr3s
cCsw|stdt��}|j|�|j�}i}x3|j�D]%}|jd�}|rD|||<qDW||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.

    rdr.)rrrvrwr[rT)r1ryr�Zidsr3r.rrrrDs

cCs@|stdt��}x|D]}|j|�qW|j�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.

    rd)rrrvrw)Zsequenceryr1rrrr\s
	
c@saeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)ra�Generic 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.

    NcCsCg|_g|_d|_d|_|dkr6t}||_dS)N)�_data�_elem�_last�_tailr�_factory)r+Zelement_factoryrrrr-{s				zTreeBuilder.__init__cCsCt|j�dks!td��|jdk	s<td��|jS)z;Flush builder buffers and return toplevel document Element.rzmissing end tagsNzmissing toplevel element)r4r��AssertionErrorr�)r+rrrrw�s!zTreeBuilder.closecCs�|jr�|jdk	r�dj|j�}|jr`|jjdksQtd��||j_n*|jjdks~td��||j_g|_dS)Nr�zinternal error (tail)zinternal error (text))r�r��joinr�r2r�r1)r+r1rrr�_flush�s		zTreeBuilder._flushcCs|jj|�dS)zAdd text to current element.N)r�rA)r+r{rrrr{�szTreeBuilder.datacCs]|j�|j||�|_}|jr@|jdj|�|jj|�d|_|S)z�Open new element and return it.

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

        rrr�)r�r�r�r�rAr�)r+r Zattrsr3rrr�start�s
		zTreeBuilder.startcCsZ|j�|jj�|_|jj|ksJtd|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��popr�r r�r�)r+r rrrr��s
	zTreeBuilder.end)
rrrrr-rwr�r{r�r�rrrrrns	c@s�eZdZdZddddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZeZdd�Z
dd�ZdS)ra�Element structure builder for XML source data based on the expat parser.

    *html* are predefined HTML entities (deprecated and not supported),
    *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

    rNcCs�yddlm}WnCtk
rYyddl}Wntk
rTtd��YnXYnX|j|d�}|dkr�t�}||_|_||_|_	|j
|_i|_|j
|_t|d�r�|j|_t|d�r�|j|_t|d�r|j|_t|d�r.|j|_t|d	�rI|j|_d
|_d
|_d
|_d|_i|_yd|j|_ Wnt!k
r�YnXdS)Nr)�expatz7No module named expat; use SimpleXMLTreeBuilder insteadr�r�r�r{�comment�pirzExpat %d.%d.%d)"�xml.parsersr��ImportErrorZpyexpatZParserCreaterryr�rd�_target�error�_error�_names�_defaultZDefaultHandlerExpandr!�_start�StartElementHandler�_end�EndElementHandlerr{ZCharacterDataHandlerr�ZCommentHandlerr�ZProcessingInstructionHandlerZbuffer_text�ordered_attributes�specified_attributes�_doctype�entity�version_info�versionr�)r+r�rdr�r�ryrrrr-�sF

							
zXMLParser.__init__cCs�|j}|j}x�|D]�}|dkrad|_d|_|||jdd�}||_q|dkr�|||jdd�}||_q|dkr�||dd�}||_q|d	kr�||d
d�}||_	qt
d|��qWdS)Nr�rcSs|||||�f�dS)Nr)r Z	attrib_inr�rAr�rrr�handler�sz%XMLParser._setevents.<locals>.handlerr�cSs||||�f�dS)Nr)r r�rAr�rrrrszstart-nscSs&|||pd|pdff�dS)Nr�r)r�r�r�rArrrrszend-nscSs||df�dS)Nr)r�r�rArrrr	szunknown event %r)r�rArrrrrrZStartNamespaceDeclHandlerZEndNamespaceDeclHandlerr�)r+Zevents_queueZevents_to_reportryrAZ
event_namerrrrr��s(		
		zXMLParser._seteventscCs7t|�}|j|_|j|jf|_|�dS)N)r
�code�lineno�offsetZposition)r+rV�errrrr�_raiseerrorszXMLParser._raiseerrorcCsSy|j|}Wn;tk
rN|}d|kr=d|}||j|<YnX|S)Nr�r�)r�KeyError)r+rU�namerrr�_fixnames

zXMLParser._fixnamecCss|j}||�}i}|r`x<tdt|�d�D]"}||d||||�<q:W|jj||�S)Nrr7r)r�ranger4rdr�)r+r Z	attr_listZfixnamer)�irrrr s	 zXMLParser._startcCs|jj|j|��S)N)rdr�r)r+r rrrr,szXMLParser._endcCs�|dd�}|dkr�y|jj}Wntk
rDdSYnXy||j|dd��Wq�tk
r�ddlm}|jd||jj	|jj
f�}d|_|jj	|_|jj
|_
|�Yq�Xn�|dkr|dd�d	krg|_n}|jdk	r�|d
kr7d|_dS|j�}|sMdS|jj|�t|j�}|dkr�|jd}|dkr�|d
kr�|j\}}}	}
|	r|	dd�}	n7|dkr�|dkr�|j\}}}
d}	ndSt|jd�r7|jj||	|
dd��nL|j|jkr�|j||	|
dd��|j||	|
dd��d|_dS)Nrr�r)r�z'undefined entity %s: line %d, column %d�r��	z	<!DOCTYPEr�r7ZPUBLIC�ZSYSTEM��doctyper�r�r�r�r�)rdr{r�r	rr�r�r�ryZErrorLineNumberZErrorColumnNumberr
rrr�striprAr4r!r�_XMLParser__doctype)r+r1r�Zdata_handlerr�r�nrGr�pubid�systemrrrr/sZ
	
	"	
	#zXMLParser._defaultcCstjdt�dS)z�(Deprecated)  Handle doctype declaration

        *name* is the Doctype name, *pubid* is the public identifier,
        and *system* is the system identifier.

        z[This method of XMLParser is deprecated.  Define doctype() method on the TreeBuilder target.N)r8r9rJ)r+rrr rrrrcszXMLParser.doctypecCsSy|jj|d�Wn5|jk
rN}z|j|�WYdd}~XnXdS)zFeed encoded data to parser.rN)ry�Parser�r)r+r{r�rrrrvsszXMLParser.feedcCs�y|jjdd�Wn5|jk
rN}z|j|�WYdd}~XnXz0y|jj}Wntk
rvYnX|�SWd|`|`|`|`XdS)z;Finish feeding data to parser and return element structure.r�rN)	ryr!r�rrdrwr�r�r�)r+r�Z
close_handlerrrrrwzs 
zXMLParser.close)rrrrr-r�rrrrrrrrvrwrrrrr�s	*!4)rZ)6r�__all__rr�r�r8r�r�r�rr�r
rrrrrrr
r�contextmanagerr�r�r�r�rW�	NameErrorr�r�r�rr�r�r�r�r�rr�r�rrr	rr�r�rrrrrrrFZ_elementtreer�rrrr�<module>"s�)	�@0�4=2
2			E$K�