U e5dÙã@s²dZddddddddd d d d d ddddddddddddgZdZddlZddlZddlZddlZddlZddlZddl Z ddl m Z Gdd „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 _!dd?„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;zeZZ>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 „Z d d „Z d d„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd9d!d"„Zd:d#d$„Zd;d%d&„Zdd3d4„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: text...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`[s z Element.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"Úsethsz Element.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 „Zd d „Zd d„Z dd„Z dd„Z dd„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,Z text_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 „Zdd d „Zd d d„Z d!dd„Z d"dd„Z d#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ƒ|d kr¤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$ 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"Ú0óz_get_writer..Ú )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.add_qname) rgr#r&r r3rlrr rÁ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ú úr�ú.©raú:ú xmlns%s="%s"ú %s="%s"ú>ú)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| d k�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..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ú&ú&rÉú<rÑú>©Ú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| d d ¡}d |krŽ| d d ¡}d |kr¢| d d¡}|WSttfk rÆt|ƒYnXdS)NrérêrÉrërÑrìú"ú"z r¬ú z ú z 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..iteratorcseZdZ”ƒjZdS)z$iterparse..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 „Zd d „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 „Zd d „Zd d„Zdd„Z dd„Z ddd„Z dd„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|jS)z;Flush builder buffers and return toplevel document Element.r€r0r!r!r"r‡~szTreeBuilder.closecCs>|jr:|jdk r4d |j¡}|jr,||j_n||j_g|_dS©Nr¼)rrÚjoinrr4r3©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 ¡|_d|_|jS)zOClose and return current Element. *tag* is the element name. r)r&rÚpoprrrjr!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„Z dd„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Ÿc Csdzddlm}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-ÚProcessingInstructionHandlerZ buffer_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|d krâ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..handlerr cSs||||ƒfƒdSr7r!)r#rrJr r!r!r"rKszstart-nsr2cSs|||||ƒfƒdSr7r!)rÄrÃrrJr2r!r!r"rK!scSs|||p d|pdffƒdSr#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¡Sr#)rqr2©r,rÄrÃr!r!r"r?OszXMLParser._start_nscCs|j |p d¡Sr#)rqr3)r,rÄr!r!r"rARszXMLParser._end_nscCsR|j}||ƒ}i}|rDtdt|ƒdƒD]}||d||||ƒ<q&|j ||¡S)Nrr:r)rSÚranger8rqr))r,r#Ú attr_listZfixnamer*Úir!r!r"r;UszXMLParser._startcCs|j | |¡¡Sr7)rqr rSrjr!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Ô|d krò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 ÚRuntimeWarning) r,r3rÄZ data_handlerr1rOÚnrQrRZpubidÚsystemr!r!r"r:dsd   ÿÿÿ          ýzXMLParser._defaultc CsFz|j |d¡Wn.|jk r@}z| |¡W5d}~XYnXdS)rrN)rŠÚParser8rP)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Šrar8rPrrqr6r‡r®)r,rØZ close_handlerr!r!r"r‡¡s zXMLParser.close)rrrr r.rrPrSr?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_datarbrcZoptionsZsiorŠr!r!r"r¶s     z ^\w+:\w+$c@s�eZdZdZddddddddœdd„Zefdd„Zd d „Zdd d „Zd d„Z dj fdd„Z dd„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£rdrerfrgrhrirjr!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|rur˜)r,Z prefixed_namerÄrRrÃÚ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ûz Namespace "r}) r¿rcr|rtÚaddrprvr8rJrur˜)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û) rrmrwr]rxÚ_looks_like_prefix_namer;ryrkÚ_escape_cdata_c14n)r,Z _join_textrŒr/Ú qname_textr!r!r"r&Gs    zC14NWriterTarget._flushcCs0|jr dS|jr| ¡|jd ||f¡dSr„)r{rr&rurJrTr!r!r"r2Us zC14NWriterTarget.start_nscCs€|jdk r,|js||jkr,|jd7_dS|jr:| ¡g}|j |¡|jdk rn||jkrn|||f|_dS| |||¡dSrÊ) ror{rr&rtrJrqrxr;)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ˆ|d knˆj d ¡ˆj }|d | |d ƒ| �rÌ|d  dd„| Dƒ¡ƒ|dƒ|dk �rö|t| ||d ƒƒdˆ_ˆj  g¡dS)Ncs i|]\}}|ˆjkr||“qSr!)rn©Ú.0rÙrØr0r!r"Ú ps z+C14NWriterTarget._start..csi|]}|ˆ|ƒ“qSr!r!)rŠr_)Ú parse_qnamer!r"r‹ˆscSs | dd¡S)Nr¾r)r~)r_r!r!r"rª‰r«z)C14NWriterTarget._start..rÍcSs$g|]\}}|rd|nd|f‘qS)zxmlns:Zxmlnsr!)rŠrÃrÄr!r!r"Ú �sÿz+C14NWriterTarget._start..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)rnrer€r�rsr…rƒrÕÚsortrJr`rwrkr$r†ryru)r,r#r(rˆr‡r¤Zresolved_namesrÂZqattrsZ attr_namerbZ parsed_qnamesrVrÙ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&rkrƒrwr*r8rzrtrurjr!r!r"r ³s  zC14NWriterTarget.endcCsd|js dS|jrdS|jr&| d¡n|jr:|jr:| ¡| dt|ƒ›d�¡|js`| d¡dS)Nr¬z)rlr{rzrkryrr&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)r{rzrkryrr&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ñú 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| d d ¡}|WSttfk ržt|ƒYnXdS) NrérêrÉrërïrðròz r¬z 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 r r 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"ÚsàJï >   0s 3 =2 2ý ö þ þ   05   zg