%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/xml/etree/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/xml/etree/__pycache__/ElementTree.cpython-38.pyc

U

qa@sdZddddddddd	d
ddd
ddddddddddddgZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZGdd
d
eZ
d dZGd!ddZifd"dZd]d#dZd^d$dZeZGd%d
d
ZGd&ddZe	jd'd(Zd_d)d*Zd+d,Zd-ZzeeZWnek
r.YnXd.d/Zd0d1Zeeed2Zd3dZ d4d5d6d7d8d9d:d;Z!e!e _!d<d=Z"d>d?Z#d@dAZ$dBdCZ%d`dddDdEdFdZ&GdGdHdHej'Z(dadddDdEdIdZ)dJdZ*dbdKd	Z+dcdLdZ,GdMddZ-dddNdZ.dedOdZ/e.Z0dfdPdZ1GdQddZ2GdRddZ3dgdddSdTdZ4e5dUej6j7Z8GdVddZ9dWdXZ:dYdZZ;zeZ<dd[l=Tdd\l=m>Z>Wne?k
rYnXe>eedS)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.

CommentdumpElementElementTree
fromstringfromstringlist	iselement	iterparseparse
ParseErrorPIProcessingInstructionQName
SubElementtostringtostringlistTreeBuilderVERSIONXMLXMLID	XMLParser
XMLPullParserregister_namespacecanonicalizeC14NWriterTargetz1.3.0N)ElementPathc@seZdZdZdS)r
zAn 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!1/usr/local/lib/python3.8/xml/etree/ElementTree.pyr
jscCs
t|dS)z2Return True if *element* appears to be an Element.tag)hasattr)elementr!r!r"rxsc@s
eZdZdZdZdZdZdZifddZddZ	ddZ
d	d
ZddZd
dZ
ddZddZddZddZddZddZddZddZdd Zd9d!d"Zd:d#d$Zd;d%d&Zd<d'd(Zd)d*Zd=d+d,Zd-d.Zd/d0Zd1d2Zd>d3d4Z d?d5d6Z!d7d8Z"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|tstd|jjf||_|||_g|_dS)Nzattrib must be dict, not %s)
isinstancedict	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#idr,r!r!r"__repr__szElement.__repr__cCs|||S)zCreate 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"makeelements	zElement.makeelementcCs0||j|j}|j|_|j|_||dd<|S)zReturn copy of current element.

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

        N)r2r#r*texttail)r,elemr!r!r"copys
zElement.copycCs
t|jSN)lenr+r0r!r!r"__len__szElement.__len__cCstjdtddt|jdkS)NzyThe behavior of this method will change in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.
stacklevelr)warningswarn
FutureWarningr8r+r0r!r!r"__bool__szElement.__bool__cCs
|j|Sr7r+r,indexr!r!r"__getitem__szElement.__getitem__cCs8t|tr |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.

        NrFr+appendr,
subelementr!r!r"rJs
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"extends
zElement.extendcCs|||j||dS)z(Insert *subelement* at position *index*.N)rFr+insert)r,rCrLr!r!r"rOs
zElement.insertcCs t|tstdt|jdS)Nzexpected an Element, not %s)r&_Element_Pyr(typer)r,er!r!r"rFs
zElement._assert_is_elementcCs|j|dS)aRemove 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.

        )rfindr,path
namespacesr!r!r"rV!s	zElement.findcCst||||S)aFind 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.

        )rfindtextr,rXdefaultrYr!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.

        )rfindallrWr!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.

        )riterfindrWr!r!r"r^Es	zElement.iterfindcCs |jg|_d|_|_dS)zReset 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)zSet 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,ravaluer!r!r"sethszElement.setcCs
|jS)zGet 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
|jS)zGet 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"rgs
zElement.itercCstjdtddt||S)NzbThis method will be removed in future versions.  Use 'elem.iter()' or 'list(elem.iter())' instead.r:r;r=r>rTlistrgr,r#r!r!r"getiteratorszElement.getiteratorccsX|j}t|ts|dk	rdS|j}|r,|V|D]"}|EdH|j}|r0|Vq0dS)zCreate text iterator.

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

        N)r#r&strr3itertextr4)r,r#trRr!r!r"rmszElement.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)aSubelement 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"rs
cCstt}||_|S)zComment 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"rs	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@sZeZdZdZdddZddZddZd	d
ZddZd
dZ	ddZ
ddZddZdS)r
aQualified 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}%sr3)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|jSr7)hashr3r0r!r!r"__hash__szQName.__hash__cCs t|tr|j|jkS|j|kSr7r&r
r3r,otherr!r!r"__le__s
zQName.__le__cCs t|tr|j|jkS|j|kSr7rvrwr!r!r"__lt__s
zQName.__lt__cCs t|tr|j|jkS|j|kSr7rvrwr!r!r"__ge__s
zQName.__ge__cCs t|tr|j|jkS|j|kSr7rvrwr!r!r"__gt__s
zQName.__gt__cCs t|tr|j|jkS|j|kSr7rvrwr!r!r"__eq__s
zQName.__eq__)N)
rrrr r.rsr1ruryrzr{r|r}r!r!r!r"r
s
c@seZdZdZdddZddZddZdd	d
ZdddZd d
dZ	d!ddZ
d"ddZd#ddZd$ddZ
d%ddddZddZdS)&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)zReplace 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._setrootcCsd}t|dst|d}d}z^|dkrLt}t|drL|||_|jW2S|d}|s\qh||qL||_|jWS|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.

        FreadrbTN_parse_wholei)r$opencloserrr~rfeed)r,sourceparserclose_sourcedatar!r!r"r	;s$






zElementTree.parsecCs|j|S)zCreate 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.itercCstjdtddt||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:|dddkr,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<|dddkr,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.

        Nrrrrr:r;)r=r>r?r~rZr[r!r!r"rZszElementTree.findtextcCs:|dddkr,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.

        Nrrrrr:r;)r=r>r?r~r]rWr!r!r"r]szElementTree.findallcCs:|dddkr,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.

        Nrrrrr:r;)r=r>r?r~r^rWr!r!r"r^szElementTree.iterfindTshort_empty_elementsc	Cs|s
d}n|tkrtd||s4|dkr0d}nd}|}t||}|dkr|sd|dkr|dkr|}	|dkrd	dl}
|
}	|d
|	f|dkrt||jn,t|j|\}}t|}
|
||j|||dW5QRXdS)
aWrite 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 %rc14nutf-8us-asciiN)rrunicoderrz$<?xml version='1.0' encoding='%s'?>
r3r)	
_serialize
ValueErrorlower_get_writerlocalegetpreferredencoding_serialize_textr~_namespaces)r,file_or_filenameencodingxml_declarationdefault_namespacemethodrZ	enc_lowerwriteZdeclared_encodingrqnamesrYZ	serializer!r!r"rs:zElementTree.writecCs|j|ddS)Nr)r)r)r,rr!r!r"
write_c14nszElementTree.write_c14n)NN)N)N)N)N)NN)N)N)NNNN)rrrr r.rrr	rgrkrVrZr]r^rrr!r!r!r"rs&



%





:ccs"z
|j}WnPtk
rZ|dkr.t|d}nt|d|dd}||jVW5QRXYnX|dkrl|Vnt}t|tjr|}nft|tjrt	|}|
|jnBt}dd|_||_z|j
|_
|j|_Wntk
rYnXtj||ddd}|
|j|jVW5QRXdS)	Nrwxmlcharrefreplace)rerrorscSsdSNTr!r!r!r!r"<lambda>0z_get_writer.<locals>.<lambda>
)rrnewline)rAttributeErrorr
contextlib	ExitStackr&ioBufferedIOBase	RawIOBaseBufferedWritercallbackdetachwritableseekabletell
TextIOWrapper)rrrrstackr!r!r"rsB



rcsddiird<fdd}|D]}|j}t|trZ|jkr||jn<t|trv|kr||n |dk	r|tk	r|tk	rt||	D]F\}}t|tr|j}|kr||t|tr|jkr||jq|j}t|tr0|jkr0||jq0fS)Ncsz|dddkr|dddd\}}|}|dkrjt|}|dkrZdt}|dkrj||<|rd||f|<q||<nrtd||<Wntk
rt|YnXdS)Nr{}zns%drz%s:%sz<cannot use non-qualified names with default_namespace option)rsplitr`_namespace_mapr8rr(_raise_serialization_error)qnameurir#prefixrrYrr!r"	add_qnameMs(


z_namespaces.<locals>.add_qname)
rgr#r&r
r3rlrrrre)r5rrr#rarbr3r!rr"rBs4




rcKs|j}|j}|tkr$|d|nv|tkr<|d|n^||}|dkr||r\|t||D]}t|||d|dq`n|d|t|}	|	s|r2|rt|dddD](\}
}|rd|}|d	|t	|
fq|	D]L\}}
t
|tr|j}t
|
tr||
j}
nt	|
}
|d
|||
fq|sHt|sH|s|d|rb|t||D]}t|||d|dqf|d|dn|d
|j
r|t|j
dS)N	<!--%s--><?%s?>r<cSs|dSNrr!xr!r!r"rrz _serialize_xml.<locals>.<lambda>ra:
 xmlns%s="%s" %s="%s"></z />)r#r3rr
_escape_cdata_serialize_xmlriresorted_escape_attribr&r
r8r4)rr5rrYrkwargsr#r3rRrevkr!r!r"rs\





r)
ZareabaseZbasefontbrcolframehrZimginputZisindexlinkmetaZparamcKs|j}|j}|tkr(|dt|n|tkrD|dt|nh||}|dkr|rd|t||D]}t|||dqhn,|d|t|}|s|r8|rt|dddD](\}	}
|
rd|
}
|d|
t	|	fq|D]N\}
}	t
|
tr|
j}
t
|	tr||	j}	nt|	}	|d	||
|	fq|d
|
}|rx|dksb|dkrl||n|t||D]}t|||dq||tkr|d
|d
|jr|t|jdS)NrrrcSs|dSrr!rr!r!r"rrz!_serialize_html.<locals>.<lambda>rrrrrZscriptstyler)r#r3rrr_serialize_htmlrirerrr&r
_escape_attrib_htmlr
HTML_EMPTYr4)rr5rrYrr#r3rRrerrZltagr!r!r"rsX



rcCs*|D]}||q|jr&||jdSr7)rmr4)rr5partr!r!r"rs
r)rhtmlr3cCsLtd|rtdttD]\}}||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)rematchrrirre)rrrrr!r!r"rsrrZrdfZwsdlZxsZxsiZdc)$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|jfdS)Nzcannot serialize %r (type %s))r(rQrrrr!r!r"rsrc	CshzBd|kr|dd}d|kr*|dd}d|kr>|dd}|WSttfk
rbt|YnXdS)N&&amp;r&lt;r&gt;replacer(rrrrr!r!r"r!src	Cszd|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
rt|YnXdS)Nrrrrrr"&quot;z
r
z&#10;	z&#09;rrrr!r!r"r1s(rc	CshzBd|kr|dd}d|kr*|dd}d|kr>|dd}|WSttfk
rbt|YnXdS)Nrrrrrrrrrr!r!r"rMsrT)rrrcCs:|dkrtnt}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.

    rrrrr)rStringIOBytesIOrrgetvalue)r%rrrrrstreamr!r!r"r\sc@s8eZdZdZddZddZddZdd	Zd
dZdS)
_ListDataStreamz7An auxiliary stream accumulating into a list reference.cCs
||_dSr7)lst)r,rr!r!r"r.vsz_ListDataStream.__init__cCsdSrr!r0r!r!r"rysz_ListDataStream.writablecCsdSrr!r0r!r!r"r|sz_ListDataStream.seekablecCs|j|dSr7)rrJ)r,br!r!r"rsz_ListDataStream.writecCs
t|jSr7)r8rr0r!r!r"rsz_ListDataStream.tellN)	rrrr r.rrrrr!r!r!r"rtsrcCs*g}t|}t|j||||||d|S)Nr)rrr)r%rrrrrrrr!r!r"rscCsLt|tst|}|jtjdd|j}|r<|ddkrHtjddS)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)rrN)r&rrsysstdoutrr4)r5r4r!r!r"rs

cCst}||||S)zParse 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	)rrtreer!r!r"r	s	csft||dfddGfdddtjj}|d_~dtdsbtd	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^zJEdHd}|s q,|q}EdH|_W5rXXdS)Ni@)rread_eventsrr_close_and_return_rootroot)rr)rit
pullparserrr!r"iterators

ziterparse.<locals>.iteratorcseZdZjZdS)z$iterparse.<locals>.IterParseIteratorN)rrr__next__r!)r	r!r"IterParseIteratorsrNFrrT)rcollectionsabcIteratorrr$r)rrrrr!)rrr	rrr"rs

c@s<eZdZd
ddddZddZddZd	d
ZddZdS)rN)rcCs<t|_|pttd|_|dkr(d}|j|j|dS)Nrq)end)rdeque
_events_queuerrr
_setevents)r,rrr!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)rrrSyntaxErrorrrJ)r,rexcr!r!r"rs
zXMLPullParser.feedcCs|j}d|_|Sr7)rr)r,rr!r!r"rs
z$XMLPullParser._close_and_return_rootcCs|dS)zFinish feeding data to parser.

        Unlike XMLParser, does not return the root element. Use
        read_events() to consume elements from XMLPullParser.
        N)rr0r!r!r"rszXMLPullParser.closeccs.|j}|r*|}t|tr"|q|VqdS)zReturn an iterator over currently available (event, elem) pairs.

        Events are consumed from the internal event queue as they are
        retrieved from the iterator.
        N)rpopleftr&	Exception)r,reventr!r!r"rs
zXMLPullParser.read_events)N)rrrr.rrrrr!r!r!r"rs

cCs"|sttd}|||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.

    rrrrr)r3rr!r!r"rs
cCsR|sttd}|||}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.

    rr/)rrrrrgr`)r3rrZidsr5r/r!r!r"r,s



cCs,|sttd}|D]}||q|S)zParse 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.

    rr)Zsequencerr3r!r!r"rDs
	c@sheZdZdZddddddddZddZd	d
ZddZd
dZddZ	ddZ
dddZddZ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_factoryinsert_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|jdkstd|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)Nrzinternal error (tail)zinternal error (text))rr!joinr"r4r&r3r,r3r!r!r"_flushs

zTreeBuilder._flushcCs|j|dS)zAdd text to current element.N)rrJr,rr!r!r"rszTreeBuilder.datacCsX|||||_}|jr2|jd|n|jdkrB||_|j|d|_|S)zOpen new element and return it.

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

        rNr)r)r%r!r rJr~r")r,r#attrsr5r!r!r"starts
zTreeBuilder.startcCs@||j|_|jj|ks4td|jj|fd|_|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"rjr!r!r"rs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"comments
zTreeBuilder.commentcCs||j|j||S)zCreate 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"piszTreeBuilder.picGs:||}|r6|||_|jr0|jd|d|_|S)Nrr)r)r!r rJr")r,factoryrOargsr5r!r!r"r.szTreeBuilder._handle_single)N)N)
rrrr r.rr)rr,rr/r0r.r!r!r!r"rVs
	c@speZdZdZdddddZddZdd	Zd
dZdd
ZddZ	ddZ
ddZddZddZ
ddZdS)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)rqrcCsdzddlm}Wn>tk
rNzddl}Wntk
rHtdYnXYnX||d}|dkrjt}||_|_||_|_	|j
|_i|_|j
|_t|dr|j|_t|dr|j|_t|dr|j|_t|dr|j|_t|d	r|j|_t|d
r|j|_t|dr|j|_d|_d|_d|_ d|_!i|_"zd
|j#|_$Wnt%k
r^YnXdS)Nrexpatz7No module named expat; use SimpleXMLTreeBuilder insteadrr,rstart_nsend_nsrr/r0rzExpat %d.%d.%d)&xml.parsersr4ImportErrorZpyexpatZParserCreaterrrrq_targeterror_error_names_defaultZDefaultHandlerExpandr$_startStartElementHandler_endEndElementHandler	_start_nsStartNamespaceDeclHandler_end_nsEndNamespaceDeclHandlerrZCharacterDataHandlerr/CommentHandlerr0ProcessingInstructionHandlerZbuffer_textordered_attributesspecified_attributes_doctypeentityversion_infoversionr)r,rqrr4rr!r!r"r.sP




zXMLParser.__init__cCs8|j}|j}|D] }|dkrDd|_d|_|||jfdd}||_q|dkrf|||jfdd}||_q|dkrt|j	dr|||j
fd	d}n||fd
d}||_q|dkrt|j	dr|||jfd
d}n||fdd}||_
q|dkr|||fdd}||_q|dkr&|||fdd}||_qtd|qdS)Nr,rcSs|||||fdSr7r!)r#Z	attrib_inrrJr,r!r!r"handlersz%XMLParser._setevents.<locals>.handlerrcSs||||fdSr7r!)r#rrJrr!r!r"rNszstart-nsr5cSs|||||fdSr7r!)rrrrJr5r!r!r"rN!scSs|||p
d|pdffdSNrr!)rrrrJr!r!r"rN%szend-nsr6cSs||||fdSr7r!)rrrJr6r!r!r"rN+scSs||dfdSr7r!)rrrJr!r!r"rN/sr/cSs|||j|fdSr7)rqr/)r3rrJr,r!r!r"rN3sr0cSs|||j||fdSr7)rqr0)Z	pi_targetrrrJr,r!r!r"rN7szunknown event %r)rrJrHrIr>r?r@rAr$rqrBrCrDrErFrGr)r,Zevents_queueZevents_to_reportrrJZ
event_namerNr!r!r"rsL





zXMLParser._seteventscCs&t|}|j|_|j|jf|_|dSr7)r
codelinenooffsetZposition)r,rberrr!r!r"_raiseerror>szXMLParser._raiseerrorcCsFz|j|}Wn2tk
r@|}d|kr2d|}||j|<YnX|S)Nrr)r<KeyError)r,ranamer!r!r"_fixnameDszXMLParser._fixnamecCs|j|pd|pdSrO)rqr5r,rrr!r!r"rBOszXMLParser._start_nscCs|j|pdSrO)rqr6)r,rr!r!r"rDRszXMLParser._end_nscCsR|j}||}i}|rDtdt|dD]}||d||||<q&|j||S)Nrr:r)rWranger8rqr,)r,r#	attr_listZfixnamer*ir!r!r"r>UszXMLParser._startcCs|j||Sr7)rqrrWrjr!r!r"r@aszXMLParser._endc	Cs|dd}|dkrz|jj}Wntk
r6YdSXz||j|ddWnZtk
rddlm}|d||jj	|jj
f}d|_|jj	|_|jj
|_
|YnXn"|dkr|dd	d
krg|_n|jdk	r|dkrd|_dS|}|sdS|j|t|j}|dkr|jd}|d
krd|dkrd|j\}}}	}
|	r|	dd}	n*|dkr|dkr|j\}}}
d}	ndSt|jdr|j||	|
ddnt|drtdtd|_dS)Nrrrrr3z'undefined entity %s: line %d, column %dr	z	<!DOCTYPErr:ZPUBLICZSYSTEMdoctypezaThe doctype() method of XMLParser is ignored.  Define doctype() method on the TreeBuilder target.)rqrrrKrUr7r4r:rZErrorLineNumberZErrorColumnNumberrPrQrRrJstriprJr8r$r`r=r>RuntimeWarning)r,r3rZdata_handlerr4rSnrQrVZpubidsystemr!r!r"r=dsd





zXMLParser._defaultc
CsFz|j|dWn.|jk
r@}z||W5d}~XYnXdS)rrN)rParser;rT)r,rrr!r!r"rszXMLParser.feedc
Csz|jddWn.|jk
r@}z||W5d}~XYnXz0z|jj}Wntk
rdYnX|WSW5|`|`|`|`XdS)z;Finish feeding data to parser and return element structure.rrN)	rrer;rTrrqr9rr)r,rZ
close_handlerr!r!r"rszXMLParser.close)rrrr r.rrTrWrBrDr>r@r=rrr!r!r!r"rs	.66)out	from_filecKs|dkr|dkrtdd}|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)
rrrrrrrrr	r)Zxml_datarfrgoptionssiorr!r!r"rs


z	^\w+:\w+$c@seZdZdZddddddddddZefddZd	d
ZdddZd
dZ	dj
fddZddZddZ
dddZddZddZddZdS) 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_textrewrite_prefixesqname_aware_tagsqname_aware_attrs
exclude_attrsexclude_tagsc	Cs||_g|_||_||_|r$t|nd|_|r6t|nd|_||_|rRt||_nd|_|rjt|j	|_
nd|_
dgg|_g|_|s|j
tt|j
gi|_dg|_d|_d|_d|_d|_dS)N)rrFr)_writer_with_comments_strip_textrc_exclude_attrs
_exclude_tags_rewrite_prefixes_qname_aware_tagsintersection_find_qname_aware_attrs_declared_ns_stack	_ns_stackrJrirre_prefix_map_preserve_space_pending_start
_root_seen
_root_done_ignored_depth)	r,rrjrkrlrmrnrorpr!r!r"r.s2zC14NWriterTarget.__init__ccs ||D]}|r|EdHqdSr7r!)r,Zns_stackZ	_reversedrYr!r!r"_iter_namespacessz!C14NWriterTarget._iter_namespacescCs\|dd\}}||jD]$\}}||krd|d|Sqtd|d|ddS)NrrrrzPrefix z of QName "" is not declared in scope)splitrr{r)r,Z
prefixed_namerrVrpr!r!r"_resolve_prefix_names
z%C14NWriterTarget._resolve_prefix_namecCs|dkr:|dddkr,|ddddnd|f\}}n|}t}||jD]B\}}||kr||kr|rz|d|n|||fS||qP|jr||jkr|j|}ndt|j}|j|<|jd||f|d|||fS|sd|kr|||fS||j	D]J\}}||kr|jd||f|rR|d|n|||fSq|st|||fSt
d|d	dS)
NrrrrrrcrzNamespace "r)rrcrrzaddrvr|r8rJr{r)r,rrr#Z
prefixes_seenurr!r!r"_qnames.2 


&
zC14NWriterTarget._qnamecCs|js|j|dSr7)rrrJr*r!r!r"rCszC14NWriterTarget.datarcCs||j}|jdd=|jr.|jds.|}|jdk	rv|jd}|_|rVt|rV|nd}|j||f|dk	rvdS|r|jr|t	|dSNr)
rrsr}rar~_looks_like_prefix_namer>rrq_escape_cdata_c14n)r,Z
_join_textrr2
qname_textr!r!r"r)Gs


zC14NWriterTarget._flushcCs0|jr
dS|jr||jd||fdSr)rrr)r{rJrXr!r!r"r5Us
zC14NWriterTarget.start_nscCs|jdk	r,|js||jkr,|jd7_dS|jr:|g}|j||jdk	rn||jkrn|||f|_dS||||dSr)	rurrr)rzrJrwr~r>)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|
}||
<||qvqd}nd}jfddt|dddD}|rdd|D}|ng}|rjt|D]^\}
}|dk	r@|
|kr@||kr@|||d	}||
\}}	}|	|r\|n|	|fq
|
d
}j	|r|dknjdj}|d
||d	|r|d
dd|D|d|dk	r|t|||d	d_j	gdS)Ncs i|]\}}|jkr||qSr!)rt.0rrr0r!r"
<dictcomp>ps
z+C14NWriterTarget._start.<locals>.<dictcomp>csi|]}||qSr!r!)rrc)parse_qnamer!r"rscSs|ddS)Nrr)r)rcr!r!r"rrz)C14NWriterTarget._start.<locals>.<lambda>rcSs$g|]\}}|rd|nd|fqS)zxmlns:Zxmlnsr!)rrrr!r!r"
<listcomp>sz+C14NWriterTarget._start.<locals>.<listcomp>rz+{http://www.w3.org/XML/1998/namespace}spaceZpreserverrrcSs&g|]\}}d|dt|dqS)rpz="r)_escape_attrib_c14nrr!r!r"rsrT)rtrerrryrrrsortrJr`r}rqr'rrr{)r,r#r+rrrZresolved_namesrZqattrsZ	attr_namerbZ
parsed_qnamesrZrrZ
attr_qnamerZspace_behaviourrr!)rr,r"r>ns`






zC14NWriterTarget._startcCst|jr|jd8_dS|jr&||d||dd|jt|jdk|_|j	|j
dS)Nrrrr)rrr)rqrr}r-r8rrzr{rjr!r!r"rs

zC14NWriterTarget.endcCsd|js
dS|jrdS|jr&|dn|jr:|jr:||dt|d|js`|ddS)Nrz<!--z-->)rrrrrqrrr)rr(r!r!r"r/szC14NWriterTarget.commentcCsp|jr
dS|jr|dn|jr0|jr0|||rNd|dt|dn
d|d|jsl|ddS)Nrz<?rpz?>)rrrqrrr)r)r,rqrr!r!r"r0s$zC14NWriterTarget.pi)N)N)rrrr r.reversedrrrrr'r)r5r,r>rr/r0r!r!r!r"rs(%
%
E
c	Cs|zVd|kr|dd}d|kr*|dd}d|kr>|dd}d|krR|dd}|WSttfk
rvt|YnXdS)	Nrrrrrrr&#xD;rrrr!r!r"rsrc	Csz~d|kr|dd}d|kr*|dd}d|kr>|dd}d|krR|dd}d	|krf|d	d
}d|krz|dd}|WSttfk
rt|YnXdS)
Nrrrrrrrz&#x9;rz&#xA;rrrrrr!r!r"rs r)rf)_set_factories)N)N)N)NN)NN)N)NN)N)N)N)N)@r __all__rrrr=rrcollections.abcrrrrr
rrrrrrr
rcontextmanagerrrrrrc	NameErrorrrrrrrrrrrrrrrr	rrrrrrrrrcompileUNICODErrrrrrP_elementtreerr8r!r!r!r"<module>sJ>

0s
3
=22	



05


zg

Zerion Mini Shell 1.0