%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/web/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/web/test/__pycache__/test_domhelpers.cpython-312.pyc

�

Ϫ�f�,���dZddlmZddlmZmZddlmZddlm	Z	ddl
mZmZGd�d�Z
Gd	�d
e
e	�ZGd�de
e	�Zy
)zH
Specific tests for (some of) the methods in L{twisted.web.domhelpers}.
�)�reload)�Any�Optional)�minidom)�TestCase)�
domhelpers�microdomc�t�eZdZUdZdZeeed<d�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zy)�DOMHelpersTestsMixinz�
    A mixin for L{TestCase} subclasses which defines test methods for
    domhelpers functionality based on a DOM creation function provided by a
    subclass.
    N�domc���|jjd�}tj|d�dj}d}|j||�|j}tj|d�dj}|j||�d}|jj|�}tj|d�}dj|D�cgc]}|jd���c}�}d}|j||�|j}	tj|	d�}dj|D�cgc]}|jd���c}�}|j||�d}
|jj|
�}tj|d�}dj|D�cgc]}|jd���c}�}d	}|j||�|j}tj|d�}dj|D�cgc]}|jd���c}�}|j||�d
}
|jj|
�}tj|d�}|j}||jdjdg}|j||�tj|d�}|j||�ycc}wcc}wcc}wcc}w)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>��in�abcdefghaH
<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>�
abdgheicfjz'<foo><bar></bar><baz><foo/></baz></foo>���)
r�parseStringr�getElementsByTagName�nodeName�assertEqual�documentElement�join�getAttribute�
childNodes)�self�doc1�actual�expected�el1�doc2_xml�doc2�tag_list�node�el2�doc3_xml�doc3�el3�doc4_xml�doc4�roots                �B/usr/lib/python3/dist-packages/twisted/web/test/test_domhelpers.py�test_getElementsByTagNamez.DOMHelpersTestsMixin.test_getElementsByTagNames����x�x�#�#�H�-���0�0��u�=�a�@�I�I���������*��"�"���0�0��e�<�Q�?�H�H�������*�U���x�x�#�#�H�-���2�2�4��?�����h�G�d�$�+�+�D�1�G�H���������*��"�"���2�2�3��>�����h�G�d�$�+�+�D�1�G�H�������*���"�x�x�#�#�H�-���2�2�4��?�����h�G�d�$�+�+�D�1�G�H���������*��"�"���2�2�3��>�����h�G�d�$�+�+�D�1�G�H�������*�<���x�x�#�#�H�-���0�0��u�=���#�#���$�/�/�"�-�8�8��;�<�������*��0�0��u�=�������*��UH��
H��,H��
Hs�K�:K�-K$�K)c���|jjd�}tj|�}d}|j	||�tj|j
�}|j	||�d}|jj|�}tj|�}d}|j	||�tj|j
�}|j	||�d}|jj|�}tj|�}d}|j	||�tj|j
�}|j	||�y)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�rrr�gatherTextNodesrr)rrrrr!r"r&r's        r,�test_gatherTextNodesz)DOMHelpersTestsMixin.test_gatherTextNodesQs0���x�x�#�#�L�1���+�+�D�1���������*��+�+�D�,@�,@�A�������*�@���x�x�#�#�H�-���+�+�D�1���������*��+�+�D�,@�,@�A�������*�
-�	��x�x�#�#�H�-���+�+�D�1���������*��+�+�D�,@�,@�A�������*�c��|jjd�}|j}tj|�|j|j
�|jjd�j
��|jjd�}|jjd}tj|�|jj
�}|jjd�}|j|jjd��|j||j
��y)Nz<a><b><c><d/></c></b></a>�ar�b)
rrrr�	clearNoder�toxml�Elementr�appendChild)rr�a_noder"�b_noderrs       r,�test_clearNodez#DOMHelpersTestsMixin.test_clearNodels����x�x�#�#�$?�@���%�%�����V�$�����������)9�)9�#�)>�)D�)D�)F�G��x�x�#�#�$?�@���%�%�0�0��3�����V�$��%�%�+�+�-���8�8�#�#�C�(�����T�X�X�-�-�c�2�3��������!1�2r2c�r�|jjd�}|jj�}tj|d�}|j�}|j
d�}|jdd�|j||j��tj|d�}|j�}|j
d�}|jdd�|j||j��|jtjtj|d�y)	N�$<a><b id="bar"/><c class="foo"/></a>r�c�class�barr5�id�pzork)rr�Documentr�getr7�
createElement�setAttributer�assertRaises�NodeLookupError�rr�docr$rrs      r,�test_getzDOMHelpersTestsMixin.test_getzs����x�x�#�#�$J�K���h�h���!���~�~�d�E�*��������$�$�S�)�����g�u�-��������!1�2��~�~�d�E�*��������$�$�S�)�����d�E�*��������!1�2����*�4�4�j�n�n�d�G�Tr2c��|jjd�}|jj�}tj|d�}|j�}|j
d�}|jdd�|j||j��tj|d�}|j|d�y)Nr>rr?r@rC)
rrrDr�getIfExistsr7rFrGr�assertIdenticalrJs      r,�test_getIfExistsz%DOMHelpersTestsMixin.test_getIfExists�s����x�x�#�#�$J�K���h�h���!���%�%�d�E�2��������$�$�S�)�����g�u�-��������!1�2��%�%�d�G�4�����T�4�(r2c�@�|jjd�}|jj�}tj|d�}|j�}|j
d�}|jdd�|j||j��y)Nz<a><b id="foo"><c></c></b></a>rr5rB)	rrrDr�getAndClearr7rFrGrrJs      r,�test_getAndClearz%DOMHelpersTestsMixin.test_getAndClear�s}���x�x�#�#�$D�E���h�h���!���%�%�d�E�2��������$�$�S�)�����d�E�*��������!1�2r2c��|jjd�}|jj�}tj|j
ddd��}dj
|D�cgc]}|j���c}�}|jd�}|jdd�|jd�}|jdd�|j|�|j||j��tj|j
ddd	��}dj
|D�cgc]}|j���c}�}|j||j�|j�z�ycc}wcc}w)
Nz:<a><b foo="olive"><c foo="olive"/></b><d foo="poopy"/></a>r�olive�)�	noNestingrr5r?r)rrrDr�locateNodesrrr7rFrGr9r)rrrK�	node_listr$rrr?s        r,�test_locateNodesz%DOMHelpersTestsMixin.test_locateNodes�s0���x�x�#�#�H�
���h�h���!���*�*�4�?�?�E�7�VW�X�	����9�=�4�$�*�*�,�=�>���$�$�S�)�����e�W�-����c�"��	���u�g�&����Q���������!1�2��*�*�4�?�?�E�7�VW�X�	����9�=�4�$�*�*�,�=�>���������!1�A�G�G�I�!=�>��>��>s�(E?�/Fc	�L�|jjd�}tj|jdjdjd�}dj|D�cgc]}t
|d�s�|j��c}�}|j|d�ycc}w)Nz!<a><b><c><d/></c><e/></b><f/></a>rr�tagName�cba)	rrr�
getParentsrr�hasattrr\r�rrrYr$rs     r,�test_getParentsz$DOMHelpersTestsMixin.test_getParents�s����x�x�#�#�$G�H���)�)��O�O�A��)�)�!�,�7�7��:�
�	����&/�L�d�7�4��3K�T�\�\�L�
��	
�����'��
Ms�'B!�9B!c��|jjd�}tj|d�}dj	|D�cgc]}|j
��c}�}|j
|d�tj|dd�}dj	|D�cgc]}|j
��c}�}|j
|d�ycc}wcc}w)Nz+<a foo="1"><b foo="2"/><c foo="1"/><d/></a>rr�abc�1�ac)rrr�findElementsWithAttributerr\rr`s     r,�test_findElementsWithAttributez3DOMHelpersTestsMixin.test_findElementsWithAttribute�s����x�x�#�#�$Q�R���8�8��u�E�	����9�=�4�$�,�,�=�>�������'��8�8��u�c�J�	����9�=�4�$�,�,�=�>�������&��>��>s�C�Cc��|jjd�}tj|d�}t	|�}|j|d�y)Nz#<doc><foo/><bar/><foo>a</foo></doc>r�)rrr�findNodesNamed�lenr)rrrYrs    r,�test_findNodesNamedz(DOMHelpersTestsMixin.test_findNodesNamed�sB���x�x�#�#�$I�J���-�-�d�E�:�	��Y��������#r2c�V�d}d}|jtj|�|�y)Nz9this string " contains many & characters> xml< won't likezHthis string &quot; contains many &amp; characters&gt; xml&lt; won't like)rr�escape�r�jrs   r,�test_escapez DOMHelpersTestsMixin.test_escape�s,��H��V�	�	
����*�*�1�-�x�8r2c�V�d}d}|jtj|�|�y)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<)rr�unescaperos   r,�
test_unescapez"DOMHelpersTestsMixin.test_unescape�s,��b��T�	�	
����,�,�Q�/��:r2c��|jjd�}|jtj|�d�y)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>�bazquuxN)rrrr�getNodeText)rr$s  r,�test_getNodeTextz%DOMHelpersTestsMixin.test_getNodeText�s4��
�x�x�#�#�$N�O������/�/��5�y�Ar2)�__name__�
__module__�__qualname__�__doc__rrr�__annotations__r-r1r<rLrPrSrZrargrlrqrtrx�r2r,rrs[����C��#���6+�p+�63�U�"
)�3�?�&(�'�$�9�;�Br2rc�"�eZdZeZd�Zd�Zd�Zy)�MicroDOMHelpersTestsc���d}|jj|�}tj|�}d}|j	||�tj|j
�}|j	||�y)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*rrs     r,�#test_gatherTextNodesDropsWhitespacez8MicroDOMHelpersTests.test_gatherTextNodesDropsWhitespace�sj��
���x�x�#�#�H�-���+�+�D�1��$�������*��+�+�D�,@�,@�A�������*r2c���d}|jj|�}tj|�}d}|j	||�tj|j
�}|j	||�y)zB
        Microdom does not decode entities in text nodes.
        �<x>Souffl&amp;</x>zSouffl&amp;Nr/�r�doc5_xml�doc5rrs     r,�test_textEntitiesNotDecodedz0MicroDOMHelpersTests.test_textEntitiesNotDecoded�sh��(���x�x�#�#�H�-���+�+�D�1�� �������*��+�+�D�,@�,@�A�������*r2c��tt�|j|jg�}|j	dt|��|j	d|dd�y)z?
        An import will raise the deprecation warning.
        rVz8twisted.web.domhelpers was deprecated at Twisted 23.10.0r�messageN)rr�
flushWarnings�test_deprecationrrk)r�warningss  r,r�z%MicroDOMHelpersTests.test_deprecationsV��	�z���%�%�t�'<�'<�&=�>������C��M�*����F��Q�K�	�"�	
r2N)ryrzr{r	rr�r�r�r~r2r,r�r��s��
�C�+�(
+�

r2r�c��eZdZeZd�Zd�Zy)�MiniDOMHelpersTestsc���d}|jj|�}tj|�}d}|j	||�tj|j
�}|j	||�y)z=
        Minidom does decode entities in text nodes.
        r�zSouffl&Nr/r�s     r,�test_textEntitiesDecodedz,MiniDOMHelpersTests.test_textEntitiesDecodedsh��(���x�x�#�#�H�-���+�+�D�1���������*��+�+�D�,@�,@�A�������*r2c��|jjd�}tj|�}|j	|d�|j|t�|jjdj��}tj|�}|j	|d�|j|t�y)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>rAu<foo>☃</foo>u☃N)rrrrwr�assertIsInstance�str�encode)rr$�texts   r,�test_getNodeUnicodeTextz+MiniDOMHelpersTests.test_getNodeUnicodeText#s����x�x�#�#�$4�5���%�%�d�+������u�%����d�C�(��x�x�#�#�$<�$C�$C�$E�F���%�%�d�+������}�-����d�C�(r2N)ryrzr{rrr�r�r~r2r,r�r�s��
�C�
+�)r2r�N)r|�	importlibr�typingrr�xml.domr�twisted.trial.unittestr�twisted.webrr	rr�r�r~r2r,�<module>r�sI��
�� ��+�,�QB�QB�h-
�/��-
�`)�.��)r2

Zerion Mini Shell 1.0