Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/microdom.cpython-37.pyc

B

;��]e��@s�dZddlZddlmZmZddlmZmZmZm	Z	ddl
mZddlm
Z
mZdd�Zd	d
�Zdd�Zd
Zee�Ze��edZee�Ze��efdd�Zefdd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de �Z!Gdd �d e �Z"Gd!d"�d"e �Z#d#d$�Z$e$�Z%Gd%d&�d&e �Z&Gd'd(�d(e�Z'd)d*�Z(d+d,�Z)Gd-d.�d.e
�Z*d/d0�Z+d1d2�Z,d3d4�Z-d5d6�Z.Gd7d8�d8�Z/dS)9a�
Micro Document Object Model: a partial DOM implementation with SUX.

This is an implementation of what we consider to be the useful subset of the
DOM.  The chief advantage of this library is that, not being burdened with
standards compliance, it can remain very stable between versions.  We can also
implement utility 'pythonic' ways to access and mutate the XML tree.

Since this has not subjected to a serious trial by fire, it is not recommended
to use this outside of Twisted applications.  However, it seems to work just
fine for the documentation generator, which parses a fairly representative
sample of XML.

Microdom mainly focuses on working with HTML and XHTML.
�N)�BytesIO�StringIO)�ioType�	iteritems�range�unicode)�InsensitiveDict)�	XMLParser�
ParseErrorcCsPg}|j}|g}x:t|�dkrJ|�d�}|j|kr:||�|j|dd�<qW|S)a3
    Return a list of all child elements of C{iNode} with a name matching
    C{name}.

    Note that this implementation does not conform to the DOM Level 1 Core
    specification because it may return C{iNode}.

    @param iNode: An element at which to begin searching.  If C{iNode} has a
        name matching C{name}, it will be included in the result.

    @param name: A C{str} giving the name of the elements to return.

    @return: A C{list} of direct or indirect child elements of C{iNode} with
        the name C{name}.  This may include C{iNode}.
    rN)�append�len�pop�nodeName�
childNodes)�iNode�name�matches�matches_append�slice�c�r�G/opt/alt/python37/lib64/python3.7/site-packages/twisted/web/microdom.py�getElementsByTagName s

rcCs\|��}g}|j}|g}x>t|�dkrV|�d�}|j��|krF||�|j|dd�<qW|S)Nr)�lowerrrr
rr)rrrrrrrrr�getElementsByTagNameNoCase<s
rcs*t��tkr�fdd�}n�fdd�}|S)Ncs"t|t�r|�d�}��|�dS)Nzutf-8)�
isinstancer�encode�write)�s)�streamrr�wLs

z_streamWriteWrapper.<locals>.wcs"t|t�r|�d�}��|�dS)Nzutf-8)r�bytes�decoder)r)rrrr Qs

)rr!)rr r)rr�_streamWriteWrapperJsr#))�&z&amp;)�<z&lt;)�>z&gt;)�"z&quot;))�'z&apos;cCs"x|D]\}}|�||�}qW|S)z1
    Perform the exact opposite of 'escape'.
    )�replace)�text�charsr�hrrr�unescapecsr-cCs"x|D]\}}|�||�}qW|S)z;
    Escape a few XML special chars with XML entities.
    )r))r*r+rr,rrr�escapemsr.c@seZdZdd�Zdd�ZdS)�MismatchedTagscCs2|||||||f\|_|_|_|_|_|_|_dS)N)�filename�expect�got�begLine�begCol�endLine�endCol)�selfr0r1r2r5r6r3r4rrr�__init__yszMismatchedTags.__init__cCs d|j|j|j|j|j|jfS)NzBexpected </%s>, got </%s> line: %s col: %s, began line: %s col: %s)r1r2r5r6r3r4)r7rrr�__str__~szMismatchedTags.__str__N)�__name__�
__module__�__qualname__r8r9rrrrr/wsr/c@s�eZdZdZd"dd�Zdd�Zddddidfdd	�Zddddidfd
d�Zd#dd�Zd$dd�Z	d%dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd d!�ZdS)&�NodeNcCs||_g|_dS)N)�
parentNoder)r7r>rrrr8�sz
Node.__init__cCsFt|j�t|j�krdSx(t|j|j�D]\}}|�|�s(dSq(WdS)a
        Compare this node to C{other}.  If the nodes have the same number of
        children and corresponding children are equal to each other, return
        C{True}, otherwise return C{False}.

        @type other: L{Node}
        @rtype: C{bool}
        FT)rr�zip�
isEqualToNode)r7�other�a�brrrr@�s	
zNode.isEqualToNode�rcCs
t��dS)N)�NotImplementedError)r7r�indent�	addindent�newl�strip�
nsprefixes�	namespacerrr�writexml�sz
Node.writexmlc		Cs(t�}|�|||||||�|��}|S)N)rrL�getvalue)	r7rFrGrHrIrJrKr�rvrrr�toxml�sz
Node.toxml� �
cCs|�|||||�S)N)rL)r7rrFrGrHrIrrr�writeprettyxml�szNode.writeprettyxmlcCs|�||||�S)N)rO)r7rFrGrHrIrrr�toprettyxml�szNode.toprettyxmlcCs
t��dS)N)rE)r7�deep�parentrrr�	cloneNode�szNode.cloneNodecCs|jr
dSdSdS)N�r)r)r7rrr�
hasChildNodes�szNode.hasChildNodescCs(t|t�std��|j�|�||_dS)z�
        Make the given L{Node} the last child of this node.

        @param child: The L{Node} which will become a child of this node.

        @raise TypeError: If C{child} is not a C{Node} instance.
        zexpected Node instanceN)rr=�	TypeErrorrrr>)r7�childrrr�appendChild�s
zNode.appendChildcCs@t|t�rt|t�std��|j�|�}||_|j�||�|S)a�
        Make the given L{Node} C{new} a child of this node which comes before
        the L{Node} C{ref}.

        @param new: A L{Node} which will become a child of this node.

        @param ref: A L{Node} which is already a child of this node which
            C{new} will be inserted before.

        @raise TypeError: If C{new} or C{ref} is not a C{Node} instance.

        @return: C{new}
        zexpected Node instance)rr=rYr�indexr>�insert)r7�new�ref�irrr�insertBefore�szNode.insertBeforecCs2t|t�std��||jkr.|j�|�d|_|S)a7
        Remove the given L{Node} from this node's children.

        @param child: A L{Node} which is a child of this node which will no
            longer be a child of this node after this method is called.

        @raise TypeError: If C{child} is not a C{Node} instance.

        @return: C{child}
        zexpected Node instanceN)rr=rYr�remover>)r7rZrrr�removeChild�s

zNode.removeChildcCsPt|t�rt|t�std��|j|k	r.td��||j|j�|�<d|_||_dS)a�
        Replace a L{Node} which is already a child of this node with a
        different node.

        @param newChild: A L{Node} which will be made a child of this node.

        @param oldChild: A L{Node} which is a child of this node which will
            give up its position to C{newChild}.

        @raise TypeError: If C{newChild} or C{oldChild} is not a C{Node}
            instance.

        @raise ValueError: If C{oldChild} is not a child of this C{Node}.
        zexpected Node instancez$oldChild is not a child of this nodeN)rr=rYr>�
ValueErrorrr\)r7ZnewChildZoldChildrrr�replaceChild�s
zNode.replaceChildcCs
|jdS)N���)r)r7rrr�	lastChild
szNode.lastChildcCst|j�r|jdSdS)Nr)rr)r7rrr�
firstChilds

zNode.firstChild)N)rDrPrQr)rDrPrQr)rN)r:r;r<rr8r@rLrOrRrSrVrXr[rarcrergrhrrrrr=�s"




r=c@s�eZdZddd�Zddd�ZdZdd�ZeZd	d
�Ze	e�Z
dd�Zd
d
d
did
fdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�DocumentNcCst�|�|r|�|�dS)N)r=r8r[)r7�documentElementrrrr8&s
zDocument.__init__rcCs6t�}|j|_|r"|j�d|�}n|j}|�|�|S)NrW)ri�doctyperjrVr[)r7rTrU�dZnewElrrrrV,s
zDocument.cloneNodecCs|j|jkot�||�S)N)rkr=r@)r7�nrrr�isEqualToDocument8szDocument.isEqualToDocumentcCs
|jdS)Nr)r)r7rrr�get_documentElement=szDocument.get_documentElementcCs|jrtd��t�||�dS)a
        Make the given L{Node} the I{document element} of this L{Document}.

        @param child: The L{Node} to make into this L{Document}'s document
            element.

        @raise ValueError: If this document already has a document element.
        zOnly one element per document.N)rrdr=r[)r7rZrrrr[Bs	zDocument.appendChildrDc		CsHt|�}|d|�|jr,|d�|j|��|j�|||||||�dS)Nz<?xml version="1.0"?>z<!DOCTYPE {}>{})r#rk�formatrjrL)	r7rrFrGrHrIrJrKr rrrrLPszDocument.writexmlcKst|f|�S)N)�Element)r7r�kwrrr�
createElement\szDocument.createElementcCst|�S)N)�Text)r7r*rrr�createTextNode`szDocument.createTextNodecCst|�S)N)�Comment)r7r*rrr�
createCommentdszDocument.createCommentcCs|jjrt||�St||�S)N)rj�caseInsensitiverr)r7rrrrrhs
zDocument.getElementsByTagNamecCsT|jdd�}x@|rN|�d�}|jr0|�|j�t|d�r|�d�|kr|SqWdS)Nr�getAttribute�id)rr
�extend�hasattrry)r7rzr�noderrr�getElementByIdns
zDocument.getElementById)N)rN)r:r;r<r8rVrkrnr@ro�propertyrjr[rLrsrurwrr~rrrrri$s


ric@sBeZdZddd�Zdd�ZeZddddidfdd	�Zd
d
d�ZdS)�EntityReferenceNcCs*t�||�||_d|d|_|_dS)Nr$�;)r=r8�eref�	nodeValue�data)r7r�r>rrrr8{szEntityReference.__init__cCs&t|t�sdS|j|jko$|j|jkS)Nr)rr�r�r�)r7rmrrr�isEqualToEntityReference�s
z(EntityReference.isEqualToEntityReferencerDrc	Cst|�}|d|j�dS)NrD)r#r�)	r7rrFrGrHrIrJrKr rrrrL�szEntityReference.writexmlcCst|j|�S)N)r�r�)r7rTrUrrrrV�szEntityReference.cloneNode)N)rN)r:r;r<r8r�r@rLrVrrrrr�ys
r�c@s"eZdZddd�Zdd�ZeZdS)�
CharacterDataNcCs"t�||�||_|_|_dS)N)r=r8�valuer�r�)r7r�r>rrrr8�szCharacterData.__init__cCs|j|jkS)N)r�)r7rmrrr�isEqualToCharacterData�sz$CharacterData.isEqualToCharacterData)N)r:r;r<r8r�r@rrrrr��s
r�c@s0eZdZdZddddidfdd�Zd	dd�ZdS)
rvz
    A comment node.
    rDrc
Cs t|�}|j}	|d�|	��dS)Nz	<!--{}-->)r#r�rp)
r7rrFrGrHrIrJrKr �valrrrrL�szComment.writexmlNcCst|j|�S)N)rvr�)r7rTrUrrrrV�szComment.cloneNode)rN)r:r;r<�__doc__rLrVrrrrrv�srvc@sFeZdZddd�Zdd�Zddd�Zd	d	d	did	fd
d�Zdd
�ZdS)rtNrcCst�|||�||_dS)N)r�r8�raw)r7r�r>r�rrrr8�sz
Text.__init__cCst�||�o|j|jkS)z�
        Compare this text to C{text}.  If the underlying values and the C{raw}
        flag are the same, return C{True}, otherwise return C{False}.
        )r�r@r�)r7rArrrr@�szText.isEqualToNodecCst|j||j�S)N)rtr�r�)r7rTrUrrrrV�szText.cloneNoderDcCspt|�}|jr.|j}	t|	ttf�sdt|j�}	n6|j}
t|
ttf�sJt|
�}
|r\d�|
���}
t|
�}	||	�dS)NrP)	r#r�r�r�strr�join�splitr.)r7rrFrGrHrIrJrKr r��vrrrrL�sz
Text.writexmlcCsdt|j�dS)NzText(%s�))�reprr�)r7rrr�__repr__�sz
Text.__repr__)Nr)rN)r:r;r<r8r@rVrLr�rrrrrt�s


rtc@s,eZdZddd�Zddddidfdd�ZdS)	�CDATASectionrNcCst|j|�S)N)r�r�)r7rTrUrrrrV�szCDATASection.cloneNoderDc	Cs*t|�}|d�|d|j�|d�dS)Nz	<![CDATA[rDz]]>)r#r�)	r7rrFrGrHrIrJrKr rrrrL�szCDATASection.writexml)rN)r:r;r<rVrLrrrrr��s
r�ccs$d}xdt|�V|d}qWdS)Nr�prW)r�)r`rrr�
_genprefix�sr�c@seZdZdZdS)�_Attrz#Support class for getAttributeNode.N)r:r;r<r�rrrrr��sr�c@s�eZdZdZdZdZd'dd�Zdd�Zdd	�Zd
d�Z	dd
�Z
d(dd�Zdd�Zdd�Z
d)dd�Zd*dd�Zdd�Zdd�Zdd�Zdd�Zd d d did fd!d"�Zd#d$�Zd%d&�ZdS)+rqrrWNc	Cs�t�||�|p||_||_|s*|��}|dkr:i|_n,||_x$|j��D]\}	}
t|
�|j|	<qLW|rzt|j|d�|_||_	|_
|_||_||_
||_dS)N)�preserve)r=r8�preserveCaserxr�
attributes�itemsr-r�
endTagNamer�tagName�	_filename�_markposrK)r7r�r�r>r0Zmarkposrxr�rK�kr�rrrr8�s"
zElement.__init__cCs"|jdkr||_n|j�|�dS)N)rJ�update)r7Zpfxsrrr�addPrefixess
zElement.addPrefixescCs|js|��}||_dS)N)r�rr�)r7r�rrr�endTagszElement.endTagcCs>|jr&|j|jko$|j��|j��kS|j|jko<|j|jkS)N)rxr�rr)r7rmrrr�isEqualToElement%szElement.isEqualToElementcCs8|j��|j��ko6|j|jko6|j|jko6t�||�S)z�
        Compare this element to C{other}.  If the C{nodeName}, C{namespace},
        C{attributes}, and C{childNodes} are all the same, return C{True},
        otherwise return C{False}.
        )rrrKr�r=r@)r7rArrrr@,szElement.isEqualToNodecsNt|j||j|j|jd���j�|j�|rD�fdd�|jD��_ng�_�S)N)r>rKr�rxcsg|]}|�d���qS)rW)rV)�.0rZ)�clonerr�
<listcomp>?sz%Element.cloneNode.<locals>.<listcomp>)rqr�rKr�rxr�r�r)r7rTrUr)r�rrV9s
zElement.cloneNodecCs|jrt||�St||�S)N)rxrr)r7rrrrrEs
zElement.getElementsByTagNamecCsdS)NrWr)r7rrr�
hasAttributesKszElement.hasAttributescCs|j�||�S)N)r��get)r7r�defaultrrrryOszElement.getAttributecCs8||f}||jkr|j|S||jkr4|j�||�S|S)N)r�rKr�)r7�nsrr�Znskrrr�getAttributeNSSs


zElement.getAttributeNScCst|�|�|�S)N)r�ry)r7rrrr�getAttributeNode\szElement.getAttributeNodecCs||j|<dS)N)r�)r7r�attrrrr�setAttribute`szElement.setAttributecCs||jkr|j|=dS)N)r�)r7rrrr�removeAttributeds
zElement.removeAttributecCs
||jkS)N)r�)r7rrrr�hasAttributeiszElement.hasAttributerDc
s�d}d}	d}
|js|j|_t|�}|jrT|j��}x$|��D]}
|
|kr<||
=q<Wni}dg}|j|	krt||g|}|j��fdd�}|j}||jkr�|jdk	r�|j|kr�||j}�|d|j�|d|j}q��|j�|d	|j�|j}n
�|j�d
j	}x�t
|j���D]|\}}t
|t��rv|\}
}|
|k�rD||
}ntt�}|||
<|dk	�sbt�||d||�n|dk	�s�t�|||��qW|�r�x*t|�D]\}
}|�r�|d||
��q�W|�|�|}n|}|||��|j�r~|d�||}xN|jD]D}|j|	k�r2|j|
k�r2||||f��|�|||||||��qW|j|	k�rj||||f��||d
|df��n,|j��|k�r�||d|df��n|d�dS)a*
        Serialize this L{Element} to the given stream.

        @param stream: A file-like object to which this L{Element} will be
            written.

        @param nsprefixes: A C{dict} mapping namespace URIs as C{str} to
            prefixes as C{str}.  This defines the prefixes which are already in
            scope in the document at the point at which this L{Element} exists.
            This is essentially an implementation detail for namespace support.
            Applications should not try to use it.

        @param namespace: The namespace URI as a C{str} which is the default at
            the point in the document at which this L{Element} exists.  This is
            essentially an implementation detail for namespace support.
            Applications should not try to use it.
        )
Zimg�br�hr�base�meta�link�paramZarea�input�colZbasefontZisindex�frame)�html�head�bodyZnoscriptZins�delZh1Zh2Zh3Zh4Zh5Zh6�script�ul�olZdl�prer�Z
blockquote�addressr��div�fieldset�table�trZform�objectr�Zapplet�map)r�r�r�r�r%cs�d|dt|�df�S)NrPz="r')r.)Z_atrZ_val)�bextrr�<lambda>��z"Element.writexml.<locals>.<lambda>N�:�xmlnsrDzxmlns:r&z</z></z />)r�r�r�r#rJ�copy�keysr{rKr��sortedr�r�r�tuple�next�	genprefix�AssertionErrorrr�rrLr)r7rrFrGrHrIrJrKZALLOWSINGLETONZ
BLOCKELEMENTSZFORMATNICELYr Znewprefixesr��beginZ	writeattrr��prefix�jr�r��keyZdownprefixesZ	newindentrZr)r�rrLms|








zElement.writexmlcCsXdt|j�}|jr$|d|jf7}|jr:|d|jf7}|jrP|d|jf7}|dS)Nz
Element(%sz, attributes=%rz
, filename=%rz, markpos=%rr�)r�rr�r�r�)r7�reprrrr��szElement.__repr__cCs�d|j}|js|jr|d7}|jr2|t|j�7}|jrF|d|j7}|jsR|jrZ|d7}x|j��D]}|d|7}qfW|��r�|d|j7}n|d7}|S)Nr%z (z line %s column %sr�z %s=%rz
 >...</%s>z />)rr�r�r�r�r�rX)r7r��itemrrrr9�s
zElement.__str__)NNNNrWrN)rN)N)N)r:r;r<r�rxrJr8r�r�r�r@rVrr�ryr�r�r�r�r�rLr�r9rrrrrq�s0



	zrqcCs*i}x |��D]\}}t|�||<qW|S)N)r�r-)rl�ddr�r�rrr�
_unescapeDictsr�cCs&i}x|��D]\}}|||<qW|S)N)r�)rlr�r�r�rrr�_reverseDictsr�c@s�eZdZd��Zddgddgddgdgdddgdddgdddgd	gd
gdgdgd
gdgddgdgd�Zdddeefdd�Zdd�Zdd�Ze	�
d�Zdd�Zdd�Z
dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/S)0�MicroDOMParserz#area link br img hr input base metar��dtr��li�thead�tfoot�tbody�colgroupr�r��td�thr�r��option)r�r�r�r�r�r�r�r�r�r�r�r�r��titler�rrWcCsZg|_ddd�}t|�}|d|fg|_g|_d|_||_||_|pF||_||_||_	dS)Nr�)r�rD)
�elementstackr��nsstack�	documents�
_mddoctype�beExtremelyLenientrxr��soonClosers�laterClosers)r7r�rxr�r�r�rlZdrrrrr80s
zMicroDOMParser.__init__cCsFx@tt|j��D].}|j|}|jdks:|�dd�dkrdSqWdS)Nr�z	xml:spacerDr�rWr)rrr�r�ry)r7Zedx�elrrr�shouldPreserveSpace@s
z"MicroDOMParser.shouldPreserveSpacecCs|jr|jdSdSdS)Nrf)r�)r7rrr�
_getparentHs
zMicroDOMParser._getparentz\s*/[/*]\s*c	Cs�|jrt|j�dksdS|��}t|t�r�d}|j}|j�|�}|r\|�	�}|t|�d�}yt
d|�jd}Wnttfk
r�dSXt|j�dkr�dS|��}t|t
tf�r�g|_|r�|j�t|��|j�|�dS)NrWrDz	<a>%s</a>r)r�rrrhrrtr��COMMENT�match�group�parseStringr
r/r�rvr)r7r�rr�Zoldvaluer��errr�_fixScriptElementPs,
z MicroDOMParser._fixScriptElementcCs
||_dS)N)r�)r7rkrrr�
gotDoctyperszMicroDOMParser.gotDoctypecCs.|��}|jr^t|t�r^|j}|}|jr8|��}|��}||j�|g�kr^|�	|j�|��}t
|�}|jdd}i}g}xV|��D]J\}	}
|	�
d�r�|	�dd�}t|�dkr�|
||d<n|
|d<|�|	�q�Wx|D]
}	||	=q�W|r�|��}|�|�g}xf|��D]Z\}	}
|	�dd�}t|�dk�r|\}
}|
dk�r|
|k�r|
|||
|f<|�|	��qWx|D]}	||	=�qpWt||||j|��|j|j|�d�d	�}t|�}|�|�|�r�|jdd��}|�|�|j�|||f�|j�|�|�r
|�|�|j�r*|j|jk�r*|�	|�dS)
Nrfrr�r�rW�rD�xml)rxr�rK)r�r�rrqr�rxrr�r��	gotTagEndr�r�r��
startswithr�rrr�r�r0�saveMarkr�r�r�r�r[r�)r7rr�rUZ
parentNameZmyNameZ
namespacesZ	newspacesZkeysToDeleter�r�Z
spacenamesZksplit�pfx�tvr�Z	revspacesZrscopyrrr�gotTagStartvsh








zMicroDOMParser.gotTagStartcCs8|��}|||�}|r"|�|�n|jr4|j�|�dS)N)r�r[r�r�r)r7�factoryr�rU�terrr�_gotStandalone�s
zMicroDOMParser._gotStandalonecCs |��s|��r|�t|�dS)N)rIr�rrt)r7r�rrr�gotText�szMicroDOMParser.gotTextcCs|�t|�dS)N)rrv)r7r�rrr�
gotComment�szMicroDOMParser.gotCommentcCs|�t|�dS)N)rr�)r7Z	entityRefrrr�gotEntityReference�sz!MicroDOMParser.gotEntityReferencecCs|�t|�dS)N)rr�)r7Zcdatarrr�gotCData�szMicroDOMParser.gotCDatac
Cs|js,|jrdSt|jd|f|��d��|j��}|jdd}|jdd|krb|j��}nd}|jr�|j�	�}|�	�}n
|j}|}|�
dd�}t|�dkr�|\}}	|�|d�}
|
dk	r�|j
|
kr�|js�t|j|j|f|��|j��||k�s�|j�r�|j�r�|jd}xntt|j��D]6}|j|dj|k�r"|j|d�|�P�q"W|j�|�|dk	�r~|j�|�dS|j|dd�=|j�s�|j�|�dSn t|j|j|f|��|j��|�|�|j�s�|j�|�|j�r
|jdk�r
|�|�dS)	NZNOTHING)rrrfr�rWr�rr�)r�r�r/r0r�r
r�rxr�rr�rr�rKr�rr�rr�r�)
r7rr�ZpfxdixZnstuple�tnZcnameZnsplitr�Znewnamer�ZlastEl�idxrrrr��s^







zMicroDOMParser.gotTagEndcCsZt�||�|jrV|jr,|j�|jd�n*t|j|jddf|��|jdj	��dS)NrrfZEND_OF_FILE)
r	�connectionLostr�r�r�rr/r0r�r�)r7�reasonrrrrszMicroDOMParser.connectionLostN)r:r;r<r�r�r�r8r�r��re�compiler�r�r�rrrrrrr�rrrrrr�s>

";	:r�c	Ost|d�st|d�}t||�}t|dd�|_|�d�t|d�rP|�|���n(|�d�}x|rv|�|�|�d�}q\W|�	d�|j
s�t|jddd	��|jr�t
|j
�d
kr�|j
d}t|t�s�td�}|�|�|}n"td�}x$|j
D]}|�|�q�Wn
|j
d}t|�}|j|_|S)z%
    Parse HTML or XML readable.
    �read�rbrz<xmlfile />NrMirzNo top-level Nodes in documentrWr�)r|�openr��getattrr0ZmakeConnectionZdataReceivedrMrrr�r
r�rrrqr[rir�rk)	�readable�args�kwargsZmdp�rrlr�rZ�docrrr�parses8











rcOs8t|t�r$tt|�d��f|�|�Stt|�f|�|�S)NzUTF-16)rrrrr)�strrrrrrr�:s
r�cCst|ddd�S)z'
    Parse an XML readable object.
    rrW)rxr�)r)rrrr�parseXMLBsrcCst|ddd�S)z'
    Parse an XML readable object.
    rrW)rxr�)r�)rrrr�parseXMLStringJsrc@sDeZdZdZddd�Zdd�Zdd�Zd	d
�Zddd
�Zdd�Z	dS)�lmxz
    Easy creation of XML.
    r�cCs t|ttf�rt|�}||_dS)N)rr�rrqr})r7r}rrrr8Wszlmx.__init__cs"�ddkrtd����fdd�S)Nr�_zno private attrscs�j�f|�S)N)�add)rr)rr7rrr�`r�z!lmx.__getattr__.<locals>.<lambda>)�AttributeError)r7rr)rr7r�__getattr__]szlmx.__getattr__cCs|j�||�dS)N)r}r�)r7r�r�rrr�__setitem__cszlmx.__setitem__cCs|j�|�S)N)r}ry)r7r�rrr�__getitem__gszlmx.__getitem__rcCst||d�}|j�|�|S)N)r�)rtr}r[)r7Ztxtr��nnrrrr*kszlmx.textcKs\t|ddd�}|j�|�t|�}x4|��D](\}}|ddkrL|dd�}|||<q,W|S)Nr)rxr�rrW)rqr}r[rr�)r7r�rrZnewNodeZxfr�r�rrrrqszlmx.addN)r�)r)
r:r;r<r�r8r r!r"r*rrrrrrRs

r)0r�r
�iorrZtwisted.python.compatrrrrZtwisted.python.utilrZtwisted.web.suxr	r
rrr#ZHTML_ESCAPE_CHARS�listZREV_HTML_ESCAPE_CHARS�reverseZXML_ESCAPE_CHARSZREV_XML_ESCAPE_CHARSr-r.�	Exceptionr/r�r=rir�r�rvrtr�r�r�r�rqr�r�r�rr�rrrrrrr�<module>sP

 U
+|(