ó
    ×›‘hÐs  ã                   ó@  • S r SSKJr  SSKJrJrJr  SSKJr  S r	SS0r
 " S S	5      r\rSS
 jrS rS rS rS r " S S\5      r " S S5      r " S S\5      r\" \5       " S S5      5       r " S S\5      rS r " S S\R4                  5      r " S S5      rg) zâ
DOM-like XML processing support.

This module provides support for parsing XML into DOM-like object structures
and serializing such structures to an XML string representation, optimized
for use in streaming XML applications.
é    )Úcast)Ú	AttributeÚ	InterfaceÚimplementer)Úsuxc                 óV   • U R                  SS5      n[        U5      S:X  a  U$ SUS   4$ )zOInternal method for splitting a prefixed Element name into its
respective partsÚ:é   é   Nr   )ÚsplitÚlen)ÚnameÚntoks     Ú]C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/words/xish/domish.pyÚ_splitPrefixr      s2   € ð �:‰:�c˜1Ó€DÜ
ˆ4ƒy�Aƒ~Øˆà�d˜1‘gˆÐó    z$http://www.w3.org/XML/1998/namespaceÚxmlc                   ó>   • \ rS rSrSrS
S jrS rS rS rSS jr	S	r
g)Ú_ListSerializeré$   z=Internal class which serializes an Element tree into a bufferNc                 óü   • / U l         0 U l        U(       a  U R                  R                  U5        U R                  R                  [        5        [        R	                  5       /U=(       d    / -   U l        SU l        g ©Nr   )Ú	writelistÚprefixesÚupdateÚ
G_PREFIXESÚvaluesÚprefixStackÚprefixCounter)Úselfr   ÚprefixesInScopes      r   Ú__init__Ú_ListSerializer.__init__'   s]   € ØˆŒØˆŒÞØ�M‰M× Ñ  Ô*Ø�‰×ÑœZÔ(Ü&×-Ñ-Ó/Ð0°O×4IÀrÑJˆÔØˆÕr   c                 ó8   • SR                  U R                  5      $ )NÚ )Újoinr   ©r    s    r   ÚgetValueÚ_ListSerializer.getValue0   s   € Ø�w‰w�t—~‘~Ó&Ð&r   c                 óž   • XR                   ;  a0  SU R                  -  U R                   U'   U R                  S-   U l        U R                   U   $ )Nzxn%dr
   )r   r   ©r    Úuris     r   Ú	getPrefixÚ_ListSerializer.getPrefix3   sG   € Ø—m‘mÓ#Ø!'¨4×+=Ñ+=Ñ!>ˆD�M‰M˜#ÑØ!%×!3Ñ!3°aÑ!7ˆDÔØ�}‰}˜SÑ!Ð!r   c                 óŠ   • U R                   n[        S[        U R                   5      S-   S-  S5       H  nXU   ;   d  M    g   g)Néÿÿÿÿr
   TF©r   Úranger   ©r    ÚprefixÚstackÚis       r   ÚprefixInScopeÚ_ListSerializer.prefixInScope9   sH   € Ø× Ñ ˆÜ�rœC × 0Ñ 0Ó1°AÑ5¸Ñ;¸RÖ@ˆAØ˜q™Õ!Ùñ Að r   c                 óx  • U R                   R                  n[        U[        5      (       a	  U" U5        g [        U[        5      (       a  U" [        U5      5        g UR                  nUR                  nUR                  UpsUR                  R                  5        H  u  p‰X€R                  U	'   M     U R                  R                  [        UR                  R                  5       5      5        Uc  UnUc  UnS n
Xc:w  d  X`R                  ;   a"  U R                  U5      n
U R!                  U
5      nU
(       d  U" SU-  5        ODU" SU
 SU 35        W(       d/  U" SU
 SU S35        U R                  S   R                  U
5        SnX7:w  a  Xc:w  d  U
(       a  W(       d  U" S	U-  5        UR                  R                  5        H  u  p‰U" SU SU	 S35        M     UR"                  R                  5        H©  u  pÍ[        U[$        5      (       av  Uu  pïU R                  U5      nU R!                  U5      (       d-  U" SU SU S35        U R                  S   R                  U5        U" S
U SU S[        US5       S35        M�  U" S
U S[        US5       S35        M«     US:X  a	  U" S5        g ['        UR(                  5      S:”  aN  U" S5        UR(                   H  nU R+                  UUS9  M     U
(       d  U" SU-  5        OU" SU
 SU S35        OU" S5        U R                  R-                  5         g )Nz<%sÚ<r	   z xmlns:z='Ú'r0   Tz xmlns='%s'Ú r
   r   Ú>)Ú
defaultUriz</%s>z</z/>)r   ÚappendÚ
isinstanceÚSerializedXMLÚstrÚescapeToXmlr   r,   r>   ÚlocalPrefixesÚitemsr   r   ÚlistÚkeysr-   r7   Ú
attributesÚtupler   ÚchildrenÚ	serializeÚpop)r    ÚelemÚcloseElementr>   Úwriter   r,   ÚcurrentDefaultUriÚpÚur4   ÚinScopeÚkÚvÚattr_uriÚ	attr_nameÚattr_prefixÚcs                     r   rK   Ú_ListSerializer.serialize@   sÿ  € à—‘×%Ñ%ˆô �dœM×*Ñ*Ù�$ŒKØô �dœC× Ñ Ù”+˜dÓ#Ô$Øð �y‰yˆØ�h‰hˆØ(,¯©¸Ð%à×&Ñ&×,Ñ,Ö.‰DˆAØ �M‰M˜!Óñ /à×Ñ×Ñ¤ T×%7Ñ%7×%<Ñ%<Ó%>Ó ?Ô@ð ÑØ*ˆJà‰;ØˆCàˆØÓ §}¡}Ó 4Ø—^‘^ CÓ(ˆFØ×(Ñ(¨Ó0ˆGö Ù�%˜4‘.Õ!á�A�f�X˜Q˜t˜fÐ%Ô&æÙ˜ ˜x r¨#¨¨aÐ0Ô1Ø× Ñ  Ñ$×+Ñ+¨FÔ3Ø�àÓ*ØÓ¦V¶7á�- :Ñ.Ô/à×&Ñ&×,Ñ,Ö.‰DˆAÙ�G˜A˜3˜b   1Ð%Ö&ñ /ð —O‘O×)Ñ)Ö+‰DˆAä˜!œU×#Ñ#Ø&'Ñ#�Ø"Ÿn™n¨XÓ6�à×)Ñ)¨+×6Ñ6Ù˜G K =°°8°*¸AÐ>Ô?Ø×$Ñ$ RÑ(×/Ñ/°Ô<á˜˜+˜ a¨	 {°"´[ÀÀAÓ5FÐ4GÀqÐIÖJá˜˜!˜˜Bœ{¨1¨aÓ0Ð1°Ð3Ö4ñ ,ð  ˜1ÓÙ�#ŒJØô ˆt�}‰}Ó Ó!Ù�#ŒJØ—]”]�Ø—‘˜q¨Z�Ó8ñ #ö Ù�g Ñ&Õ'á˜˜6˜( ! D 6¨Ð+Õ,á�$ŒKà×Ñ×ÑÕr   )r   r   r   r   ©NN)r
   r%   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   r(   r-   r7   rK   Ú__static_attributes__© r   r   r   r   $   s   † ÙGôò'ò"ò÷Yr   r   c                 óÆ   • U R                  SS5      n U R                  SS5      n U R                  SS5      n US:X  a$  U R                  SS	5      n U R                  S
S5      n U $ )zûEscape text to proper XML form, per section 2.3 in the XML specification.

@type text: C{str}
@param text: Text to escape

@type isattrib: C{bool}
@param isattrib: Triggers escaping of characters necessary for use as
                 attribute values
Ú&ú&amp;r:   ú&lt;r=   ú&gt;r
   r;   ú&apos;Ú"ú&quot;©Úreplace)ÚtextÚisattribs     r   rC   rC   Ÿ   s`   € ð �<‰<˜˜WÓ%€DØ�<‰<˜˜VÓ$€DØ�<‰<˜˜VÓ$€DØ�1ƒ}Ø�|‰|˜C Ó*ˆØ�|‰|˜C Ó*ˆØ€Kr   c                 óº   • U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  S	S
5      n U $ )Nrf   r:   rg   r=   rh   r;   rj   ri   re   rd   rk   ©rm   s    r   ÚunescapeFromXmlrq   ²   sW   € Ø�<‰<˜ Ó$€DØ�<‰<˜ Ó$€DØ�<‰<˜ #Ó&€DØ�<‰<˜ #Ó&€DØ�<‰<˜ Ó%€DØ€Kr   c              #   óV   #   • U  H  nUR                  U5      (       d  M  Uv •  M!     g7f)z Filters items in a list by classN)Ú
providedBy)rF   ÚintÚns      r   ÚgenerateOnlyInterfacerv   »   s#   é € ãˆØ�>‰>˜!×ÓØŒGò ùs   ‚) 	)c              #   ó¦   #   • U  HG  n[         R                  U5      (       d  M  UR                  U:X  d  M1  UR                  U:X  d  MC  Uv •  MI     g7f)z;Filters Element items in a list with matching name and URI.N)ÚIElementrs   r   r,   )rF   r   r,   ru   s       r   ÚgenerateElementsQNamedry   Â   s9   é € ãˆÜ×Ñ˜q×!Ó! a§f¡f°¥n¸¿¹À#½ØŒGò ùs   ‚A¤A¶AÁ	Ac              #   ó‚   #   • U  H5  n[         R                  U5      (       d  M  UR                  U:X  d  M1  Uv •  M7     g7f)zFFilters Element items in a list with matching name, regardless of URI.N)rx   rs   r   )rF   r   ru   s      r   ÚgenerateElementsNamedr{   É   s/   é € ãˆÜ×Ñ˜q×!Ó! a§f¡f°¥nØŒGò ùs   ‚?¤?¶	?c                   ó   • \ rS rSrSrSrg)rA   éÐ   z/Marker class for pre-serialized XML in the DOM.rb   N©r\   r]   r^   r_   r`   ra   rb   r   r   rA   rA   Ð   s   † Ù9âr   rA   c                   ó*   • \ rS rSrSrS rS rS rSrg)Ú	NamespaceéÖ   z7Convenience object for tracking namespace declarations.c                 ó   • Xl         g ©N©Ú_urir+   s     r   r"   ÚNamespace.__init__Ù   s   € Ø�	r   c                 ó   • U R                   U4$ rƒ   r„   ©r    ru   s     r   Ú__getattr__ÚNamespace.__getattr__Ü   ó   € Ø—	‘	˜1ˆ~Ðr   c                 ó   • U R                   U4$ rƒ   r„   rˆ   s     r   Ú__getitem__ÚNamespace.__getitem__ß   r‹   r   r„   N)	r\   r]   r^   r_   r`   r"   r‰   r�   ra   rb   r   r   r€   r€   Ö   s   † ÙAòòõr   r€   c                   ó¨   • \ rS rSrSr\" S5      r\" S5      r\" S5      r\" S5      r	\" S5      r
\" S5      r\" S	5      rSS jrSS jrS rS rSrg
)rx   éã   zŠ
Interface to XML element nodes.

See L{Element} for a detailed example of its general use.

Warning: this Interface is not yet complete!
z Element's namespace URI z Element's local name z) Default namespace URI of child elements z" Dictionary of element attributes z List of child nodes z' Reference to element's parent element z Dictionary of local prefixes Nc                 ó   • g)af  Serializes object to a (partial) XML document

@param prefixes: dictionary that maps namespace URIs to suggested
                 prefix names.
@type prefixes: L{dict}

@param closeElement: flag that determines whether to include the
    closing tag of the element in the serialized string. A value of
    C{0} only generates the element's start tag. A value of C{1} yields
    a complete serialization.
@type closeElement: L{int}

@param defaultUri: Initial default namespace URI. This is most useful
    for partial rendering, where the logical parent element (of which
    the starttag was already serialized) declares a default namespace
    that should be inherited.
@type defaultUri: L{str}

@param prefixesInScope: list of prefixes that are assumed to be
    declared by ancestors.
@type prefixesInScope: L{list}

@return: (partial) serialized XML
@rtype: L{str}
Nrb   )r   rN   r>   r!   s       r   ÚtoXmlÚIElement.toXmlô   ó   � r   c                 ó   • g)a¼  
Create an element and add as child.

The new element is added to this element as a child, and will have
this element as its parent.

@param name: element name. This can be either a L{str} object that
    contains the local name, or a tuple of (uri, local_name) for a
    fully qualified name. In the former case, the namespace URI is
    inherited from this element.
@type name: L{str} or L{tuple} of (L{str}, L{str})

@param defaultUri: default namespace URI for child elements. If
    L{None}, this is inherited from this element.
@type defaultUri: L{str}

@param content: text contained by the new element.
@type content: L{str}

@return: the created element
@rtype: object providing L{IElement}
Nrb   )r   r>   Úcontents      r   Ú
addElementÚIElement.addElement  r”   r   c                 ó   • g)a™  
Adds a node as child of this element.

The C{node} will be added to the list of childs of this element, and
will have this element set as its parent when C{node} provides
L{IElement}. If C{node} is a L{str} and the current last child is
character data (L{str}), the text from C{node} is appended to the
existing last child.

@param node: the child node.
@type node: L{str} or object implementing L{IElement}
Nrb   )Únodes    r   ÚaddChildÚIElement.addChild'  r”   r   c                 ó   • g)a  
Adds character data to this element.

If the current last child of this element is a string, the text will
be appended to that string. Otherwise, the text will be added as a new
child.

@param text: The character data to be added to this element.
@type text: L{str}
Nrb   rp   s    r   Ú
addContentÚIElement.addContent5  r”   r   rb   ©Nr
   r%   Nr[   )r\   r]   r^   r_   r`   r   r,   r   r>   rH   rJ   ÚparentrD   r’   r—   r›   rž   ra   rb   r   r   rx   rx   ã   sj   † ññ Ð3Ó
4€CÙÐ1Ó2€DÙÐJÓK€JÙÐCÓD€JÙÐ4Ó5€HÙÐDÓE€FÙÐBÓC€Môô6ò0õ
r   rx   c                   ó¸   • \ rS rSrSrSrSS jrS rS rS r	S	 r
S
 rS r\rS rSS jrS rS rS rS rS\S\4S jrSS jrS rS rSS jrSS jrS rSrg) ÚElementiB  a,  Represents an XML element node.

An Element contains a series of attributes (name/value pairs), content
(character data), and other child Element objects. When building a document
with markup (such as HTML or XML), use this object as the starting point.

Element objects fully support XML Namespaces. The fully qualified name of
the XML Element it represents is stored in the C{uri} and C{name}
attributes, where C{uri} holds the namespace URI. There is also a default
namespace, for child elements. This is stored in the C{defaultUri}
attribute. Note that C{''} means the empty namespace.

Serialization of Elements through C{toXml()} will use these attributes
for generating proper serialized XML. When both C{uri} and C{defaultUri}
are not None in the Element and all of its descendents, serialization
proceeds as expected:

  >>> from twisted.words.xish import domish
  >>> root = domish.Element(('myns', 'root'))
  >>> root.addElement('child', content='test')
  <twisted.words.xish.domish.Element object at 0x83002ac>
  >>> root.toXml()
  u"<root xmlns='myns'><child>test</child></root>"

For partial serialization, needed for streaming XML, a special value for
namespace URIs can be used: L{None}.

Using L{None} as the value for C{uri} means: this element is in whatever
namespace inherited by the closest logical ancestor when the complete XML
document has been serialized. The serialized start tag will have a
non-prefixed name, and no xmlns declaration will be generated.

Similarly, L{None} for C{defaultUri} means: the default namespace for my
child elements is inherited from the logical ancestors of this element,
when the complete XML document has been serialized.

To illustrate, an example from a Jabber stream. Assume the start tag of the
root element of the stream has already been serialized, along with several
complete child elements, and sent off, looking like this::

  <stream:stream xmlns:stream='http://etherx.jabber.org/streams'
                 xmlns='jabber:client' to='example.com'>
    ...

Now suppose we want to send a complete element represented by an
object C{message} created like:

  >>> message = domish.Element((None, 'message'))
  >>> message['to'] = 'user@example.com'
  >>> message.addElement('body', content='Hi!')
  <twisted.words.xish.domish.Element object at 0x8276e8c>
  >>> message.toXml()
  u"<message to='user@example.com'><body>Hi!</body></message>"

As, you can see, this XML snippet has no xmlns declaration. When sent
off, it inherits the C{jabber:client} namespace from the root element.
Note that this renders the same as using C{''} instead of L{None}:

  >>> presence = domish.Element(('', 'presence'))
  >>> presence.toXml()
  u"<presence/>"

However, if this object has a parent defined, the difference becomes
clear:

  >>> child = message.addElement(('http://example.com/', 'envelope'))
  >>> child.addChild(presence)
  <twisted.words.xish.domish.Element object at 0x8276fac>
  >>> message.toXml()
  u"<message to='user@example.com'><body>Hi!</body><envelope xmlns='http://example.com/'><presence xmlns=''/></envelope></message>"

As, you can see, the <presence/> element is now in the empty namespace, not
in the default namespace of the parent or the streams'.

@type uri: L{str} or None
@ivar uri: URI of this Element's name

@type name: L{str}
@ivar name: Name of this Element

@type defaultUri: L{str} or None
@ivar defaultUri: URI this Element exists within

@type children: L{list}
@ivar children: List of child Elements and content

@type parent: L{Element}
@ivar parent: Reference to the parent Element, if any.

@type attributes: L{dict}
@ivar attributes: Dictionary of attributes associated with this Element.

@type localPrefixes: L{dict}
@ivar localPrefixes: Dictionary of namespace declarations on this
                     element. The key is the prefix to bind the
                     namespace uri to.
r   Nc                 ó  • U=(       d    0 U l         Uu  U l        U l        Uc:  U R                  U R                   R                  5       ;  a  U R                  U l        OX l        U=(       d    0 U l        / U l        SU l        g)ai  
@param qname: Tuple of (uri, name)
@param defaultUri: The default URI of the element; defaults to the URI
                   specified in C{qname}
@param attribs: Dictionary of attributes
@param localPrefixes: Dictionary of namespace declarations on this
                      element. The key is the prefix to bind the
                      namespace uri to.
N)rD   r,   r   r   r>   rH   rJ   r¡   )r    Úqnamer>   ÚattribsrD   s        r   r"   ÚElement.__init__¨  sh   € ð +×0¨bˆÔØ#ÑˆŒ�$”)ØÑ $§(¡(°$×2DÑ2D×2KÑ2KÓ2MÓ"MØ"Ÿh™hˆD�Oà(ŒOØ!Ÿ- RˆŒØˆŒØˆ�r   c                 óÌ   • U R                    H3  n[        R                  U5      (       d  M  UR                  U:X  d  M1  Us  $    UR	                  S5      (       a  [        U5      eg )NÚ_)rJ   rx   rs   r   Ú
startswithÚAttributeError)r    Úkeyru   s      r   r‰   ÚElement.__getattr__¼  sO   € à—”ˆAÜ×"Ñ" 1×%Ó%¨!¯&©&°C­-Ø’ñ ð �>‰>˜#×ÑÜ  Ó%Ð%àr   c                 ó>   • U R                   U R                  U5         $ rƒ   ©rH   Ú_dqa©r    r¬   s     r   r�   ÚElement.__getitem__É  s   € Ø�‰˜tŸy™y¨›~Ñ.Ð.r   c                 ó<   • U R                   U R                  U5      	 g rƒ   r¯   r±   s     r   Ú__delitem__ÚElement.__delitem__Ì  s   € Ø�O‰O˜DŸI™I c›NÑ+r   c                 ó>   • X R                   U R                  U5      '   g rƒ   r¯   )r    r¬   Úvalues      r   Ú__setitem__ÚElement.__setitem__Ï  s   € Ø*/�‰˜Ÿ	™	 #›Ò'r   c                 ó\   • U R                    H  n[        U[        5      (       d  M  Us  $    g)z)
Retrieve the first CData (content) node
r%   )rJ   r@   rB   rˆ   s     r   Ú__unicode__ÚElement.__unicode__Ò  s)   € ð —”ˆAÜ˜!œS×!Ó!Ø’ñ ð r   c                 ó6   • [        U 5      R                  S5      $ )z8
Retrieve the first character data node as UTF-8 bytes.
zutf-8)rB   Úencoder'   s    r   Ú	__bytes__ÚElement.__bytes__Û  s   € ô �4‹y×Ñ Ó(Ð(r   c                 óN   • [        U[        5      (       a  US   (       d  US   $ U$ )z$Dequalify an attribute key as neededr   r
   )r@   rI   )r    Úattrs     r   r°   ÚElement._dqaã  s#   € ä�dœE×"Ñ"¨4°¯7Ø˜‘7ˆNàˆKr   c                 ó8   • U R                   R                  X5      $ )z.Retrieve the value of attribname, if it exists)rH   Úget)r    Ú
attribnameÚdefaults      r   ÚgetAttributeÚElement.getAttributeê  s   € à�‰×"Ñ" :Ó7Ð7r   c                 ó>   • U R                  U5      U R                  ;   $ )z+Determine if the specified attribute exists)r°   rH   )r    Úattribs     r   ÚhasAttributeÚElement.hasAttributeî  s   € à�y‰y˜Ó  D§O¡OÑ3Ð3r   c                 ó^   • U R                   R                  U R                  U5      S5      U:H  $ )zRSafely compare the value of an attribute against a provided value.

L{None}-safe.
N)rH   rÅ   r°   )r    rË   r·   s      r   ÚcompareAttributeÚElement.compareAttributeò  s)   € ð
 �‰×"Ñ" 4§9¡9¨VÓ#4°dÓ;¸uÑDÐDr   c                 ó8   • U R                   nX1   nX2   X1'   XCU'   g)z!Swap the values of two attribute.N)rH   )r    ÚleftÚrightÚdÚls        r   ÚswapAttributeValuesÚElement.swapAttributeValuesù  s"   € à�O‰OˆØ‰GˆØ‘(ˆ‰Øˆ%Šr   c                 ó|   • [         R                  U5      (       a  Xl        U R                  R	                  U5        U$ )zAdd a child to this Element.)rx   rs   r¡   rJ   r?   )r    rš   s     r   r›   ÚElement.addChild   s/   € ä×Ñ˜t×$Ñ$ØŒKØ�‰×Ñ˜TÔ"Øˆr   rm   Úreturnc                 ó>  • [        U[        5      (       d&  [        SU< S[        U5      R                   S35      eU R
                  n[        U5      S:”  a$  [        US   [        5      (       a  US   U-   US'   OUR                  U5        [        [        US   5      $ )z#Add some text data to this Element.zExpected str not z (Ú)r   r0   )	r@   rB   Ú	TypeErrorÚtyper\   rJ   r   r?   r   )r    rm   rY   s      r   rž   ÚElement.addContent  s†   € ä˜$¤×$Ñ$ÜÐ/°©x°r¼$¸t»*×:MÑ:MÐ9NÈaÐPÓQÐQØ�M‰MˆÜˆq‹6�A‹:œ* Q r¡U¬C×0Ñ0Ø�b‘E˜D‘LˆAˆbŠEà�H‰H�TŒNÜ”C˜˜2™ÓÐr   c                 óâ   • [        U[        5      (       a  Uc  US   n[        X5      nOUc  U R                  n[        X!4U5      nU R	                  U5        U(       a  UR                  U5        U$ r   )r@   rI   r£   r>   r›   rž   )r    r   r>   r–   Úchilds        r   r—   ÚElement.addElement  sh   € Ü�dœE×"Ñ"ØÑ!Ø! !™W�
Ü˜DÓ-‰EàÑ!Ø!Ÿ_™_�
Ü˜ZÐ.°
Ó;ˆEà�‰�eÔæØ×Ñ˜WÔ%àˆr   c                 óL   • U R                   R                  [        U5      5        g)z=Add a pre-serialized chunk o' XML as a child of this Element.N)rJ   r?   rA   )r    Úrawxmlstrings     r   Ú	addRawXmlÚElement.addRawXml#  s   € à�‰×Ñœ]¨<Ó8Õ9r   c                 ó|   • S[         R                  -  U R                  S'   [         R                  S-   [         l        g)zKAdd a unique (across a given Python session) id attribute to this
Element.
zH_%dÚidr
   N)r£   Ú
_idCounterrH   r'   s    r   ÚaddUniqueIdÚElement.addUniqueId'  s0   € ð !'¬×);Ñ);Ñ ;ˆ�‰˜ÑÜ$×/Ñ/°!Ñ3ŒÕr   c                 óh   • Uc  [        U R                  [        5      $ [        U R                  X!5      $ )a�  
Iterate across all children of this Element that are Elements.

Returns a generator over the child elements. If both the C{uri} and
C{name} parameters are set, the returned generator will only yield
on elements matching the qualified name.

@param uri: Optional element URI.
@type uri: L{str}
@param name: Optional element name.
@type name: L{str}
@return: Iterator that yields objects implementing L{IElement}.
)rv   rJ   rx   ry   )r    r,   r   s      r   ÚelementsÚElement.elements.  s+   € ð ‰<Ü(¨¯©¼ÓAÐAä)¨$¯-©-¸ÓCÐCr   c                 óT   • [        XS9nUR                  XUS9  UR                  5       $ )z4Serialize this Element and all children to a string.)r   r!   )rN   r>   )ÚSerializerClassrK   r(   )r    r   rN   r>   r!   Úss         r   r’   ÚElement.toXmlA  s(   € ä XÑOˆØ	�‰�DÀ
ˆÑKØ�z‰z‹|Ðr   c                 óf   • U R                    H!  n[        R                  U5      (       d  M  Us  $    g rƒ   )rJ   rx   rs   )r    rY   s     r   ÚfirstChildElementÚElement.firstChildElementG  s+   € Ø—”ˆAÜ×"Ñ" 1×%Ó%Ø’ñ ð r   )rH   rJ   r>   rD   r   r¡   r,   )NNNrƒ   r[   r    )r\   r]   r^   r_   r`   ré   r"   r‰   r�   r´   r¸   r»   r¿   Ú__str__r°   rÈ   rÌ   rÏ   rÖ   r›   rB   rž   r—   rå   rê   rí   r’   rô   ra   rb   r   r   r£   r£   B  s‹   † ñ`ðD €Jôò(ò/ò,ò0òò)ð €Gòô8ò4òEòòð	 ˜sð 	  sô 	 ôò":ò4ôDô&õr   r£   c                   ó   • \ rS rSrSrSrg)ÚParserErroriN  z,Exception thrown when a parsing error occursrb   Nr~   rb   r   r   rø   rø   N  s   † Ù6âr   rø   c                  óx   •  [        5       n U $ ! [         a!    [        c  [        S5      e[        5       n U s $ f = f)zzPreferred method to construct an ElementStream

Uses Expat-based stream if available, and falls back to Sux if necessary.
zNo parsers available :()ÚExpatElementStreamÚImportErrorÚSuxElementStreamÚ	Exception)Úess    r   ÚelementStreamrÿ   T  sB   € ð
ÜÓ!ˆØˆ	øÜó ÜÑ#ÜÐ5Ó6Ð6ÜÓˆØŠ	ð	ús   ‚ Ž(9¸9c                   óZ   • \ rS rSrS rS rS rS rS rS r	S r
S	S
SSSS.rS rS rSrg)rü   ic  c                 ó”   • U R                  5         S U l        S U l        S U l        S U l        S U l        SU l        / U l        / U l        g )NF)	ÚconnectionMadeÚDocumentStartEventÚElementEventÚDocumentEndEventÚcurrElemÚrootElemÚdocumentStartedÚdefaultNsStackr   r'   s    r   r"   ÚSuxElementStream.__init__d  sL   € Ø×ÑÔØ"&ˆÔØ ˆÔØ $ˆÔØˆŒØˆŒØ$ˆÔØ ˆÔØˆÕr   c                 óˆ   •  U R                  U5        g ! [        R                   a  n[        [	        U5      5      eS nAff = frƒ   )ÚdataReceivedr   Ú
ParseErrorrø   rB   ©r    ÚbufferÚes      r   ÚparseÚSuxElementStream.parseo  s8   € ð	&Ø×Ñ˜fÕ%øÜ�~‰~ó 	&Üœc !›fÓ%Ð%ûð	&ús   ‚ ”A¨<¼Ac                 ó˜   • U R                   n[        S[        U R                   5      S-   S-  S5       H  nXU   ;   d  M  X#   U   s  $    g )Nr0   r
   r1   r3   s       r   ÚfindUriÚSuxElementStream.findUriu  sT   € ð × Ñ ˆÜ�rœC × 0Ñ 0Ó1°AÑ5¸Ñ;¸RÖ@ˆAØ˜q™Õ!Ø‘x Ñ'Ò'ñ Að r   c                 óH  • S n0 n0 nS n[        UR                  5       5       H6  u  pxUR                  S5      (       d  M  [        U5      u  pšU	c  UnOX„U
'   X'	 M8     U R                  R                  U5        Uc+  [        U R                  5      S:”  a  U R                  S   nOSn[        U5      u  p±Uc  UnOU R                  U5      nUR                  5        H9  u  px[        U5      u  p¬U
c  X…U'   M  [        U5      XPR                  U
5      U4'   M;     [        Xa4X5U5      nU R                  R                  U5        U R                  (       a5  U R                  c  XÐl        g U R                  R                  U5      U l        g XÐl        SU l        U R                  U5        g )NÚxmlnsr   r0   r%   T)rF   rE   rª   r   r   r?   r   r	  r  rq   r£   r  r  r›   r  r  )r    r   rH   r>   rD   r¦   r,   rT   rU   ÚxrQ   r4   ru   r  s                 r   ÚgotTagStartÚSuxElementStream.gotTagStart~  s�  € Øˆ
ØˆØˆØˆô ˜×)Ñ)Ó+Ö,‰DˆAØ�|‰|˜G×$Ó$Ü# A“‘�Ø‘9Ø!"‘Jà'( !Ñ$Ø’Mñ -ð 	×Ñ×Ñ Ô.ð ÑÜ�4×&Ñ&Ó'¨!Ó+Ø!×0Ñ0°Ñ4‘
à�
ô $ DÓ)‰ˆØ‰>Ø‰Cð —,‘,˜vÓ&ˆCð ×$Ñ$Ö&‰DˆAÜ “?‰DˆAØ‰yØ˜“
ä0?ÀÓ0B�Ÿ™ a›¨1Ð,Ó-ñ 'ô �S�K °mÓDˆð 	×Ñ×"Ñ" :Ô.ð ××à�}‰}Ñ$Ø !•ð !%§¡× 6Ñ 6°qÓ 9�•ð ŒMØ#'ˆDÔ Ø×#Ñ# AÕ&r   c                 ó¢   • U R                   bB  [        U[        5      (       a  UR                  S5      nU R                   R	                  U5        g g ©NÚascii©r  r@   ÚbytesÚdecoderž   ©r    Údatas     r   ÚgotTextÚSuxElementStream.gotText½  ó>   € Ø�=‰=Ñ$Ü˜$¤×&Ñ&Ø—{‘{ 7Ó+�Ø�M‰M×$Ñ$ TÕ*ð %r   c                 ó¢   • U R                   bB  [        U[        5      (       a  UR                  S5      nU R                   R	                  U5        g g r  r  r!  s     r   ÚgotCDataÚSuxElementStream.gotCDataÃ  r%  r   c                 ó   • g rƒ   rb   r!  s     r   Ú
gotCommentÚSuxElementStream.gotCommentÉ  s   € àr   rd   r:   r=   r;   ri   )ÚampÚltÚgtÚaposÚquotc                 óÖ   • U[         R                  ;   aU  [         R                  U   n[        U[        5      (       a  UR	                  S5      nU R
                  R                  U5        g g r  )rü   Úentitiesr@   r  r   r  rž   )r    Ú	entityRefr"  s      r   ÚgotEntityReferenceÚ#SuxElementStream.gotEntityReferenceÕ  sU   € ð Ô(×1Ñ1Ó1Ü#×,Ñ,¨YÑ7ˆDÜ˜$¤×&Ñ&Ø—{‘{ 7Ó+�Ø�M‰M×$Ñ$ TÕ*ð	 2r   c                 ó$  • U R                   c  [        S5      e[        U5      u  p!Uc  U R                  S   nOU R	                  U5      nU R
                  cW  U R                   R                  U:w  d  U R                   R                  U:w  a  [        S5      eU R                  5         S U l         g U R
                  R                  U:w  d  U R
                  R                  U:w  a  [        S5      eU R                  R                  5         U R                  R                  5         U R
                  R                  c>  U R                   U R
                  l        U R                  U R
                  5        S U l        g U R
                  R                  U l        g )Nz%Element closed after end of document.r0   zMismatched root elementszMalformed element close)r  rø   r   r	  r  r  r   r,   r  r   rL   r¡   r  )r    r   r4   r,   s       r   Ú	gotTagEndÚSuxElementStream.gotTagEndÞ  s<  € à�=‰=Ñ äÐEÓFÐFô $ DÓ)‰ˆØ‰>Ø×%Ñ% bÑ)‰Cà—,‘,˜vÓ&ˆCð �=‰=Ñ à�}‰}×!Ñ! TÓ)¨T¯]©]×->Ñ->À#Ó-EÜ!Ð"<Ó=Ð=Ø×!Ñ!Ô#Ø ˆD�Mð �}‰}×!Ñ! TÓ)¨T¯]©]×->Ñ->À#Ó-Eä!Ð";Ó<Ð<ð ×Ñ× Ñ Ô"Ø×Ñ×#Ñ#Ô%ð �}‰}×#Ñ#Ñ+Ø'+§}¡}�—‘Ô$Ø×!Ñ! $§-¡-Ô0Ø $�•ð !%§¡× 4Ñ 4�•r   )r  r  r  r  r	  r  r   r  N)r\   r]   r^   r_   r"   r  r  r  r#  r'  r*  r2  r4  r7  ra   rb   r   r   rü   rü   c  sH   † ò	ò&òò='ò~+ò+òð
 ØØØØñ€Hò+õ*5r   rü   c                   ó>   • \ rS rSrS rS rS rS rS rS r	S r
S	rg
)rú   i  c                 óÎ  • SS K nS U l        S U l        S U l        UR                  U l        UR                  SS5      U l        U R                  U R                  l        U R                  U R                  l
        U R                  U R                  l        U R                  U R                  l        U R                  U R                  l        S U l        S/U l        SU l        0 U l        g )Nr   zUTF-8r<   r%   )Úpyexpatr  r  r  ÚerrorÚParserCreateÚparserÚ_onStartElementÚStartElementHandlerÚ_onEndElementÚEndElementHandlerÚ_onCdataÚCharacterDataHandlerÚ_onStartNamespaceÚStartNamespaceDeclHandlerÚ_onEndNamespaceÚEndNamespaceDeclHandlerr  r	  r  rD   )r    r;  s     r   r"   ÚExpatElementStream.__init__  sµ   € Ûà"&ˆÔØ ˆÔØ $ˆÔØ—]‘]ˆŒ
Ø×*Ñ*¨7°CÓ8ˆŒØ*.×*>Ñ*>ˆ�‰Ô'Ø(,×(:Ñ(:ˆ�‰Ô%Ø+/¯=©=ˆ�‰Ô(Ø04×0FÑ0Fˆ�‰Ô-Ø.2×.BÑ.Bˆ�‰Ô+ØˆŒØ!˜dˆÔØ ˆÔØˆÕr   c                 ó”   •  U R                   R                  U5        g ! U R                   a  n[        [	        U5      5      eS nAff = frƒ   )r>  ÚParser<  rø   rB   r  s      r   r  ÚExpatElementStream.parse  s<   € ð	&Ø�K‰K×Ñ˜fÕ%øØ�z‰zó 	&Üœc !›fÓ%Ð%ûð	&ús   ‚ žA®AÁAc                 ól  • UR                  SS5      n[        U5      S:X  a  SU4n0 n/ nUR                  5        H<  u  pgSU;   d  M  UR                  SS5      nXtUS   US   4'   UR                  U5        M>     UR	                  U5        U H  nX&	 M     [        X0R                  S   X R                  5      n	0 U l        U R                  S:X  aM  U R                  S :w  a6  U R                  R                  R                  U	5        U R                  U	l        X�l	        g SU l        U R                  U	5        g )Nr<   r
   r%   r   r0   )Úrsplitr   rE   r?   r   r£   r	  rD   r  r  rJ   r¡   r  )
r    r   Úattrsr¥   ÚnewAttrsÚtoDeleterT   rU   Úaqnamer  s
             r   r?  Ú"ExpatElementStream._onStartElement$  s  € ð —‘˜C Ó#ˆÜˆu‹:˜‹?Ø˜�JˆEð ˆØˆØ—K‘K–M‰DˆAØ�a�xØŸ™ # qÓ)�Ø34˜& ™) V¨A¡YÐ/Ñ0Ø—‘ Ö"ñ	 "ð 	�‰�XÔãˆAØ’ñ ô �E×.Ñ.¨rÑ2°E×;MÑ;MÓNˆØˆÔð ×Ñ 1Ó$Ø�}‰} Ó$Ø—‘×&Ñ&×-Ñ-¨aÔ0ØŸ=™=�”Ø�Mð $%ˆDÔ Ø×#Ñ# AÕ&r   c                 óê   • U R                   c  U R                  5         g U R                   R                  c#  U R                  U R                   5        S U l         g U R                   R                  U l         g rƒ   )r  r  r¡   r  )r    r©   s     r   rA  Ú ExpatElementStream._onEndElementJ  sV   € à�=‰=Ñ Ø×!Ñ!Õ#ð �]‰]×!Ñ!Ñ)Ø×Ñ˜dŸm™mÔ,Ø ˆD�Mð
 !ŸM™M×0Ñ0ˆD�Mr   c                 ó\   • U R                   S :w  a  U R                   R                  U5        g g rƒ   )r  rž   r!  s     r   rC  ÚExpatElementStream._onCdataZ  s%   € Ø�=‰=˜DÓ Ø�M‰M×$Ñ$ TÕ*ð !r   c                 ó^   • Uc  U R                   R                  U5        g X R                  U'   g rƒ   )r	  r?   rD   )r    r4   r,   s      r   rE  Ú$ExpatElementStream._onStartNamespace^  s+   € ð ‰>Ø×Ñ×&Ñ& sÕ+à),×Ñ˜vÒ&r   c                 ó@   • Uc  U R                   R                  5         g g rƒ   )r	  rL   )r    r4   s     r   rG  Ú"ExpatElementStream._onEndNamespacef  s   € à‰>Ø×Ñ×#Ñ#Õ%ð r   )	r  r  r  r  r	  r  r<  rD   r>  N)r\   r]   r^   r_   r"   r  r?  rA  rC  rE  rG  ra   rb   r   r   rú   rú     s&   † ò ò$&ò$'òL1ò +ò-õ&r   rú   N)r   )r`   Útypingr   Úzope.interfacer   r   r   Útwisted.webr   r   r   r   rð   rC   rq   rv   ry   r{   rB   rA   r€   rx   r£   rý   rø   rÿ   Ú	XMLParserrü   rú   rb   r   r   Ú<module>r`     sÍ   ðñ
õ ç <Ñ <å òð 5°eÐ<€
÷uñ uðp "€ôò&òòòô	�Cô 	÷
ñ 
ô\ˆyô \ñ~ ˆXÓ÷Hð Hó ðHôV	�)ô 	òôe5�s—}‘}ô e5÷P^&ò ^&r   