
    F\hE"                       S r / SQrSrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr   " S S\5      rS	 r " S
 S5      r0 4S jrSCS jrSCS jr\r " S S5      r " S S5      r\	R.                  S 5       rSCS jrS r1 SkrS rS r\\\S.rS rSSSSSS S!S".r \ \l         S# r!S$ r"S% r#S& r$SDSSS'S(.S) jjr% " S* S+\RL                  5      r'SDSSS'S(.S, jjr(S- r)SES. jr*SCS/ jr+SDS0 jr, " S1 S25      r-SCS3 jr.SCS4 jr/\.r0SCS5 jr1 " S6 S75      r2 " S8 S95      r3SCSSS:.S; jjr4\Rj                  " S<\Rl                  5      Rn                  r8 " S= S>5      r9S? r:S@ r; \r<SSAK=7  SSBK=J>r>  \>" \\5        g! \? a     gf = f)Fa  Lightweight XML support for Python.

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

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

   2. Element represents a single node in this tree.

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

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

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

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

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

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

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

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

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

)CommentdumpElementElementTree
fromstringfromstringlistindent	iselement	iterparseparse
ParseErrorPIProcessingInstructionQName
SubElementtostringtostringlistTreeBuilderVERSIONXMLXMLID	XMLParserXMLPullParserregister_namespacecanonicalizeC14NWriterTargetz1.3.0    N   )ElementPathc                       \ rS rSrSrSrg)r   k   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____firstlineno____doc____static_attributes__r!       ,/usr/lib/python3.13/xml/etree/ElementTree.pyr   r   k   s     	r(   r   c                     [        U S5      $ )z2Return True if *element* appears to be an Element.tag)hasattr)elements    r)   r	   r	   y   s    7E""r(   c                       \ rS rSrSrSr Sr Sr Sr 0 4S jr	S r
S rS rS rS	 rS
 rS rS rS rS rS rS rS rSS jrSS jrSS jrSS jrS rSS jrS rS rS rSS jr S r!Sr"g) r   ~   a8  An 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

Nc                     [        U[        5      (       d#  [        SUR                  R                  < 35      eXl        0 UEUEU l        / U l        g )Nzattrib must be dict, not )
isinstancedict	TypeError	__class__r"   r+   attrib	_children)selfr+   r5   extras       r)   __init__Element.__init__   sM    &$''  )), - -))5)r(   c                 `    SU R                   R                  U R                  [        U 5      4-  $ )Nz<%s %r at %#x>)r4   r"   r+   idr7   s    r)   __repr__Element.__repr__   s&    4>>#:#:DHHbh"OOOr(   c                 $    U R                  X5      $ )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.

)r4   )r7   r+   r5   s      r)   makeelementElement.makeelement   s     ~~c**r(   c                     U R                  U R                  U R                  5      nU R                  Ul        U R                  Ul        XS S & U$ N)rA   r+   r5   texttail)r7   elems     r)   __copy__Element.__copy__   s>    $++6II	II	Qr(   c                 ,    [        U R                  5      $ rD   )lenr6   r=   s    r)   __len__Element.__len__   s    4>>""r(   c                 f    [         R                  " S[        SS9  [        U R                  5      S:g  $ )NzTesting an element's truth value will always return True in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.   
stacklevelr   )warningswarnDeprecationWarningrK   r6   r=   s    r)   __bool__Element.__bool__   s1    K 1		 4>>"a''r(   c                      U R                   U   $ rD   r6   r7   indexs     r)   __getitem__Element.__getitem__   s    ~~e$$r(   c                     [        U[        5      (       a  U H  nU R                  U5        M     OU R                  U5        X R                  U'   g rD   )r1   slice_assert_is_elementr6   )r7   rZ   r-   elts       r)   __setitem__Element.__setitem__   sC    eU##'',  ##G, 'ur(   c                     U R                   U	 g rD   rX   rY   s     r)   __delitem__Element.__delitem__   s    NN5!r(   c                 \    U R                  U5        U R                  R                  U5        g)zAdd *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r_   r6   appendr7   
subelements     r)   rh   Element.append   s$     	
+j)r(   c                 n    U H/  nU R                  U5        U R                  R                  U5        M1     g)z[Append subelements from a sequence.

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

Nrg   )r7   elementsr-   s      r)   extendElement.extend   s.      G##G,NN!!'*  r(   c                 \    U R                  U5        U R                  R                  X5        g)z(Insert *subelement* at position *index*.N)r_   r6   insert)r7   rZ   rj   s      r)   rq   Element.insert   s"    
+e0r(   c                 p    [        U[        5      (       d!  [        S[        U5      R                  -  5      eg )Nzexpected an Element, not %s)r1   _Element_Pyr3   typer"   )r7   es     r)   r_   Element._assert_is_element   s1     ![))9DG<L<LLMM *r(   c                 :    U R                   R                  U5        g)ay  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)r6   removeri   s     r)   ry   Element.remove  s     	j)r(   c                 0    [         R                  " XU5      $ )zFind 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r7   path
namespacess      r)   r|   Element.find  s     J77r(   c                 0    [         R                  " XX#5      $ )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r7   r~   defaultr   s       r)   r   Element.findtext  s     ##DDDr(   c                 0    [         R                  " XU5      $ )zFind all matching subelements by tag name or path.

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

Returns list containing all matching elements in document order.

)r   findallr}   s      r)   r   Element.findall)  s     ""4z::r(   c                 0    [         R                  " XU5      $ )a   Find all matching subelements by tag name or path.

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

Return an iterable yielding all matching elements in document order.

)r   iterfindr}   s      r)   r   Element.iterfind4  s     ##D
;;r(   c                 b    U R                   R                  5         / U l        S=U l        U l        g)z~Reset element.

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

N)r5   clearr6   rE   rF   r=   s    r)   r   Element.clear?  s)     	 $$	DIr(   c                 8    U R                   R                  X5      $ )a7  Get 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.

)r5   get)r7   keyr   s      r)   r   Element.getJ  s     {{s,,r(   c                      X R                   U'   g)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)r5   )r7   r   values      r)   setElement.setW  s     !Cr(   c                 6    U R                   R                  5       $ )zGet list of attribute names.

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

)r5   keysr=   s    r)   r   Element.keysa  s     {{!!r(   c                 6    U R                   R                  5       $ )zGet element attributes as a sequence.

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

Return a list of (name, value) tuples.

)r5   itemsr=   s    r)   r   Element.itemsj  s     {{  ""r(   c              #      #    US:X  a  SnUb  U R                   U:X  a  U v   U R                   H  nUR                  U5       Sh  vN   M     g N	7f)a  Create 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+   r6   iter)r7   r+   rv   s      r)   r   Element.iteru  sI      #:C;$((c/JAvvc{""  "s   AAA
Ac              #      #    U R                   n[        U[        5      (       d  Ub  gU R                  nU(       a  Uv   U  H4  nUR	                  5        Sh  vN   UR
                  nU(       d  M0  Uv   M6     g N"7f)z}Create text iterator.

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

N)r+   r1   strrE   itertextrF   )r7   r+   trv   s       r)   r   Element.itertext  sd      hh#s##IIGAzz|##Aq	 #s   AA<A:A<1
A<)r6   r5   r+   rF   rE   rD   NN)#r"   r#   r$   r%   r&   r+   r5   rE   rF   r9   r>   rA   rH   rL   rU   r[   ra   rd   rh   rn   rq   r_   ry   r|   r   r   r   r   r   r   r   r   r   r   r'   r!   r(   r)   r   r   ~   s    ( CF1D D $& P	+#(%("	*+1
N*	8E	;	<	%-!"	##,r(   r   c                 V    0 UEUEnU R                  X5      nU R                  U5        U$ )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.

)rA   rh   )parentr+   r5   r8   r-   s        r)   r   r     s4     ! % F  -G
MM'Nr(   c                 0    [        [        5      nXl        U$ )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.

)r   r   rE   )rE   r-   s     r)   r   r     s     gGLNr(   c                 l    [        [        5      nXl        U(       a  UR                  S-   U-   Ul        U$ )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.

 )r   r   rE   )targetrE   r-   s      r)   r   r     s1     +,GL||c)D0Nr(   c                   R    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rSrg)r   i  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.

Nc                 2    U(       a
  SU< SU< 3nXl         g )N{}rE   )r7   text_or_urir+   s      r)   r9   QName.__init__  s    &137K	r(   c                     U R                   $ rD   r   r=   s    r)   __str__QName.__str__  s    yyr(   c                 T    SU R                   R                  < SU R                  < S3$ )N<r   >)r4   r"   rE   r=   s    r)   r>   QName.__repr__  s     NN33TYY??r(   c                 ,    [        U R                  5      $ rD   )hashrE   r=   s    r)   __hash__QName.__hash__  s    DIIr(   c                 |    [        U[        5      (       a  U R                  UR                  :*  $ U R                  U:*  $ rD   r1   r   rE   r7   others     r)   __le__QName.__le__  1    eU##99

**yyE!!r(   c                 |    [        U[        5      (       a  U R                  UR                  :  $ U R                  U:  $ rD   r   r   s     r)   __lt__QName.__lt__  1    eU##99uzz))yy5  r(   c                 |    [        U[        5      (       a  U R                  UR                  :  $ U R                  U:  $ rD   r   r   s     r)   __ge__QName.__ge__  r   r(   c                 |    [        U[        5      (       a  U R                  UR                  :  $ U R                  U:  $ rD   r   r   s     r)   __gt__QName.__gt__  r   r(   c                 |    [        U[        5      (       a  U R                  UR                  :H  $ U R                  U:H  $ rD   r   r   s     r)   __eq__QName.__eq__  r   r(   r   rD   )r"   r#   r$   r%   r&   r9   r   r>   r   r   r   r   r   r   r'   r!   r(   r)   r   r     s5     @"!"!"r(   r   c                       \ rS rSrSrSS jrS rS rSS jrSS jr	SS	 jr
SS
 jrSS jrSS jr    SSS.S jjrS rSrg)r   i  a  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.

Nc                 B    Xl         U(       a  U R                  U5        g g rD   )_rootr   )r7   r-   files      r)   r9   ElementTree.__init__  s    
JJt r(   c                     U R                   $ )z!Return root element of this tree.r   r=   s    r)   getrootElementTree.getroot  s    zzr(   c                     Xl         g)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   )r7   r-   s     r)   _setrootElementTree._setroot  s	     
r(   c                 (   Sn[        US5      (       d  [        US5      nSn UcU  [        5       n[        US5      (       a:  UR                  U5      U l        U R                  U(       a  UR                  5         $ $ UR                  S5      =n(       a+  UR                  U5        UR                  S5      =n(       a  M+  UR                  5       U l        U R                  U(       a  UR                  5         $ $ ! U(       a  UR                  5         f f = f)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rbT_parse_wholei   )r,   openr   r   r   closer   feed)r7   sourceparserclose_sourcedatas        r)   r   ElementTree.parse!  s     vv&&&$'FL	~"6>22
 "(!4!4V!<DJ::   !++e,,$,D! !++e,,$,DJ:: | s   ?C7 ;AC7 > C7 7Dc                 8    U R                   R                  U5      $ )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   r   r7   r+   s     r)   r   ElementTree.iterC  s     zzs##r(   c                     USS S:X  a"  SU-   n[         R                  " SU-  [        SS9  U R                  R	                  X5      $ )a4  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 %rrO   rP   )rR   rS   FutureWarningr   r|   r}   s      r)   r|   ElementTree.findO  sO     8s?:DMM-/34 !	 zzt00r(   c                     USS S:X  a"  SU-   n[         R                  " SU-  [        SS9  U R                  R	                  XU5      $ )a=  Find 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.

Nr   r   r   r   rO   rP   )rR   rS   r   r   r   r   s       r)   r   ElementTree.findtexte  sS     8s?:DMM-/34 !	 zz""4*==r(   c                     USS S:X  a"  SU-   n[         R                  " SU-  [        SS9  U R                  R	                  X5      $ )a9  Find 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.

Nr   r   r   r   rO   rP   )rR   rS   r   r   r   r}   s      r)   r   ElementTree.findall{  sQ     8s?:DMM-/34 !	 zz!!$33r(   c                     USS S:X  a"  SU-   n[         R                  " SU-  [        SS9  U R                  R	                  X5      $ )a?  Find 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.

Nr   r   r   r   rO   rP   )rR   rS   r   r   r   r}   s      r)   r   ElementTree.iterfind  sQ     8s?:DMM-/34 !	 zz""444r(   Tshort_empty_elementsc          	         U(       d  SnOU[         ;  a  [        SU-  5      eU(       d  US:X  a  SnOSn[        X5       u  pxUS:X  a?  U(       d+  Uc5  UR                  5       S:w  a!  UR                  5       S;  a  U" S	U< S
35        US:X  a  [	        XpR
                  5        O3[        U R
                  U5      u  p[         U   nU" XpR
                  XUS9  SSS5        g! , (       d  f       g= f)az  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

xmlzunknown method %rc14nutf-8us-asciiNunicode)r   r   z<?xml version='1.0' encoding='z'?>
rE   r   )
_serialize
ValueError_get_writerlower_serialize_textr   _namespaces)r7   file_or_filenameencodingxml_declarationdefault_namespacemethodr   writedeclared_encodingqnamesr   	serializes               r)   r  ElementTree.write  s    : F:%069::"%)48RO$,^^%2&,,.6KK%( )zz2%0=N%O"&v.	%V/CE 544s    BC  
C.c                 "    U R                  USS9$ )Nr   )r  )r  )r7   r   s     r)   
write_c14nElementTree.write_c14n  s    zz$vz..r(   r   r   rD   )NNNN)r"   r#   r$   r%   r&   r9   r   r   r   r   r|   r   r   r   r  r  r'   r!   r(   r)   r   r     sZ    	 D
$1,>,4,5. " $	3E
 $(3Ej/r(   r   c              #     #     U R                   nUR                  5       S:X  a  U[        U SS 5      =(       d    S4v   g [        R                  " 5        n[        U [        R                  5      (       a  U nO[        U [        R                  5      (       a2  [        R                  " U 5      nUR                  UR                  5        OF[        R                  " 5       nS Ul        X$l          U R                  Ul        U R                  Ul        [        R                   " UUSSS9nUR                  UR                  5        UR                   U4v   S S S 5        g ! [         a     NWf = f! , (       d  f       g = f! [         aP    UR                  5       S:X  a  Sn[#        U SUSS	9 nUR                   U4v   S S S 5         g ! , (       d  f        g = ff = f7f)
Nr  r	  r   c                      gNTr!   r!   r(   r)   <lambda>_get_writer.<locals>.<lambda>  s    Dr(   xmlcharrefreplace
)r	  errorsnewlinew)r	  r  )r  r  getattr
contextlib	ExitStackr1   ioBufferedIOBase	RawIOBaseBufferedWritercallbackdetachwritableseekabletellAttributeErrorTextIOWrapperr   )r  r	  r  stackr   s        r)   r  r    s    -+ && >>y(!1:tDOOO %%'5.0A0ABB+D 0",,??,,-=>D NN4;;/ ,,.D$0DM!&J )9(A(A$4$9$9	 ''19/B046 t{{+jj(**9 ('& * ' ('  '>>y(H"C(,.15**h&&. . . .	's   GE: AGBE),"EAE)	G
E&#E)%E&&E))
E73G:,G&G7G?G
G	GGGGc                   ^^^ S S 0m0 mT(       a  STT'   UUU4S jnU R                  5        GHX  n U R                  n[        U[        5      (       a#  UR                  T;  a  U" UR                  5        OD[        U[
        5      (       a  UT;  a  U" U5        O Ub  U[        La  U[        La  [        U5        U R                  5        Ho  u  pE[        U[        5      (       a  UR                  nUT;  a  U" U5        [        U[        5      (       d  MK  UR                  T;  d  M]  U" UR                  5        Mq     U R                  n[        U[        5      (       d  GM3  UR                  T;  d  GMF  U" UR                  5        GM[     TT4$ )N c                 j  >  U S S S:X  av  U SS  R                  SS5      u  pTR                  U5      nUc1  [        R                  U5      nUc  S[        T5      -  nUS:w  a  UTU'   U(       a  U< SU< 3TU '   g UTU '   g T(       a  [	        S5      eU TU '   g ! [
         a    [        U 5         g f = f)Nr   r   r   zns%dr   :z<cannot use non-qualified names with default_namespace option)rsplitr   _namespace_maprK   r  r3   _raise_serialization_error)qnameurir+   prefixr  r   r  s       r)   	add_qname_namespaces.<locals>.add_qname   s    	.RayC 9++C3#,>+//4F~!'#j/!9*0
3/5s$;F5M$'F5M$$3  !&u 	.&u-	.s   A8B <B B B21B2)
r   r+   r1   r   rE   r   r   r   r4  r   )	rG   r  r8  r+   r   r   rE   r   r  s	    `     @@r)   r  r    s7    D\F J(*
$%.8 		hhc5!!xxv%#((#S!!& #_G!32&s+**,JC#u%%hh& #%''EJJf,D%**% ' yydE""tyy'>dii ' ( :r(   c           	         UR                   nUR                  nU[        L a  U " SU-  5        GOU[        L a  U " SU-  5        GOX&   nUc/  U(       a  U " [	        U5      5        U H  n[        XUS US9  M     GOYU " SU-   5        [        UR                  5       5      n	U	(       d  U(       a  U(       aH  [        UR                  5       S S9 H+  u  pU(       a  SU-   nU " SU< S	[        U
5      < S
35        M-     U	 Hh  u  p[        U[        5      (       a  UR                  n[        U
[        5      (       a  X*R                     n
O[        U
5      n
U " SX+   < S	U
< S
35        Mj     U(       d  [        U5      (       d  U(       dD  U " S5        U(       a  U " [	        U5      5        U H  n[        XUS US9  M     U " SU-   S-   5        OU " S5        UR                  (       a  U " [	        UR                  5      5        g g )N	<!--%s--><?%s?>r   r   c                     U S   $ Nr   r!   xs    r)   r   _serialize_xml.<locals>.<lambda>h      QqTr(   r   r1   xmlns=""r   r   </z />)r+   rE   r   r   _escape_cdata_serialize_xmllistr   sorted_escape_attribr1   r   rK   rF   )r  rG   r  r   r   kwargsr+   rE   rv   r   vks               r)   rI  rI  R  s   
((C99D
g~kD !	%	%hok;mD)*u4HJ  #)&E
 &z'7'7'9+9!; #aA*1- 	!; "DA!!U++FF!!U++"66N*1-&)Q78 " s4yy(<c
--.A"5VT8LN  dSj3&'eyymDII&' r(   >   brhrcolimgwbrareabaselinkmetaembedframeinputparamtrackr   isindexbasefontc           	      <   UR                   nUR                  nU[        L a  U " S[        U5      -  5        GOU[        L a  U " S[        U5      -  5        GOX%   nUc0  U(       a  U " [        U5      5        U H  n[        XUS 5        M     GObU " SU-   5        [        UR                  5       5      nU(       d  U(       a  U(       aH  [        UR                  5       S S9 H+  u  pU
(       a  SU
-   n
U " SU
< S[        U	5      < S	35        M-     U Hh  u  p[        U
[        5      (       a  U
R                  n
[        U	[        5      (       a  X)R                     n	O[        U	5      n	U " S
X*   < SU	< S	35        Mj     U " S5        UR                  5       nU(       a&  US:X  d  US:X  a	  U " U5        OU " [        U5      5        U H  n[        XUS 5        M     U[        ;  a  U " SU-   S-   5        UR                  (       a  U " [        UR                  5      5        g g )Nr;  r<  r   c                     U S   $ r>  r!   r?  s    r)   r  !_serialize_html.<locals>.<lambda>  rB  r(   rC  r1  rD  rE  rF  r   r   scriptstylerG  )r+   rE   r   rH  r   _serialize_htmlrJ  r   rK  rL  r1   r   _escape_attrib_htmlr  
HTML_EMPTYrF   )r  rG   r  r   rM  r+   rE   rv   r   rN  rO  ltags               r)   re  re    s   
((C99D
g~kM$//0	%	%ht,,-k;mD)*&$7  #)&E
 &z'7'7'9+9!; #aA*1- 	!; "DA!!U++FF!!U++"66N/2&)Q78 " #J99;D8#tw$K--.&$7 :%dSj3&'yymDII&' r(   c                     UR                  5        H  nU " U5        M     UR                  (       a  U " UR                  5        g g rD   )r   rF   )r  rG   parts      r)   r  r    s1    d  yydii r(   )r   htmlrE   c                     [         R                  " SU 5      (       a  [        S5      e[        [        R                  5       5       H  u  p#X!:X  d  X0:X  d  M  [        U	 M     U [        U'   g)a\  Register 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.

zns\d+$z'Prefix format reserved for internal useN)rematchr  rJ  r3  r   )r7  r6  rO  rN  s       r)   r   r     sX     
xx	6""BCC^))+,8q{q! - !N3r(   r   rk  rdfwsdlxsxsidc)$http://www.w3.org/XML/1998/namespacezhttp://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/c                 P    [        SU < S[        U 5      R                  < S35      e)Nzcannot serialize z (type ))r3   ru   r"   r   s    r)   r4  r4    s!    
+/d1D1DE
 
r(   c                      SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n U $ ! [        [        4 a    [        U 5         g f = f)N&&amp;r   &lt;r   &gt;replacer3   r+  r4  r   s    r)   rH  rH    so    ) $;<<W-D$;<<V,D$;<<V,D~& )"4()   A	A A*)A*c                     SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n S	U ;   a  U R                  S	S
5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n U $ ! [        [        4 a    [        U 5         g f = f)Nrx  ry  r   rz  r   r{  rF  &quot;z&#13;r  z&#10;	z&#09;r|  r   s    r)   rL  rL     s    )$;<<W-D$;<<V,D$;<<V,D4<<<h/D 4<<<g.D4<<<g.D4<<<g.D~& )"4()s   B)B, ,C
	C
c                      SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n U $ ! [        [        4 a    [        U 5         g f = f)Nrx  ry  r   r{  rF  r  r|  r   s    r)   rf  rf    sm    	)$;<<W-D$;<<V,D4<<<h/D~& )"4()r~  T)r
  r  r   c          	          US:X  a  [         R                  " 5       O[         R                  " 5       n[        U 5      R	                  XaUUUUS9  UR                  5       $ )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BytesIOr   r  getvalue)r-   r	  r  r
  r  r   streams          r)   r   r   +  sT      ')3R[[]Fv/>1B&,4H	  J
 ??r(   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
_ListDataStreamiC  z7An auxiliary stream accumulating into a list reference.c                     Xl         g rD   lst)r7   r  s     r)   r9   _ListDataStream.__init__E  s    r(   c                     gr  r!   r=   s    r)   r(  _ListDataStream.writableH      r(   c                     gr  r!   r=   s    r)   r)  _ListDataStream.seekableK  r  r(   c                 :    U R                   R                  U5        g rD   )r  rh   )r7   bs     r)   r  _ListDataStream.writeN  s    r(   c                 ,    [        U R                  5      $ rD   )rK   r  r=   s    r)   r*  _ListDataStream.tellQ  s    488}r(   r  N)r"   r#   r$   r%   r&   r9   r(  r)  r  r*  r'   r!   r(   r)   r  r  C  s    Ar(   r  c          	      X    / n[        U5      n[        U 5      R                  XqUUUUS9  U$ )Nr  )r  r   r  )r-   r	  r  r
  r  r   r  r  s           r)   r   r   T  sA     CS!Fv/>1B&,4H	  J
 Jr(   c                    [        U [        5      (       d  [        U 5      n U R                  [        R                  SS9  U R                  5       R                  nU(       a	  US   S:w  a   [        R                  R                  S5        gg)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)r1   r   r  sysstdoutr   rF   )rG   rF   s     r)   r   r   a  se     dK((4 JJszzIJ.<<>D48t#

 $r(   c                    ^^^ [        U [        5      (       a  U R                  5       n US:  a  [        SU 35      e[	        U 5      (       d  gSUT-  -   /mUUU4S jmT" U S5        g)a  Indent an XML document by inserting newlines and indentation space
after elements.

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

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

*level* is the initial indentation level. Setting this to a higher
value than 0 can be used for indenting subtrees that are more deeply
nested inside of a document.
r   z,Initial indentation level must be >= 0, got Nr  c                   > US-   n TU   nU R                  (       a  U R                  R                  5       (       d  X0l        U  HS  n[	        U5      (       a  T" XB5        UR
                  (       a!  UR
                  R                  5       (       a  MM  X4l        MU     WR
                  R                  5       (       d  TU   Ul        g g ! [          a    TU   T-   nTR                  U5         Nf = fr>  )
IndexErrorrh   rE   striprK   rF   )rG   levelchild_levelchild_indentationchild_indent_childrenindentationsspaces        r)   r   indent.<locals>._indent_children  s    ai	3 ,[ 9
 yy		 1 1)IE5zz 4::UZZ%5%5%7%7.
	  zz!!%e,EJ "  	3 ,U 3e ; 12	3s   C #C-,C-)r1   r   r   r  rK   )treer  r  r  r  s    ` @@r)   r   r   t  sg     $$$||~qyGwOPPt99 55=()L-, T1r(   c                 <    [        5       nUR                  X5        U$ )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.

)r   r   )r   r   r  s      r)   r   r     s     =DJJvKr(   c                   ^ ^^^^	 [        XS9m[        T S5      (       d  [        T S5      m SmOSmUUU	4S jnU" T 5      m " UUU 4S jS[        R                  R
                  5      nU" 5       nS	Ul        [        R                  " U5      m	U$ )
a&  Incrementally 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_parserr   r   TFc              3   |  >#      TR                  5        S h  vN   U R                  S5      nU(       d  OTR                  U5        MD  TR                  5       nTR                  5        S h  vN   T" 5       nUb  X#l        T(       a  U R                  5         g g  N N/! T(       a  U R                  5         f f = f7f)Ni @  )read_eventsr   r   _close_and_return_rootrootr   )r   r   r  itr   
pullparserwrs       r)   iteratoriterparse.<locals>.iterator  s     	%11333{{9-%  446D!--///B~  4 0
  s?   B<B BAB -B.B B<B B B99B<c                   N   > \ rS rSr YR                  rU UU4S jrU U4S jrSrg)$iterparse.<locals>.IterParseIteratori  c                 T   > T(       a  TR                  5         TR                  5         g rD   r   )r7   r   genr   s    r)   r   *iterparse.<locals>.IterParseIterator.close  s    IIKr(   c                 6   > T(       a  TR                  5         g g rD   r  )r7   r   r   s    r)   __del__,iterparse.<locals>.IterParseIterator.__del__  s      r(   r!   N)r"   r#   r$   r%   __next__r   r  r'   )r   r  r   s   r)   IterParseIteratorr    s    <<	
	 	r(   r  N)	r   r,   r   collectionsabcIteratorr  weakrefref)
r   r  r   r  r  r  r   r  r  r  s
   `     @@@@r)   r
   r
     s    " f=J66""fd#$ 6
C KOO44  
	BBG	RBIr(   c                   D    \ rS rSrSSS.S jjrS rS rS rS rS	 r	S
r
g)r   i  N)r  c                    [         R                  " 5       U l        U=(       d    [        [	        5       S9U l        Uc  SnU R
                  R                  U R                  U5        g )Nr   )end)r  deque_events_queuer   r   r  
_setevents)r7   r  r  s      r)   r9   XMLPullParser.__init__  sL    
 )..0A);="A>F 2 2F;r(   c                     U R                   c  [        S5      eU(       a   U R                   R                  U5        gg! [         a%  nU R                  R                  U5         SnAgSnAff = f)Feed encoded data to parser.Nz!feed() called after end of stream)r  r  r   SyntaxErrorr  rh   )r7   r   excs      r)   r   XMLPullParser.feed  s`    <<@AA/!!$'   /""))#../s   > 
A-A((A-c                 H    U R                   R                  5       nS U l         U$ rD   )r  r   )r7   r  s     r)   r  $XMLPullParser._close_and_return_root  s     ||!!#r(   c                 $    U R                  5         g)zFinish feeding data to parser.

Unlike XMLParser, does not return the root element. Use
read_events() to consume elements from XMLPullParser.
N)r  r=   s    r)   r   XMLPullParser.close  s     	##%r(   c              #      #    U R                   nU(       a5  UR                  5       n[        U[        5      (       a  UeUv   U(       a  M4  gg7f)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)r  popleftr1   	Exception)r7   r  events      r)   r  XMLPullParser.read_events  s?      ##NN$E%++ fs   AA
Ac                 h    U R                   c  [        S5      eU R                   R                  5         g )Nz"flush() called after end of stream)r  r  flushr=   s    r)   r  XMLPullParser.flush+  s(    <<ABBr(   )r  r  rD   )r"   r#   r$   r%   r9   r   r  r   r  r  r'   r!   r(   r)   r   r     s'    
<t 
</&r(   r   c                 t    U(       d  [        [        5       S9nUR                  U 5        UR                  5       $ )a  Parse 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  r   r   r   r   )rE   r   s     r)   r   r   1  s+     +-0
KK<<>r(   c                     U(       d  [        [        5       S9nUR                  U 5        UR                  5       n0 nUR	                  5        H!  nUR                  S5      nU(       d  M  XCU'   M#     X#4$ )a  Parse 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<   )r   r   r   r   r   r   )rE   r   r  idsrG   r<   s         r)   r   r   B  sb     +-0
KK<<>D
C		XXd^2G  9r(   c                     U(       d  [        [        5       S9nU  H  nUR                  U5        M     UR                  5       $ )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.

r  r  )sequencer   rE   s      r)   r   r   Z  s5     +-0D <<>r(   c                   d    \ rS rSrSrSSSSSS.S jjrS rS rS	 rS
 r	S r
S rSS jrS rSrg)r   il  a  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.

*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_pisc                    / U l         / U l        S U l        S U l        S U l        Uc  [
        nX l        X@l        Uc  [        nX0l	        XPl
        Uc  [        nXl        g rD   )_data_elem_lastr   _tailr   _comment_factoryr  r   _pi_factoryr  r   _factory)r7   element_factoryr  r  r  r  s         r)   r9   TreeBuilder.__init__  sd     




"%O /..J%$"%O'r(   c                     [        U R                  5      S:X  d   S5       eU R                  c   S5       eU R                  $ )z;Flush builder buffers and return toplevel document Element.r   zmissing end tagszmissing toplevel element)rK   r  r   r=   s    r)   r   TreeBuilder.close  s>    4::!#7%77#zz%A'AA%zzr(   c                 b   U R                   (       a  U R                  b  SR                  U R                   5      nU R                  (       a/  U R                  R                  b   S5       eXR                  l        O.U R                  R
                  b   S5       eXR                  l        / U l         g g )Nr/  zinternal error (tail)zinternal error (text))r  r  joinr  rF   rE   r7   rE   s     r)   _flushTreeBuilder._flush  s~    ::zz%wwtzz*::::??2K4KK2&*JJO::??2K4KK2&*JJODJ r(   c                 :    U R                   R                  U5        g)zAdd text to current element.N)r  rh   r7   r   s     r)   r   TreeBuilder.data  s    

$r(   c                     U R                  5         U R                  X5      =U l        nU R                  (       a  U R                  S   R	                  U5        OU R
                  c  X0l        U R                  R	                  U5        SU l        U$ )znOpen new element and return it.

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

r  r   )r  r  r  r  rh   r   r  )r7   r+   attrsrG   s       r)   startTreeBuilder.start  sl     	 MM#55
T::JJrN!!$'ZZJ

$
r(   c                    U R                  5         U R                  R                  5       U l        U R                  R                  U:X  d$   SU R                  R                  < SU< S35       eSU l        U R                  $ )z?Close and return current Element.

*tag* is the element name.

zend tag mismatch (expected z, got rv  r   )r  r  popr  r+   r  r   s     r)   r  TreeBuilder.end  sa     	ZZ^^%
zz~~$ 	(::>>3(	($ 
zzr(   c                 P    U R                  U R                  U R                  U5      $ )zPCreate a comment using the comment_factory.

*text* is the text of the comment.
)_handle_singler  r  r  s     r)   commentTreeBuilder.comment  s*    
 ""!!4#7#7? 	?r(   c                 P    U R                  U R                  U R                  X5      $ )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  )r7   r   rE   s      r)   piTreeBuilder.pi  s(     ""doov= 	=r(   c                     U" U6 nU(       aL  U R                  5         X@l        U R                  (       a  U R                  S   R                  U5        SU l        U$ )Nr  r   )r  r  r  rh   r  )r7   factoryrq   argsrG   s        r)   r	  TreeBuilder._handle_single  sE    ~KKMJzz

2%%d+DJr(   )
r  r  r  r  r  r  r   r  r  r  rD   )r"   r#   r$   r%   r&   r9   r   r  r   r  r  r
  r  r	  r'   r!   r(   r)   r   r   l  sC    &(!%$!&5((
 "?=r(   r   c                   j    \ rS rSrSrSSS.S jrS rS rS rS	 r	S
 r
S rS rS rS rS rS rSrg)r   i  aM  Element 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)r   r	  c                    SSK Jn  UR	                  US5      nUc
  [        5       nU=U l        U l        U=U l        U l	        UR                  U l        0 U l        U R                  Ul        [        US5      (       a  U R                   Ul        [        US5      (       a  U R$                  Ul        [        US5      (       a  U R(                  Ul        [        US5      (       a  U R,                  Ul        [        US	5      (       a  UR0                  Ul        [        US
5      (       a  UR4                  Ul        [        US5      (       a  UR8                  Ul        SUl        SUl        S U l         0 U l!         SURD                  -  U l#        g ! [         a"     SS Kn GN! [         a    [        S5      ef = ff = f! [H         a     g f = f)Nr   expatz7No module named expat; use SimpleXMLTreeBuilder insteadr   r  r  start_nsend_nsr   r
  r  r   zExpat %d.%d.%d)%xml.parsersr  ImportErrorpyexpatParserCreater   r   r  r   _targeterror_error_names_defaultDefaultHandlerExpandr,   _startStartElementHandler_endEndElementHandler	_start_nsStartNamespaceDeclHandler_end_nsEndNamespaceDeclHandlerr   CharacterDataHandlerr
  CommentHandlerr  ProcessingInstructionHandlerbuffer_textordered_attributes_doctypeentityversion_infoversionr+  )r7   r   r	  r  r   s        r)   r9   XMLParser.__init__  s   	) ##Hc2> ]F%++dl%++dlkk&*mm#67##)-F&65!!'+yyF$6:&&/3~~F,68$$-1\\F*66""*0++F'69%%$*NNF!64  28))F/$%!	+e.@.@@DLM  	' !M 	N  		s/   F 7F; 
F8FF44F8;
GGc                 B   U R                   nUR                  nU GH   nUS:X  a   SUl        XTU R                  4S jnXcl        M*  US:X  a  XTU R
                  4S jnXcl        MI  US:X  a;  [        U R                  S5      (       a  XTU R                  4S jnOXT4S	 jnXcl
        M  US
:X  a;  [        U R                  S5      (       a  XTU R                  4S jnOXT4S jnXcl        M  US:X  a  XTU 4S jnXcl        M  US:X  a  XTU 4S jnXcl        M  [        SU-  5      e   g )Nr  r   c                 "    U" X$" X5      45        g rD   r!   )r+   	attrib_inr  rh   r  s        r)   handler%XMLParser._setevents.<locals>.handler)  s    E5#89:r(   r  c                 "    U" X" U 5      45        g rD   r!   )r+   r  rh   r  s       r)   r8  r9  .  s    E3s8,-r(   zstart-nsr  c                 "    U" X$" X5      45        g rD   r!   )r7  r6  r  rh   r  s        r)   r8  r9  5  s    x'<=>r(   c                 >    U" X =(       d    SU=(       d    S445        g Nr/  r!   )r7  r6  r  rh   s       r)   r8  r9  9  s    "ciR'@ABr(   zend-nsr  c                 "    U" X" U 5      45        g rD   r!   )r7  r  rh   r  s       r)   r8  r9  ?  s    vf~67r(   c                     U" US 45        g rD   r!   )r7  r  rh   s      r)   r8  r9  C  s    t}-r(   r
  c                 H    U" XR                   R                  U 5      45        g rD   )r   r
  )rE   r  rh   r7   s       r)   r8  r9  G  s    E;;#6#6t#<=>r(   r  c                 H    U" X$R                   R                  X5      45        g rD   )r   r  )	pi_targetr   r  rh   r7   s        r)   r8  r9  K  s    E;;>>)#BCDr(   zunknown event %r)r  rh   r/  r#  r$  r%  r&  r,   r   r'  r(  r)  r*  r,  r-  r  )r7   events_queueevents_to_reportr   rh   
event_namer8  s          r)   r  XMLParser._setevents  s    $$*JW$,-)2<"&++; .5*u$'1 $		. ,3(z)4;;
333=)-? 4> C3:0x'4;;11.8'+||8 /9 .18.y((2 ?(/%t#3=!%E 7>3 !3j!@AAU +r(   c                 x    [        U5      nUR                  Ul        UR                  UR                  4Ul        UerD   )r   codelinenooffsetposition)r7   r   errs      r)   _raiseerrorXMLParser._raiseerrorR  s0    ::||U\\1	r(   c                 ~     U R                   U   nU$ ! [         a    UnSU;   a  SU-   nX R                   U'    U$ f = f)Nr   r   )r   KeyError)r7   r   names      r)   _fixnameXMLParser._fixnameX  sS    	$;;s#D   	$Dd{Tz#KK	$s    %<<c                 ^    U R                   R                  U=(       d    SU=(       d    S5      $ r=  )r   r  r7   r7  r6  s      r)   r'  XMLParser._start_nsc  s!    {{##FLb#)<<r(   c                 J    U R                   R                  U=(       d    S5      $ r=  )r   r  )r7   r7  s     r)   r)  XMLParser._end_nsf  s    {{!!&,B//r(   c                     U R                   nU" U5      n0 nU(       a.  [        S[        U5      S5       H  nX%S-      XC" X%   5      '   M     U R                  R	                  X5      $ )Nr   rO   r   )rR  rangerK   r   r  )r7   r+   	attr_listfixnamer5   is         r)   r#  XMLParser._starti  sa     --cl1c)na009A#wy|,- 1{{  --r(   c                 V    U R                   R                  U R                  U5      5      $ rD   )r   r  rR  r   s     r)   r%  XMLParser._endu  s    {{t}}S122r(   c                 L   US S nUS:X  a1   U R                   R                  n U" U R                  USS    5        g US:X  a  US S	 S
:X  a  / U l        g U R                  Gb"  US:X  a  S U l        g UR                  5       nU(       d  g U R                  R!                  U5        [#        U R                  5      nUS:  a  U R                  S   nUS:X  a"  US:X  a  U R                  u  ppU	(       a  U	SS n	OUS:X  a  US:X  a  U R                  u  pn
S n	Og [%        U R                   S5      (       a   U R                   R'                  XU
SS 5        O,[%        U S5      (       a  [(        R*                  " S[,        5        S U l        g g g ! [         a     g f = f! [         a    SSKJn  UR                  SXR                  R                  U R                  R                  4-  5      nSUl        U R                  R                  Ul        U R                  R                  Ul        Uef = f)Nr   rx  r  r   r  z'undefined entity %s: line %d, column %d   r   	   z	<!DOCTYPEr   rO   PUBLIC   SYSTEM   doctypezaThe doctype() method of XMLParser is ignored.  Define doctype() method on the TreeBuilder target.)r   r   r+  r1  rP  r  r  r  r   ErrorLineNumberErrorColumnNumberrH  rI  rJ  r0  r  rh   rK   r,   rh  rR   rS   RuntimeWarning)r7   rE   r7  data_handlerr  rL  nru   rQ  pubidsystems              r)   r!  XMLParser._defaultx  s   bqS=#{{//T[[a45 s]tBQx;6DM]]&} $::<DMM  &DMM"A1u}}Q'8#Q04-D %aX%!q&)-&D E4;;	22KK''VAb\BT9--MMM&(
 !%'  '# "   
-kk=;;66KK1133
 ![[88
![[::
	
s   F F 
FFBH#c                      U R                   R                  US5        g! U R                   a  nU R                  U5         SnAgSnAff = f)r  FN)r   Parser  rM  )r7   r   rN  s      r)   r   XMLParser.feed  s@    	 KKdE*{{ 	 Q	 s    A
AA
c                 2    U R                   R                  SS5         U R                  R
                  nU" 5       U ? U ?U ?U ?$ ! U R                   a  nU R                  U5         SnANLSnAff = f! [         a     Of = f U ? U ?U ?U ?g! U ? U ?U ?U ?f = f)z;Finish feeding data to parser and return element structure.r(   TN)	r   rr  r  rM  r   r   r  r  r+  )r7   rN  close_handlers      r)   r   XMLParser.close  s    	 KKc4(		* KK--M !? T\T\ {{ 	 Q	   		
 T\T\ T\T\s?   A A2 B A/A**A/2
A?<B >A??B 
Bc                 z   U R                   R                  5       n U R                   R                  S5        U R                   R                  SS5        U R                   R                  U5        g ! U R                   a  nU R                  U5         S nANBS nAff = f! U R                   R                  U5        f = f)NFr(   )r   GetReparseDeferralEnabledSetReparseDeferralEnabledrr  r  rM  )r7   was_enabledrN  s      r)   r  XMLParser.flush  s    kk;;=	?KK11%8KKc5) KK11+> {{ 	 Q	  KK11+>s)   7A/ /B?BB BB B:)	r0  r  r   r  r  r1  r   r   r3  )r"   r#   r$   r%   r&   r9   r  rM  rR  r'  r)  r#  r%  r!  r   r   r  r'   r!   r(   r)   r   r     sN     "& +Z3Bj	=0
.34%l *"?r(   r   )out	from_filec                    U c  Uc  [        S5      eSnUc  [        R                  " 5       =pA[        [	        UR
                  40 UD6S9nU b"  UR                  U 5        UR                  5         OUb	  [        X%S9  Ub  UR                  5       $ S$ )a  Convert 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  r   r   r  r   r   r   r  )xml_datar|  r}  optionssior   s         r)   r   r     s     I-UVV
C
{KKM!.syyDGDEFH		i' _3<<>6$6r(   z	^\w+:\w+$c                       \ rS rSrSrSSSSSSSS.S jr\4S jrS rSS	 jr	S
 r
SR                  4S jrS rS rSS jrS rS rS rSrg)r   i  a  
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                \   Xl         / U l        X l        X0l        U(       a  [	        U5      OS U l        U(       a  [	        U5      OS U l        X@l        U(       a  [	        U5      U l        OS U l        U(       a  [	        U5      R                  U l
        OS U l
        S//U l        / U l        U(       d6  U R                  R                  [        [        R!                  5       5      5        U R                  R                  / 5        0 U l        S/U l        S U l        SU l        SU l        SU l        g )N)rt  r   Fr   )_writer  _with_comments_strip_textr   _exclude_attrs_exclude_tags_rewrite_prefixes_qname_aware_tagsintersection_find_qname_aware_attrs_declared_ns_stack	_ns_stackrh   rJ  r3  r   _prefix_map_preserve_space_pending_start
_root_seen
_root_done_ignored_depth)	r7   r  r  r  r  r  r  r  r  s	            r)   r9   C14NWriterTarget.__init__
  s     
+%4Ac-0t2>S.D!1%()9%:D"%)D"+./@+A+N+ND(+/D( <$
 # NN!!$~';';'=">?b! %w"r(   c              #   T   #    U" U5       H  nU(       d  M  U S h  vN   M     g  N	7frD   r!   )r7   ns_stack	_reversedr   s       r)   _iter_namespaces!C14NWriterTarget._iter_namespaces/  s%     #H-Jz%%% .%s   ((&
(c                     UR                  SS5      u  p#U R                  U R                  5       H  u  pEXR:X  d  M  SU SU 3s  $    [        SU SU S35      e)Nr1  r   r   r   zPrefix z of QName "" is not declared in scope)splitr  r  r  )r7   prefixed_namer7  rQ  r6  ps         r)   _resolve_prefix_name%C14NWriterTarget._resolve_prefix_name4  sf    $**32++DNN;FC{C54&)) < 76(+m_D^_``r(   c                    Uc%  US S S:X  a  USS  R                  SS5      OSU4u  p#OUn[        5       nU R                  U R                  5       H4  u  pVXR:X  a  Xd;  a  U(       a  U SU 3OUX24s  $ UR	                  U5        M6     U R
                  (       am  X R                  ;   a  U R                  U   nO&S[        U R                  5       3=o`R                  U'   U R                  S   R                  X&45        U SU 3X24$ U(       d
  SU;  a  X3U4$ U R                  U R                  5       H=  u  pVXR:X  d  M  U R                  S   R                  X&45        U(       a  U SU 3OUX24s  $    U(       d  X3U4$ [        SU S	35      e)
Nr   r   r   r/  r1  rm  r  zNamespace "r  )r2  r   r  r  addr  r  rK   rh   r  r  )r7   r5  r6  r+   prefixes_seenur7  s          r)   _qnameC14NWriterTarget._qname;  s   ;38!93CuQRy''Q/"eHCC..t/F/FGIAxF7,2&3%(SEEf% H !!&&&))#.34S9I9I5J4K1LL))#.##B'..}=XQse$c..r.S= ..t~~>IAx''+22C=A,2&3%(SEE ?
  S= ;se+EFGGr(   c                 ^    U R                   (       d  U R                  R                  U5        g g rD   )r  r  rh   r  s     r)   r   C14NWriterTarget.data`  s"    ""JJd# #r(   r/  c                    U" U R                   5      nU R                   S S 2	 U R                  (       a$  U R                  S   (       d  UR                  5       nU R                  bF  U R                  S so0l        U(       a  [        U5      (       a  UOS nU R                  " / UQUP76   Ub  g U(       a-  U R                  (       a  U R                  [        U5      5        g g g Nr  )
r  r  r  r  r  _looks_like_prefix_namer#  r  r  _escape_cdata_c14n)r7   
_join_textr   r  
qname_texts        r)   r  C14NWriterTarget._flushd  s    $**%JJqMD$8$8$<::<D*(,(;(;T%D%!%*A$*G*GTJKK**z*%DOOKK*401 $4r(   c                     U R                   (       a  g U R                  (       a  U R                  5         U R                  S   R	                  X!45        g r  )r  r  r  r  rh   rU  s      r)   r  C14NWriterTarget.start_nsr  s7    ::KKMr!!3-0r(   c                 v   U R                   b6  U R                  (       d  XR                   ;   a  U =R                  S-  sl        g U R                  (       a  U R                  5         / nU R                  R                  U5        U R                  b  XR                  ;   a
  XU4U l        g U R                  XU5        g r>  )	r  r  r  r  r  rh   r  r  r#  )r7   r+   r  new_namespacess       r)   r  C14NWriterTarget.startz  s    )##s.@.@'@1$::KKM&&~6!!-#9O9O2O#&~">DC/r(   c                    U R                   b<  U(       a5  UR                  5        VVs0 s H  u  pVXPR                   ;  d  M  XV_M     nnnU1Ukn0 nUb&  U R                  U5      =oU'   UR                  U	5        U R                  bh  U(       aa  U R	                  U5      n
U
(       aF  U
 H?  nX+   n[        U5      (       d  M  U R                  U5      =oU'   UR                  U	5        MA     OS n
OS n
U R                  n[        US S9 Vs0 s H  oU" U5      _M     nnU(       a6  U VVs/ s H  u  nnU(       a  SU-   OSU4PM     nnnUR                  5         O/ nU(       a]  [        UR                  5       5       H@  u  pVU
b  XZ;   a  Xh;   a
  XU      S   nX   u  nnnUR                  U(       a  UOUU45        MB     UR                  S5      nU R                  R                  U(       a  US:H  OU R                  S   5        U R                  nU" S	X   S   -   5        U(       a<  U" S
R                  U VVs/ s H  u  pVSU S[        U5       S3PM     snn5      5        U" S5        Ub  U" [        XU      S   5      5        SU l        U R"                  R                  / 5        g s  snnf s  snf s  snnf s  snnf )Nc                 &    U R                  SS5      $ )Nr   r   )r  )rm  s    r)   r  )C14NWriterTarget._start.<locals>.<lambda>  s    !''#q/r(   rC  zxmlns:xmlnsr   z+{http://www.w3.org/XML/1998/namespace}spacepreserver  r   r/  r   rE  rF  r   T)r  r   r  r  r  r  r  rK  sortrh   r   r  r  r  _escape_attrib_c14nr  r  r  )r7   r+   r  r  r  rO  rN  r  resolved_namesr5  qattrs	attr_namer   parse_qnamerm  parsed_qnamesr6  r7  r[  
attr_qnamespace_behaviourr  s                         r)   r#  C14NWriterTarget._start  s   *u&+kkmTmdaq@S@S7STQTmET !151J1J:1VVE:.JJu''311%8F!'I!,E.u558<8Q8QRW8XXu 5

5)	 "( F kk4:153 4 53qKN* 53 4  $2#1KC '-F"'3?#1   NN I u{{}-%!+!:M%Q&78;A-:-=*
Is  *A!FG .  ))$QR##-<Oz)%%b)	+
 cM&q))*"'')T)$!Qqc$7$:#;1=)TUVc
 !$]*3M%Nq%QRSb!C U04
8 Us   J,J,
J2*J7;J=c                    U R                   (       a  U =R                   S-  sl         g U R                  (       a  U R                  5         U R                  SU R	                  U5      S    S35        U R
                  R                  5         [        U R
                  5      S:H  U l        U R                  R                  5         U R                  R                  5         g )Nr   rG  r   r   )r  r  r  r  r  r  r  rK   r  r  r  r   s     r)   r  C14NWriterTarget.end  s    1$::KKMbS)!,-Q/0  "d223q8##%r(   c                 x   U R                   (       d  g U R                  (       a  g U R                  (       a  U R                  S5        O2U R                  (       a!  U R
                  (       a  U R                  5         U R                  S[        U5       S35        U R                  (       d  U R                  S5        g g )Nr  z<!--z-->)r  r  r  r  r  r  r  r  r  s     r)   r
  C14NWriterTarget.comment  sw    ""??KK__KKMd-d34C89KK r(   c                 t   U R                   (       a  g U R                  (       a  U R                  S5        O2U R                  (       a!  U R                  (       a  U R                  5         U R                  U(       a  SU S[        U5       S3OSU S35        U R                  (       d  U R                  S5        g g )Nr  z<?r   z?>)r  r  r  r  r  r  r  )r7   r   r   s      r)   r  C14NWriterTarget.pi  s    ??KK__KKM:>b,T2326bPRO	UKK r(   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rD   )r"   r#   r$   r%   r&   r9   reversedr  r  r  r   r  r  r  r  r#  r  r
  r  r'   r!   r(   r)   r   r     sj    ,  %"&$#$# J 4< &
a#HJ$ !# 210"C"J

r(   r   c                 
    SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n U $ ! [        [        4 a    [        U 5         g f = f)	Nrx  ry  r   rz  r   r{  r  &#xD;r|  r   s    r)   r  r    s    ) $;<<W-D$;<<V,D$;<<V,D4<<<g.D~& )"4()s   A!A$ $BBc                 j    SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n SU ;   a  U R                  SS5      n S	U ;   a  U R                  S	S
5      n SU ;   a  U R                  SS5      n U $ ! [        [        4 a    [        U 5         g f = f)Nrx  ry  r   rz  rF  r  r  z&#x9;r  z&#xA;r  r  r|  r   s    r)   r  r  	  s    )$;<<W-D$;<<V,D$;<<X.D4<<<g.D4<<<g.D4<<<g.D~& )"4()s   BB B21B2)r   )_set_factoriesrD   r   )z  r   )@r&   __all__r   r  rm  rR   r"  r  collections.abcr   r  r/  r   r  r   r	   r   r   r   r   r   r   r   contextmanagerr  r  rI  rg  re  r  r  r   r3  r4  rH  rL  rf  r   r#  r  r   r   r   r   r
   r   r   r   r   r   r   r   r   compileUNICODErn  r  r   r  r  rt   _elementtreer  r  r!   r(   r)   <module>r     s  !P(  
 	  	     		 		#
^ ^B	 $& $  +" +"`\/ \/B /+ /+b;z0(d
0(d 
!* -2$*38(.(,16(, %3  !

) )8)!T"&0b'' "
!%&*
&/l<~7 7t", 
$v vth? h?Z7tt 7< **\2::>DD  D)&).3 K + 712  		s   %E< <FF