%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_util.cpython-312.pyc

�

Ϫ�f
;��`�dZddlZddlmZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZdd	lmZdd
lmZddlmZmZmZddlmZmZdd
lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$Gd�de
�Z%Gd�de	�Z&Gd�de
�Z'Gd�de
�Z(Gd�dejR�Z*Gd�de	�Z+y)z 
Tests for L{twisted.web.util}.
�N)�defer)�
networkString)�Failure)�SynchronousTestCase�TestCase)�resource�util)�FlattenerError)�FOUND)�Request)�	TagLoader�
flattenString�tags)�DummyChannel�DummyRequest)	�DeferredResource�FailureElement�ParentRedirect�
_FrameElement�_SourceFragmentElement�_SourceLineElement�
_StackElement�
formatFailure�
redirectToc�(�eZdZdZd�Zd�Zd�Zd�Zy)�RedirectToTestsz"
    Tests for L{redirectTo}.
    c�F�tt�d�}d|_d}t||�|j	|j
t�|j	|jjd�|g�|j	|jjd�dg�y)z�
        L{redirectTo} will set the C{Location} and C{Content-Type} headers on
        its request, and set the response code to C{FOUND}, so the browser will
        be redirected.
        T�GETshttp://target.example.com/4321slocationscontent-typestext/html; charset=utf-8N)	rr�methodr�assertEqual�coder�responseHeaders�
getRawHeaders��self�request�	targetURLs   �</usr/lib/python3/dist-packages/twisted/web/test/test_util.py�test_headersAndCodez#RedirectToTests.test_headersAndCode&s����,�.�$�/�����5�	��9�g�&�������u�-�����#�#�1�1�+�>���	
�	
����#�#�1�1�/�B�
(�)�	
�c�v�tt�d�}d|_d}|jtt
||�y)zW
        L{redirectTo} will raise TypeError if unicode object is passed in URL
        Trzhttp://target.example.com/4321N)rrr�assertRaises�	TypeErrorrr$s   r(�test_redirectToUnicodeURLz)RedirectToTests.test_redirectToUnicodeURL9s2���,�.�$�/�����4�	����)�Z��G�Dr*c�\�tdg�}td|�}d}|j||�y)zq
        Legitimate URLs are fully interpolated in the `redirectTo` response body without transformation
        r*shttps://twisted.org/s�
<html>
    <head>
        <meta http-equiv="refresh" content="0;URL=https://twisted.org/">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <a href="https://twisted.org/">click here</a>
    </body>
</html>
N�rrr �r%r&�html�expecteds    r(�test_legitimateRedirectz'RedirectToTests.test_legitimateRedirectBs6����u�%���1�7�;��	��	
����x�(r*c�\�tdg�}td|�}d}|j||�y)zm
        Malicious URLs are HTML-escaped before interpolating them in the `redirectTo` response body
        r*s?https://twisted.org/"><script>alert(document.location)</script>sX
<html>
    <head>
        <meta http-equiv="refresh" content="0;URL=https://twisted.org/&quot;&gt;&lt;script&gt;alert(document.location)&lt;/script&gt;">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <a href="https://twisted.org/&quot;&gt;&lt;script&gt;alert(document.location)&lt;/script&gt;">click here</a>
    </body>
</html>
Nr0r1s    r(�test_maliciousRedirectz&RedirectToTests.test_maliciousRedirectTs9����u�%���N�PW�
��	��	
����x�(r*N)�__name__�
__module__�__qualname__�__doc__r)r.r4r6�r*r(rr!s���
�&E�)�$)r*rc�2�eZdZdZdedefd�Zd�Zd�Zd�Zy)	�ParentRedirectTestsz!
    Test L{ParentRedirect}.
    �requestPath�returnc��tt�d�}d|_|jd�j	d�|_t
�}|j|�|jjd�}|�J�|\}|S)z�
        Render a response to a request with path *requestPath*

        @param requestPath: A slash-separated path like C{b'/foo/bar'}.

        @returns: The value of the I{Location} header.
        Tr�/sLocation)
rrr�lstrip�split�prepathr�renderr"r#)r%r>r&r�headers�locations      r(�doLocationTestz"ParentRedirectTests.doLocationTestnsz���,�.�$�/�����%�,�,�T�2�8�8��>���!�#������� ��)�)�7�7��D���"�"�"��
���r*c��|jd|jd��|jd|jd��y)zi
        At the URL root issue a redirect to the current URL, removing any query
        string.
        �http://10.0.0.1/rAs/?biff=baffN�r rH�r%s r(�test_locationRootz%ParentRedirectTests.test_locationRoot�s<��
	
���,�d�.A�.A�$�.G�H����,�d�.A�.A�.�.Q�Rr*c��|jd|jd��|jd|jd��y)zt
        A request for a resource one level down from the URL root produces
        a redirect to the root.
        rJs/foos/foo?bar=sproiiingNrKrLs r(�test_locationToRootz'ParentRedirectTests.test_locationToRoot�s?��
	
���,�d�.A�.A�'�.J�K������!4�!4�5J�!K�	
r*c���|jd|jd��|jd|jd��|jd|jd��y)zp
        Requests for resources directly under the path C{/foo/} produce
        redirects to C{/foo/}.
        shttp://10.0.0.1/foo/s/foo/s/foo/bars/foo/bar?biz=bazNrKrLs r(�test_locationUpOnez&ParentRedirectTests.test_locationUpOne�s[��
	
���0�$�2E�2E�h�2O�P����0�$�2E�2E�k�2R�S����#�T�%8�%8�9L�%M�	
r*N)	r7r8r9r:�bytesrHrMrOrQr;r*r(r=r=is*����%��E��(S�
�	
r*r=c�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�FailureElementTestszn
    Tests for L{FailureElement} and related helpers which can render a
    L{Failure} as an HTML string.
    c���d�}|jjdz|_	|�y#t$r2t	d��|_|j
jd|_YywxYw)zO
        Create a L{Failure} which can be used by the rendering tests.
        c��d}t|��)NzThis is a problem)�	Exception)�messages r(�lineNumberProbeAlsoBrokenz<FailureElementTests.setUp.<locals>.lineNumberProbeAlsoBroken�s��)�G��G�$�$r*�T)�captureVars���N)�__code__�co_firstlineno�base�
BaseExceptionr�failure�frames�frame)r%rYs  r(�setUpzFailureElementTests.setUp�s]��
	%�
.�6�6�E�E��I��	�	1�%�'���	1�"�t�4�D�L����,�,�R�0�D�J�	1�s�+�8A&�%A&c
��tttjtjd��tjd����dd�}td|�}d}|j
|j|jd��|S)	zN
        L{_SourceLineElement} renders a source line and line number.
        �
lineNumber�rE�
sourceLine�2z    print 'hello'Nu:<div><span>50</span><span>    print 'hello'</span></div>zutf-8)	rr
r�div�spanr�addCallbackr �encode)r%�element�dr3s    r(�test_sourceLineElementz*FailureElementTests.test_sourceLineElement�s{��%��������,�7����,�9W�X�
�
��
��
�$��(��
O�	�	
�
�
�d�&�&�����(@�A��r*c
��tttjtjd��tjd��d���|j
�}gd�}t
d|�}d}t|�D]a\}}d}|d	kr/||jdd
g|d	k(|j|zd|z�z
}�<||jd|j|zd|z�z
}�c|jd�}|j|j|�|S)
z�
        L{_SourceFragmentElement} renders source lines at and around the line
        number indicated by a frame object.
        rfrgrh�sourceLines)u#    message = "This is a problem"u    raise Exception(message)�Nrsz?<div class="snippet{}Line"><span>{}</span><span>{}</span></div>rZ�	Highlightu        �utf8)
rr
rrjrkrcr�	enumerate�formatr_rmrlr )	r%rn�sourcero�stringToCheckForrfrh�template�bytesToCheckFors	         r(�test_sourceFragmentElementz.FailureElementTests.test_sourceFragmentElement�s��
)������I�I�\�2��I�I�\�2�(��
�
�J�J�	
��
��

�$��(����&/��&7�	�"�J�
�X�H��Q�� �H�O�O���%�j�A�o�6��I�I�
�*�.��;�%�� �!�H�O�O���	�	�J�.��j��%�� �	�+�1�1�&�9��	�
�
�d�&�&��8��r*c	��tttjd���|j�}td|�}|j
|jdttjd��zdz�|S)z�
        The I{filename} renderer of L{_FrameElement} renders the filename
        associated with the frame object used to initialize the
        L{_FrameElement}.
        �filenamergN�<span>�c�</span>)rr
rrkrcrrlr r�__file__�rstrip�r%rnros   r(�test_frameElementFilenamez-FailureElementTests.test_frameElementFilename�sg�� �	�$�)�)�:�*F� G����T���$��(��	�
�
�
����
�h�o�o�c�&:�;�;�j�H�		
��r*c���tttjd���|j�}td|�}|j
|jd|jdzfz�|S)z�
        The I{lineNumber} renderer of L{_FrameElement} renders the line number
        associated with the frame object used to initialize the
        L{_FrameElement}.
        rfrgNs<span>%d</span>rZ)	rr
rrkrcrrlr r_r�s   r(�test_frameElementLineNumberz/FailureElementTests.test_frameElementLineNumbersX�� �	�$�)�)�<�*H� I�4�:�:�V���$��(��	�
�
�d�&�&�(:�d�i�i�!�m�=M�(M�N��r*c��tttjd���|j�}td|�}|j
|jd�|S)z�
        The I{function} renderer of L{_FrameElement} renders the line number
        associated with the frame object used to initialize the
        L{_FrameElement}.
        �functionrgNs&<span>lineNumberProbeAlsoBroken</span>)rr
rrkrcrrlr r�s   r(�test_frameElementFunctionz-FailureElementTests.test_frameElementFunctionsH�� �	�$�)�)�:�*F� G����T���$��(��	�
�
�d�&�&�(Q�R��r*c�Z�td|j�}|jd�}tj�}|d|�}|j|t�|j|j|j�|j|g|jj��y)z�
        The I{source} renderer of L{_FrameElement} renders the source code near
        the source filename/line number associated with the frame object used to
        initialize the L{_FrameElement}.
        Nrx)rrc�lookupRenderMethodrrj�assertIsInstancer�assertIdenticalr �loader�load�r%rn�renderer�tag�results     r(�test_frameElementSourcez+FailureElementTests.test_frameElementSources��� ��d�j�j�1���-�-�h�7���h�h�j���$��$�����f�&<�=����V�\�\�4�:�:�6����#���
�
� 2� 2� 4�5r*c���td|jjdd�}|jd�}t	j
�}|d|�}|j
|t�|j
|dt�|j|dj|jjd�|j
|dt�|j|dj|jjd�|j|djj�|djj��|jdt|��y)z�
        The I{frames} renderer of L{_StackElement} renders each stack frame in
        the list of frames used to initialize the L{_StackElement}.
        N�rbrrZ)rrarbr�rrjr��listrr�rc�assertNotEqualr�r�r �lenr�s     r(�test_stackElementz%FailureElementTests.test_stackElement)s��
 ��d�l�l�&9�&9�"�1�&=�>���-�-�h�7���h�h�j���$��$�����f�d�+����f�Q�i��7����V�A�Y�_�_�d�l�l�.A�.A�!�.D�E����f�Q�i��7����V�A�Y�_�_�d�l�l�.A�.A�!�.D�E����F�1�I�,�,�1�1�3�V�A�Y�5E�5E�5J�5J�5L�M�����C��K�(r*c�l�t|j�}|jd�}tj�}|d|�}|j|t�|j|j|jj�|j|g|jj��y)z�
        The I{traceback} renderer of L{FailureElement} renders the failure's
        stack frames using L{_StackElement}.
        �	tracebackN)
rrar�rrjr�rr��stackFramesrbr r�r�r�s     r(�test_failureElementTracebackz0FailureElementTests.test_failureElementTraceback;s���
!����.���-�-�k�:���h�h�j���$��$�����f�m�4����V�/�/����1D�1D�E����#���
�
� 2� 2� 4�5r*c���t|jttjd����}td|�}d}|j
|jd|zdz�|S)zi
        The I{type} renderer of L{FailureElement} renders the failure's
        exception type.
        �typergNsbuiltins.Exceptionrr��rrar
rrkrrlr )r%rnro�excs    r(�test_failureElementTypez+FailureElementTests.test_failureElementTypeHsU��
!����y����&�9Q�/R�S���$��(��#��	�
�
�d�&�&�	�C��*�(D�E��r*c��t|jttjd����}td|�}|j
|jd�|S)zi
        The I{value} renderer of L{FailureElement} renders the value's exception
        value.
        �valuergNs<span>This is a problem</span>r�r�s   r(�test_failureElementValuez,FailureElementTests.test_failureElementValueSsH��
!����y����'�9R�/S�T���$��(��	�
�
�d�&�&�(I�J��r*N)r7r8r9r:rdrpr|r�r�r�r�r�r�r�r�r;r*r(rTrT�s?���
1�$�&(�T� 	�	�6�)�$6�	�r*rTc��eZdZdZd�Zd�Zy)�FormatFailureTestsz�
    Tests for L{twisted.web.util.formatFailure} which returns an HTML string
    representing the L{Failure} instance passed to it.
    c�J�|jttt��y)z}
        If there is an error flattening the L{Failure} instance,
        L{formatFailure} raises L{FlattenerError}.
        N)r,r
r�objectrLs r(�test_flattenerErrorz&FormatFailureTests.test_flattenerErrords��
	
���.�-���Br*c���	td��#t$rtt��}YnwxYw|j	|t
�|j
td�|D���|jd|�y)z�
        The return value of L{formatFailure} is a C{str} instance (not a
        C{unicode} instance) with numeric character references for any non-ASCII
        characters meant to appear in the output.
        zFake bugc3�&K�|]	}|dk���y�w)�Nr;)�.0�chs  r(�	<genexpr>z7FormatFailureTests.test_returnsBytes.<locals>.<genexpr>ws����6��B��H�6�s�s&#160;N)	rWr`rrr�rR�
assertTrue�all�assertIn)r%r�s  r(�test_returnsBytesz$FormatFailureTests.test_returnsBytesksd��	.��J�'�'���	.�"�7�9�-�F�	.��	
���f�e�,�����6�v�6�6�7��
�
�i��(s�
�,�,N)r7r8r9r:r�r�r;r*r(r�r�^s���
C�)r*r�c��eZdZd�Zd�Zy)�
SDResourcec��||_y�N)�default)r%r�s  r(�__init__zSDResource.__init__}s	����r*c��tj|j�}tj|�}|j
||�Sr�)r�succeedr�r	r�getChildWithDefault)r%�namer&rors     r(r�zSDResource.getChildWithDefault�s9���M�M�$�,�,�'���(�(��+��+�x�+�+�D�'�:�:r*N)r7r8r9r�r�r;r*r(r�r�|s���;r*r�c�"�eZdZdZd�Zd�Zd�Zy)�DeferredResourceTestsz(
    Tests for L{DeferredResource}.
    c���tj�}d|_t|�}t	gd��}tj
||�|j
|jddg�y)NrZ)�foo�bar�bazr�r�)r�Resource�isLeafr�r�getChildForRequestr �postpath)r%�r�sros    r(�testDeferredResourcez*DeferredResourceTests.testDeferredResource�sS�����������q�M���.�/���#�#�A�q�)�������e�U�^�4r*c���g}tg�}|j|_tj�}tt
j|��}|j|�|j||g�y)z�
        L{DeferredResource} uses the request object's C{render} method to
        render the resource which is the result of the L{Deferred} being
        handled.
        N)	r�appendrErr�rrr�r )r%�renderedr&r��deferredResources     r(�test_renderz!DeferredResourceTests.test_render�s`�����r�"��!������"�"�$��+�E�M�M�&�,A�B������(�����F�8�,r*c�x�tg�}|j�}tt��}t	tj|��}|j|�|j|j|�|�~tj�|jt�}|j|g�y)z�
        If the L{Deferred} fails, L{DeferredResource} reports the failure via
        C{processingFailed}, and does not cause an unhandled error to be
        logged.
        N)
r�notifyFinishr�RuntimeErrorrr�failrEr �failureResultOf�gc�collect�flushLoggedErrors)r%r&rorar��errorss      r(�test_renderNoFailurez*DeferredResourceTests.test_renderNoFailure�s����r�"��� � �"���,�.�)��+�E�J�J�w�,?�@������(�����-�-�a�0�'�:��
�
�
���'�'��5�������$r*N)r7r8r9r:r�r�r�r;r*r(r�r��s���5�
-�%r*r�),r:r��twisted.internetr�twisted.python.compatr�twisted.python.failurer�twisted.trial.unittestrr�twisted.webrr	�twisted.web.errorr
�twisted.web.httpr�twisted.web.serverr�twisted.web.templater
rr�twisted.web.test.requesthelperrr�twisted.web.utilrrrrrrrrrrr=rTr�r�r�r�r;r*r(�<module>r�s����
�"�/�*�@�&�,�"�&�?�?�E�
�
�
�E)�h�E)�P4
�-�4
�n{�(�{�|)��)�<;��"�"�;�+%�/�+%r*

Zerion Mini Shell 1.0