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

�

Ϫ�fy)���dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZm
ZmZmZmZddlmZGd�d	e�ZGd
�de�ZGd�d
e�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Zy)z$
Tests for L{twisted.web.resource}.
�)�TestCase)�UnsupportedMethod)�Headers)�IRequest)�	FORBIDDEN�	NOT_FOUND�Resource�_UnsafeErrorPage�_UnsafeForbiddenResource�_UnsafeNoResource�getChildForRequest)�DummyRequestc
�p�eZdZdZeZeZeZ	dd�Z
dd�Zdd�Zdd�Z
ded	ed
ededdf
d�Zdd
�Zdd�Zdd�Zy)�ErrorPageTestszb
    Tests for L{_UnafeErrorPage}, L{_UnsafeNoResource}, and
    L{_UnsafeForbiddenResource}.
    �returnNc���ddlm}|j||j�|j	�\}|j|dt�|jd|d�y)z�
        The public C{twisted.web.resource.ErrorPage} alias for the
        corresponding C{_Unsafe} class produces a deprecation warning when
        imported.
        r)�	ErrorPage�categoryztwisted.web.pages.errorPage�messageN)�twisted.web.resourcer�assertIs�	errorPage�
flushWarnings�assertEqual�DeprecationWarning�assertIn)�selfr�warnings   �@/usr/lib/python3/dist-packages/twisted/web/test/test_resource.py�test_deprecatedErrorPagez'ErrorPageTests.test_deprecatedErrorPage"sS��	3��
�
�i����0��&�&�(�	�������,�.@�A��
�
�3�W�Y�5G�H�c���ddlm}|j||j�|j	�\}|j|dt�|jd|d�y)z�
        The public C{twisted.web.resource.NoResource} alias for the
        corresponding C{_Unsafe} class produces a deprecation warning when
        imported.
        r)�
NoResourcerztwisted.web.pages.notFoundrN)rr#r�
noResourcerrrr)rr#rs   r�test_deprecatedNoResourcez(ErrorPageTests.test_deprecatedNoResource0sS��	4��
�
�j�$�/�/�2��&�&�(�	�������,�.@�A��
�
�2�G�I�4F�Gr!c���ddlm}|j||j�|j	�\}|j|dt�|jd|d�y)z�
        The public C{twisted.web.resource.ForbiddenResource} alias for the
        corresponding C{_Unsafe} class produce a deprecation warning when
        imported.
        r)�ForbiddenResourcerztwisted.web.pages.forbiddenrN)rr'r�forbiddenResourcerrrr)rr'rs   r� test_deprecatedForbiddenResourcez/ErrorPageTests.test_deprecatedForbiddenResource>sV��	;��
�
�'��)?�)?�@��&�&�(�	�������,�.@�A��
�
�3�W�Y�5G�Hr!c�~�|jddd�}|j|jdt��|�y)zj
        The C{getChild} method of L{ErrorPage} returns the L{ErrorPage} it is
        called on.
        �A�foo�barsnameN)r�assertIdentical�getChild�object)r�pages  r�
test_getChildzErrorPageTests.test_getChildLs3��
�~�~�c�5�%�0�����T�]�]�7�F�H�=�t�Dr!r1�code�brief�detailc��tdg�}d}|||||fz}|j|j|�|jd��|j|j|�|j|j
t
ddgi��y)Nr!zg
<html>
  <head><title>%s - %s</title></head>
  <body>
    <h1>%s</h1>
    <p>%s</p>
  </body>
</html>
zutf-8scontent-typestext/html; charset=utf-8)rr�render�encode�responseCode�responseHeadersr)rr1r3r4r5�request�template�expecteds        r�_pageRenderingTestz!ErrorPageTests._pageRenderingTestTs�����u�%��
�	��t�U�E�6�:�:��������W�-�x���w�/G�H�����-�-�t�4�����#�#��_�'B�&C�D�E�	
r!c�^�d}d}d}|j|||�}|j||||�y)a
        L{ErrorPage.render} returns a C{bytes} describing the error defined by
        the response code and message passed to L{ErrorPage.__init__}.  It also
        uses that response code to set the response code on the L{Request}
        passed in.
        r+zbrief description textzmuch longer text might go hereN)rr>)rr3r4r5r1s     r�test_errorPageRenderingz&ErrorPageTests.test_errorPageRenderingjs9����(��1���~�~�d�E�6�2������d�E�6�:r!c�Z�d}|j|�}|j|td|�y)z@
        L{NoResource} sets the HTTP I{NOT FOUND} code.
        zlong messagezNo Such ResourceN)r$r>r�rr5r1s   r�test_noResourceRenderingz'ErrorPageTests.test_noResourceRenderingws,�� �����v�&������i�1C�V�Lr!c�Z�d}|j|�}|j|td|�y)zG
        L{ForbiddenResource} sets the HTTP I{FORBIDDEN} code.
        zlonger messagezForbidden ResourceN)r(r>rrBs   r�test_forbiddenResourceRenderingz.ErrorPageTests.test_forbiddenResourceRenderings.��"���%�%�f�-������i�1E�v�Nr!�rN)�__name__�
__module__�__qualname__�__doc__rrr#r$r'r(r r%r)r2r	�int�strr>r@rCrE�r!rrrso���
�I��J�)��I�H�I�E�
��
�$'�
�03�
�=@�
�	
�
�,;�M�Or!rc�$�eZdZdZdededdfd�Zy)�DynamicChildzG
    A L{Resource} to be created on the fly by L{DynamicChildren}.
    �pathr;rNc�J�tj|�||_||_y�N)r	�__init__rPr;�rrPr;s   rrSzDynamicChild.__init__�s�����$����	���r!)rGrHrIrJ�bytesrrSrMr!rrOrO�s!����U��X��$�r!rOc�$�eZdZdZdededefd�Zy)�DynamicChildrenz.
    A L{Resource} with dynamic children.
    rPr;rc��t||�SrR)rOrTs   rr/zDynamicChildren.getChild�s���D�'�*�*r!N)rGrHrIrJrUrrOr/rMr!rrWrW�s!���+�U�+�X�+�,�+r!rWc�0�eZdZdZdeddfd�Zdedefd�Zy)�BytesReturnedRenderablezG
    A L{Resource} with minimal capabilities to render a response.
    �responserNc�<�tj|�||_y)zo
        @param response: A C{bytes} object giving the value to return from
            C{render_GET}.
        N)r	rS�	_response)rr[s  rrSz BytesReturnedRenderable.__init__�s��
	���$��!��r!r;c��|jS)z}
        Render a response to a I{GET} request by returning a short byte string
        to be written by the server.
        )r]�rr;s  r�
render_GETz"BytesReturnedRenderable.render_GET�s��
�~�~�r!)rGrHrIrJrUrSr0r`rMr!rrZrZ�s-���"��"�4�"��&��U�r!rZc�0�eZdZdZdeddfd�Zdeddfd�Zy)�ImplicitAllowedMethodszn
    A L{Resource} which implicitly defines its allowed methods by defining
    renderers to handle them.
    r;rNc��yrRrMr_s  rr`z!ImplicitAllowedMethods.render_GET����r!c��yrRrMr_s  r�
render_PUTz!ImplicitAllowedMethods.render_PUT�rdr!)rGrHrIrJr0r`rfrMr!rrbrb�s-���

�&�
�T�
�
�&�
�T�
r!rbc�@�eZdZdZd	d�Zd	d�Zd	d�Zd	d�Zd	d�Zd	d�Z	y)
�
ResourceTestsz 
    Tests for L{Resource}.
    Nc	���t�}t�}t�}|jd|�|jd|�|j||jdt	g���y)z�
        L{Resource.putChild} adds a I{static} child to the resource.  That child
        is returned from any call to L{Resource.getChildWithDefault} for the
        child's path.
        �foo�barN)r	�putChildr.�getChildWithDefaultr�r�resource�child�siblings    r�test_staticChildrenz!ResourceTests.test_staticChildren�s^���:���
���*�����&�%�(����&�'�*�����8�/�/���R�8H�I�	
r!c���d}tg�}t�}|j||�}|j|t�|j|j|�|j|j|�y)z�
        L{Resource.getChildWithDefault} delegates to L{Resource.getChild} when
        the requested path is not associated with any static child.
        rjN)	rrWrm�assertIsInstancerOrrPr.r;)rrPr;rorps     r�test_dynamicChildrenz"ResourceTests.test_dynamicChildren�se��
���r�"��"�$���,�,�T�7�;�����e�\�2�������T�*����U�]�]�G�4r!c���t�}t�}t�}|jt|jd|�|jt|jd|�y)zv
        Test that passing the wrong type to putChild results in a warning,
        and a failure in Python 3
        r,N)r	�assertRaises�	TypeErrorrlrns    r�test_staticChildPathTypez&ResourceTests.test_staticChildPathType�sM��
�:���
���*�����)�X�%6�%6��u�E����)�X�%6�%6��g�Fr!c��d}tg�}d|_t|�}|j||j	|��y)z�
        When not otherwise overridden, L{Resource.render} treats a I{HEAD}
        request as if it were a I{GET} request.
        sinsert response here�HEADN)r�methodrZrr7)rr=r;ros    r�test_defaultHEADzResourceTests.test_defaultHEAD�s=��
+���r�"�� ���*�8�4������8�?�?�7�#;�<r!c���gd�}t�}||_tg�}d|_|j	t
|j|�}|jt|�t|j��y)z�
        The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported
        request method has a C{allowedMethods} attribute set to the value of the
        C{allowedMethods} attribute of the L{Resource}, if it has one.
        )�GETr{�PUT�	FICTIONALN)	r	�allowedMethodsrr|rwrr7r�set�rr=ror;�excs     r�test_explicitAllowedMethodsz)ResourceTests.test_explicitAllowedMethods�sa��-���:��"*����r�"��%������ 1�8�?�?�G�L������X���C�,>�,>�(?�@r!c���hd�}t�}tg�}d|_|jt|j
|�}|j
|t|j��y)al
        The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported
        request method has a C{allowedMethods} attribute set to a list of the
        methods supported by the L{Resource}, as determined by the
        I{render_}-prefixed methods which it defines, if C{allowedMethods} is
        not explicitly defined by the L{Resource}.
        >rr�r{r�N)	rbrr|rwrr7rr�r�r�s     r�test_implicitAllowedMethodsz)ResourceTests.test_implicitAllowedMethodssV��-��)�+���r�"��%������ 1�8�?�?�G�L������3�s�'9�'9�#:�;r!rF)
rGrHrIrJrrruryr}r�r�rMr!rrhrh�s'���

�5�	G�	=�A�
<r!rhc�(�eZdZdZdd�Zdd�Zdd�Zy)�GetChildForRequestTestsz*
    Tests for L{getChildForRequest}.
    Nc�j�tg�}t�}t||�}|j||�y)z�
        L{getChildForRequest} returns whatever resource has been reached by the
        time the request's C{postpath} is empty.
        N)rr	r
r.�rr;ro�results    r�test_exhaustedPostPathz.GetChildForRequestTests.test_exhaustedPostPaths1��
�r�"���:��#�H�g�6�����X�v�.r!c�|�tddg�}t�}d|_t||�}|j	||�y)z�
        L{getChildForRequest} returns the first resource it encounters with a
        C{isLeaf} attribute set to C{True}.
        rjrkTN)rr	�isLeafr
r.r�s    r�test_leafResourcez)GetChildForRequestTests.test_leafResource"s=��
���/�0���:�����#�H�g�6�����X�v�.r!c�$�tddg�}t�}t�}d|_|jd|�|j	|t||��|j
|jdg�|j
|jdg�y)z�
        As path segments from the request are traversed, they are taken from
        C{postpath} and put into C{prepath}.
        rjrkTN)	rr	r�rlr.r
r�prepath�postpath)rr;�rootrps    r�test_postPathToPrePathz.GetChildForRequestTests.test_postPathToPrePath-s|��
���/�0���z���
������
�
�f�e�$����U�$6�t�W�$E�F�������6�(�3�����)�)�F�8�4r!rF)rGrHrIrJr�r�r�rMr!rr�r�s���/�	/�5r!r�N)rJ�twisted.trial.unittestr�twisted.web.errorr�twisted.web.http_headersr�twisted.web.iwebrrrrr	r
rrr'rr#r
�twisted.web.test.requesthelperrrrOrWrZrbrhr�rMr!r�<module>r�s����,�/�,�%����8�mO�X�mO�`�8��+�h�+��h��*

�X�

�R<�H�R<�j&5�h�&5r!

Zerion Mini Shell 1.0