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_resource.cpython-38.pyc
U


W[ �@s�dZddlmZddlmZddlmZmZmZm	Z	m
Z
mZmZddl
mZddlmZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)z$
Tests for L{twisted.web.resource}.
�)�TestCase)�UnsupportedMethod)�	NOT_FOUND�	FORBIDDEN�Resource�	ErrorPage�
NoResource�ForbiddenResource�getChildForRequest)�Headers)�DummyRequestc@sDeZdZdZeZeZeZ	dd�Z
dd�Zdd�Zdd	�Z
d
d�ZdS)
�ErrorPageTestszJ
    Tests for L{ErrorPage}, L{NoResource}, and L{ForbiddenResource}.
    cCs(|�ddd�}|�|�dt��|�dS)zj
        The C{getChild} method of L{ErrorPage} returns the L{ErrorPage} it is
        called on.
        �AZfooZbarsnameN)�	errorPage�assertIdentical�getChild�object)�self�page�r�@/usr/lib/python3/dist-packages/twisted/web/test/test_resource.py�
test_getChildszErrorPageTests.test_getChildcCs`tdg�}d}|||||f}|�|�|�|�d��|�|j|�|�|jtddgi��dS)N�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)r�assertEqual�render�encodeZresponseCodeZresponseHeadersr)rr�code�brief�detail�request�template�expectedrrr�_pageRenderingTest$s
�	��z!ErrorPageTests._pageRenderingTestcCs.d}d}d}|�|||�}|�||||�dS)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.
        rzbrief description textzmuch longer text might go hereN)rr")rrrrrrrr�test_errorPageRendering8s
z&ErrorPageTests.test_errorPageRenderingcCs"d}|�|�}|�|td|�dS)z@
        L{NoResource} sets the HTTP I{NOT FOUND} code.
        zlong messagezNo Such ResourceN)�
noResourcer"r�rrrrrr�test_noResourceRenderingFs
z'ErrorPageTests.test_noResourceRenderingcCs"d}|�|�}|�|td|�dS)zG
        L{ForbiddenResource} sets the HTTP I{FORBIDDEN} code.
        zlonger messagezForbidden ResourceN)�forbiddenResourcer"rr%rrr�test_forbiddenResourceRenderingOs
z.ErrorPageTests.test_forbiddenResourceRenderingN)�__name__�
__module__�__qualname__�__doc__rrrr$r	r'rr"r#r&r(rrrrr
s		r
c@seZdZdZdd�ZdS)�DynamicChildzG
    A L{Resource} to be created on the fly by L{DynamicChildren}.
    cCst�|�||_||_dS�N)r�__init__�pathr�rr0rrrrr/]s
zDynamicChild.__init__N)r)r*r+r,r/rrrrr-Ysr-c@seZdZdZdd�ZdS)�DynamicChildrenz.
    A L{Resource} with dynamic children.
    cCs
t||�Sr.)r-r1rrrrhszDynamicChildren.getChildN)r)r*r+r,rrrrrr2dsr2c@s eZdZdZdd�Zdd�ZdS)�BytesReturnedRenderablezG
    A L{Resource} with minimal capabilities to render a response.
    cCst�|�||_dS)zo
        @param response: A C{bytes} object giving the value to return from
            C{render_GET}.
        N)rr/�	_response)rZresponserrrr/qs
z BytesReturnedRenderable.__init__cCs|jS)z}
        Render a response to a I{GET} request by returning a short byte string
        to be written by the server.
        )r4�rrrrr�
render_GETzsz"BytesReturnedRenderable.render_GETN)r)r*r+r,r/r6rrrrr3ms	r3c@s eZdZdZdd�Zdd�ZdS)�ImplicitAllowedMethodszn
    A L{Resource} which implicitly defines its allowed methods by defining
    renderers to handle them.
    cCsdSr.rr5rrrr6�sz!ImplicitAllowedMethods.render_GETcCsdSr.rr5rrr�
render_PUT�sz!ImplicitAllowedMethods.render_PUTN)r)r*r+r,r6r8rrrrr7�sr7c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
ResourceTestsz 
    Tests for L{Resource}.
    cCsFt�}t�}t�}|�d|�|�d|�|�||�dtg���dS)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�childZsiblingrrr�test_staticChildren�s�z!ResourceTests.test_staticChildrencCsJd}tg�}t�}|�||�}|�|t�|�|j|�|�|j|�dS)z�
        L{Resource.getChildWithDefault} delegates to L{Resource.getChild} when
        the requested path is not associated with any static child.
        r:N)	rr2r=ZassertIsInstancer-rr0rr)rr0rr>r?rrr�test_dynamicChildren�sz"ResourceTests.test_dynamicChildrencCs0d}tg�}d|_t|�}|�||�|��dS)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�methodr3rr)rr!rr>rrr�test_defaultHEAD�s
zResourceTests.test_defaultHEADcCsNdddg}t�}||_tg�}d|_|�t|j|�}|�t|�t|j��dS)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.
        �GETrB�PUT�	FICTIONALN)	r�allowedMethodsrrC�assertRaisesrrr�set�rr!r>r�excrrr�test_explicitAllowedMethods�s
z)ResourceTests.test_explicitAllowedMethodscCsHtdddg�}t�}tg�}d|_|�t|j|�}|�|t|j��dS)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}.
        rErBrFrGN)	rJr7rrCrIrrrrHrKrrr�test_implicitAllowedMethods�sz)ResourceTests.test_implicitAllowedMethodsN)	r)r*r+r,r@rArDrMrNrrrrr9�sr9c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�GetChildForRequestTestsz*
    Tests for L{getChildForRequest}.
    cCs(tg�}t�}t||�}|�||�dS)z�
        L{getChildForRequest} returns whatever resource has been reached by the
        time the request's C{postpath} is empty.
        N)rrr
r�rrr>�resultrrr�test_exhaustedPostPath�s
z.GetChildForRequestTests.test_exhaustedPostPathcCs2tddg�}t�}d|_t||�}|�||�dS)z�
        L{getChildForRequest} returns the first resource it encounters with a
        C{isLeaf} attribute set to C{True}.
        r:r;TN)rr�isLeafr
rrPrrr�test_leafResource�s

z)GetChildForRequestTests.test_leafResourcecCs`tddg�}t�}t�}d|_|�d|�|�|t||��|�|jdg�|�|jdg�dS)z�
        As path segments from the request are traversed, they are taken from
        C{postpath} and put into C{prepath}.
        r:r;TN)	rrrSr<rr
rZprepathZpostpath)rr�rootr?rrr�test_postPathToPrePath�sz.GetChildForRequestTests.test_postPathToPrePathN)r)r*r+r,rRrTrVrrrrrO�srON)r,Ztwisted.trial.unittestrZtwisted.web.errorrZtwisted.web.resourcerrrrrr	r
Ztwisted.web.http_headersrZtwisted.web.test.requesthelperrr
r-r2r3r7r9rOrrrr�<module>s$G	N