HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_domhelpers.cpython-38.pyc
U


W[_+�@sndZddlmZddlmZddlmZddlmZm	Z	Gdd�d�Z
Gdd	�d	e
e�ZGd
d�de
e�ZdS)
zH
Specific tests for (some of) the methods in L{twisted.web.domhelpers}.
�)�minidom)�unicode)�TestCase)�
domhelpers�microdomc@s|eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�DOMHelpersTestsMixinz�
    A mixin for L{TestCase} subclasses which defines test methods for
    domhelpers functionality based on a DOM creation function provided by a
    subclass.
    NcCs�|j�d�}t�|d�dj}d}|�||�|j}t�|d�dj}|�||�d}|j�|�}t�|d�}d�dd�|D��}d}|�||�|j}t�|d�}d�d	d�|D��}|�||�d
}	|j�|	�}
t�|
d�}d�dd�|D��}d}|�||�|
j}t�|d�}d�d
d�|D��}|�||�d}|j�|�}
t�|
d�}|
j}||jdjdg}|�||�t�|d�}|�||�dS)Nz<foo/>�foorz<a><foo in="a"/><b><foo in="b"/></b><c><foo in="c"/></c><foo in="d"/><foo in="ef"/><g><foo in="g"/><h><foo in="h"/></h></g></a>�cSsg|]}|�d��qS��in�ZgetAttribute��.0�node�r�B/usr/lib/python3/dist-packages/twisted/web/test/test_domhelpers.py�
<listcomp>$szBDOMHelpersTestsMixin.test_getElementsByTagName.<locals>.<listcomp>�abcdefghcSsg|]}|�d��qSr
rr
rrrr)saH
<a><foo in="a"/>
    <b><foo in="b"/>
        <d><foo in="d"/>
            <g><foo in="g"/></g>
            <h><foo in="h"/></h>
        </d>
        <e><foo in="e"/>
            <i><foo in="i"/></i>
        </e>
    </b>
    <c><foo in="c"/>
        <f><foo in="f"/>
            <j><foo in="j"/></j>
        </f>
    </c>
</a>cSsg|]}|�d��qSr
rr
rrrr?s�
abdgheicfjcSsg|]}|�d��qSr
rr
rrrrDsz'<foo><bar></bar><baz><foo/></baz></foo>���)	�dom�parseStringrZgetElementsByTagNameZnodeName�assertEqual�documentElement�join�
childNodes)�self�doc1�actual�expectedZel1�doc2_xml�doc2Ztag_listZel2�doc3_xml�doc3Zel3�doc4_xml�doc4�rootrrr�test_getElementsByTagNamesFz.DOMHelpersTestsMixin.test_getElementsByTagNamecCs�|j�d�}t�|�}d}|�||�t�|j�}|�||�d}|j�|�}t�|�}d}|�||�t�|j�}|�||�d}|j�|�}t�|�}d}|�||�t�|j�}|�||�dS)Nz
<a>foo</a>rz+<a>a<b>b</b><c>c</c>def<g>g<h>h</h></g></a>rzP<a>a<b>b<d>d<g>g</g><h>h</h></d><e>e<i>i</i></e></b><c>c<f>f<j>j</j></f></c></a>r�rrrZgatherTextNodesrr)rrrrr r!r"r#rrr�test_gatherTextNodesQs(


z)DOMHelpersTestsMixin.test_gatherTextNodescCs�|j�d�}|j}t�|�|�|��|j�d����|j�d�}|jjd}t�|�|j��}|j�d�}|�	|j�d��|�||���dS)Nz<a><b><c><d/></c></b></a>�ar�b)
rrrrZ	clearNoder�toxmlZElementr�appendChild)rrZa_noder!Zb_noderrrrr�test_clearNodeks
�

z#DOMHelpersTestsMixin.test_clearNodecCs�|j�d�}|j��}t�|d�}|��}|�d�}|�dd�|�||���t�|d�}|��}|�d�}|�dd�|�||���|�	tj
tj|d�dS)	N�$<a><b id="bar"/><c class="foo"/></a>r�c�class�barr+�id�pzork)rr�Documentr�getr,�
createElement�setAttributerZassertRaisesZNodeLookupError�rr�docrrrrrr�test_get|s"


�zDOMHelpersTestsMixin.test_getcCsl|j�d�}|j��}t�|d�}|��}|�d�}|�dd�|�||���t�|d�}|�	|d�dS)Nr/rr0r1r4)
rrr5rZgetIfExistsr,r7r8rZassertIdenticalr9rrr�test_getIfExists�s

z%DOMHelpersTestsMixin.test_getIfExistscCsT|j�d�}|j��}t�|d�}|��}|�d�}|�dd�|�||���dS)Nz<a><b id="foo"><c></c></b></a>rr+r3)	rrr5rZgetAndClearr,r7r8rr9rrr�test_getAndClear�s

z%DOMHelpersTestsMixin.test_getAndClearcCs�|j�d�}|j��}tj|jdddd�}d�dd�|D��}|�d	�}|�dd�|�d
�}|�dd�|�	|�|�
||���tj|jdddd�}d�dd�|D��}|�
||��|���dS)
Nz:<a><b foo="olive"><c foo="olive"/></b><d foo="poopy"/></a>rZolive�)Z	noNestingr	cSsg|]}|���qSr�r,r
rrrr�sz9DOMHelpersTestsMixin.test_locateNodes.<locals>.<listcomp>r+r0rcSsg|]}|���qSrr?r
rrrr�s)rrr5rZlocateNodesrrr7r8r-rr,)rrr:�	node_listrrr0rrr�test_locateNodes�s.
�


�z%DOMHelpersTestsMixin.test_locateNodescCsL|j�d�}t�|jdjdjd�}d�dd�|D��}|�|d�dS)Nz!<a><b><c><d/></c><e/></b><f/></a>rr	cSsg|]}t|d�r|j�qS��tagName)�hasattrrCr
rrrr�s
�z8DOMHelpersTestsMixin.test_getParents.<locals>.<listcomp>Zcba)rrrZ
getParentsrrr�rrr@rrrr�test_getParents�s�z$DOMHelpersTestsMixin.test_getParentscCsj|j�d�}t�|d�}d�dd�|D��}|�|d�t�|dd�}d�dd�|D��}|�|d	�dS)
Nz+<a foo="1"><b foo="2"/><c foo="1"/><d/></a>rr	cSsg|]
}|j�qSrrBr
rrrr�szGDOMHelpersTestsMixin.test_findElementsWithAttribute.<locals>.<listcomp>�abc�1cSsg|]
}|j�qSrrBr
rrrr�sZac)rrrZfindElementsWithAttributerrrErrr�test_findElementsWithAttribute�sz3DOMHelpersTestsMixin.test_findElementsWithAttributecCs0|j�d�}t�|d�}t|�}|�|d�dS)Nz#<doc><foo/><bar/><foo>a</foo></doc>r�)rrrZfindNodesNamed�lenrrErrr�test_findNodesNamed�sz(DOMHelpersTestsMixin.test_findNodesNamedcCsd}d}|�t�|�|�dS)Nz9this string " contains many & characters> xml< won't likezHthis string &quot; contains many &amp; characters&gt; xml&lt; won't like)rr�escape�r�jrrrr�test_escape�sz DOMHelpersTestsMixin.test_escapecCsd}d}|�t�|�|�dS)NzTthis string &quot; has &&amp; entities &gt; &lt; and some characters xml won't like<zEthis string " has && entities > < and some characters xml won't like<)rrZunescaperNrrr�
test_unescape�sz"DOMHelpersTestsMixin.test_unescapecCs"|j�d�}|�t�|�d�dS)z|
        L{getNodeText} returns the concatenation of all the text data at or
        beneath the node passed to it.
        z(<foo><bar>baz</bar><bar>quux</bar></foo>ZbazquuxN)rrrr�getNodeText)rrrrr�test_getNodeText�sz%DOMHelpersTestsMixin.test_getNodeText)�__name__�
__module__�__qualname__�__doc__rr'r)r.r;r<r=rArFrIrLrPrQrSrrrrrs9

	rc@s eZdZeZdd�Zdd�ZdS)�MicroDOMHelpersTestscCsFd}|j�|�}t�|�}d}|�||�t�|j�}|�||�dS)z�
        Microdom discards whitespace-only text nodes, so L{gatherTextNodes}
        returns only the text from nodes which had non-whitespace characters.
        z?<html>
  <head>
  </head>
  <body>
    stuff
  </body>
</html>
z
    stuff
  Nr()rr$r%rrrrr�#test_gatherTextNodesDropsWhitespace�s
z8MicroDOMHelpersTests.test_gatherTextNodesDropsWhitespacecCsFd}|j�|�}t�|�}d}|�||�t�|j�}|�||�dS)zB
        Microdom does not decode entities in text nodes.
        �<x>Souffl&amp;</x>zSouffl&amp;Nr(�rZdoc5_xmlZdoc5rrrrr�test_textEntitiesNotDecodeds
z0MicroDOMHelpersTests.test_textEntitiesNotDecodedN)rTrUrVrrrYr\rrrrrX�srXc@s eZdZeZdd�Zdd�ZdS)�MiniDOMHelpersTestscCsFd}|j�|�}t�|�}d}|�||�t�|j�}|�||�dS)z=
        Minidom does decode entities in text nodes.
        rZzSouffl&Nr(r[rrr�test_textEntitiesDecodeds
z,MiniDOMHelpersTests.test_textEntitiesDecodedcCsf|j�d�}t�|�}|�|d�|�|t�|j�d�d��}t�|�}|�|d�|�|t�dS)z�
        L{domhelpers.getNodeText} returns a C{unicode} string when text
        nodes are represented in the DOM with unicode, whether or not there
        are non-ASCII characters present.
        z<foo>bar</foo>r2u<foo>☃</foo>zutf-8u☃N)rrrrRrZassertIsInstancer�encode)rr�textrrr�test_getNodeUnicodeText#s

z+MiniDOMHelpersTests.test_getNodeUnicodeTextN)rTrUrVrrr^rarrrrr]s
r]N)
rWZxml.domrZtwisted.python.compatrZtwisted.trial.unittestrZtwisted.webrrrrXr]rrrr�<module>s^&