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: //proc/self/root/usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_tap.cpython-38.pyc
U


W[�*�@s:dZddlmZmZddlZddlZddlmZmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZddlmZddlmZddl m!Z!m"Z"ddl#m$Z$m%Z%ddl#m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-e.�Z/Gdd�de�Z0Gdd�de�Z1dS)z
Tests for L{twisted.web.tap}.
�)�absolute_import�divisionN)�reactor�	endpoints)�IReactorUNIX)�FilePath)�
requireModule)�
ThreadPool)�
UsageError)�PBServerFactory)�TestCase)�demo)�ResourcePublisher�
UserDirectory)�PythonScript)�Site)�Data�File)�Options�makeService)�makePersonalServerFactory�_AddHeadersResource)�DummyRequest)�	CGIScript)�WSGIResourcec@s�eZdZdZdd�Zdd�Zdd�Ze�e	�s4de_
d	d
�Zdd�Zd
d�Z
dd�Zdd�Ze�e	�slde_
dd�Ze�e	�s�de_
dd�Zdd�Zdd�Zdd�Zdd�Zed�d k	r�d!e_
d"d#�Zed�d kr�d$e_
d%d&�Zd'd(�Zd S))�ServiceTestszD
    Tests for the service creation APIs in L{twisted.web.tap}.
    cCs:t|���}|��t�}|�d|jg�|d}||fS)a�
        Helper for the I{--path} tests which creates a directory and creates
        an L{Options} object which uses that directory as its static
        filesystem root.

        @return: A two-tuple of a L{FilePath} referring to the directory and
            the value associated with the C{'root'} key in the L{Options}
            instance after parsing a I{--path} option.
        �--path�root)r�mktemp�makedirsr�parseOptions�path)�selfr!�optionsr�r$�;/usr/lib/python3/dist-packages/twisted/web/test/test_tap.py�_pathOption's
zServiceTests._pathOptioncCs,|��\}}|�|t�|�|j|j�dS)z�
        The I{--path} option causes L{Options} to create a root resource
        which serves responses from the specified path.
        N)r&�assertIsInstancer�assertEqualr!�r"r!rr$r$r%�	test_path9szServiceTests.test_pathcCs�t|���}|��|��}t�}|�dd|d|jg�t|�}|��|�|j	�|�
|jdjj
t�|�|jdjj
j|j�|�tj�|��|�t�t�|�j��dS)z�
        The I{--path} option to L{makeService} causes it to return a service
        which will listen on the server address given by the I{--port} option.
        �--port�unix:rrN)rrrrr r!r�startService�
addCleanup�stopServicer'�services�factory�resourcerr(�
assertTrue�os�exists�stat�S_ISSOCK�st_mode)r"r!�portr#�servicer$r$r%�test_pathServerCszServiceTests.test_pathServerz0The reactor does not support UNIX domain socketscCs4|��\}}|�d��d�|�|�dd�t�dS)z�
        The I{--path} option creates a root resource which serves a
        L{CGIScript} instance for any child with the C{".cgi"} extension.
        zfoo.cgi�N)r&�child�
setContentr'�getChildrr)r$r$r%�test_cgiProcessorZszServiceTests.test_cgiProcessorcCs4|��\}}|�d��d�|�|�dd�t�dS)z�
        The I{--path} option creates a root resource which serves a
        L{PythonScript} instance for any child with the C{".epy"} extension.
        zfoo.epyr<N)r&r=r>r'r?rr)r$r$r%�test_epyProcessordszServiceTests.test_epyProcessorcCsT|��\}}|�d��d�|�dd�}|�|t�|�|jd�|�|jd�dS)z�
        The I{--path} option creates a root resource which serves the
        C{resource} global defined by the Python source in any child with
        the C{".rpy"} extension.
        zfoo.rpysNfrom twisted.web.static import Data
resource = Data('content', 'major/minor')
NZcontentzmajor/minor)	r&r=r>r?r'rr(�data�type)r"r!rr=r$r$r%�test_rpyProcessorns
�zServiceTests.test_rpyProcessorcCsDttdd��}t|�}|�|t�|�|jt�|�|jj|�dS)z�
        L{makePersonalServerFactory} returns a PB server factory which has
        as its root object a L{ResourcePublisher}.
        sfoo barz
text/plainN)	rrrr'rrr�assertIdentical�site)r"rFZ
serverFactoryr$r$r%�test_makePersonalServerFactory~s
z+ServiceTests.test_makePersonalServerFactorycCsl|��}t�}|�dd|dg�t|�}|��|�|j�|�tj	�
|��|�t�t�|�j
��dS)z�
        The I{--personal} option to L{makeService} causes it to return a
        service which will listen on the server address given by the I{--port}
        option.
        r+r,�
--personalN)rrr rr-r.r/r3r4r!r5r6r7r8)r"r9r#r:r$r$r%�test_personalServer�sz ServiceTests.test_personalServercCsHt�}|�dg�tj�tj�dtj��}|�|ddd�	|��dS)z�
        If the I{--port} option not specified but the I{--personal} option is,
        L{Options} defaults the port to C{UserDirectory.userSocketName} in the
        user's home directory.
        rH�~�portsrzunix:{}N)
rr r4r!�
expanduser�joinrZuserSocketNamer(�format)r"r#r!r$r$r%�test_defaultPersonalPath�s��z%ServiceTests.test_defaultPersonalPathcCs8t�}|�g�|�t�|ddd�dd�d�dS)zl
        If the I{--port} option is not specified, L{Options} defaults the port
        to C{8080}.
        rKrN�)ZTCP)i�N)rr r(rZ_parseServer�r"r#r$r$r%�test_defaultPort�s
�zServiceTests.test_defaultPortcCsDt�}|�ddddg�|�d|dd�|�d|dd�d	S)
zQ
        If the I{--http} option is given twice, there are two listeners
        z--listenztcp:8001ztcp:8002Z8001rKrZ8002�N�rr ZassertInrQr$r$r%�
test_twoPorts�szServiceTests.test_twoPortscCs�t�}|�dtdg�|d}|�|t�|�|jt�|�t|j	t
��|�|jt�|�
|j	j�t�d�|�|j	j�|�
|j	j�t�d�|�|j	j�dS)z�
        The I{--wsgi} option takes the fully-qualifed Python name of a WSGI
        application object and creates a L{WSGIResource} at the root which
        serves that application.
        �--wsgiz.applicationrZstartupZshutdownN)rr �__name__r3rrEZ_reactorr�
isinstanceZ_threadpoolr	Z_application�applicationZassertFalseZstartedZfireSystemEventZjoined)r"r#rr$r$r%�	test_wsgi�s

zServiceTests.test_wsgicCsFt�}tddfD].}|�t|jd|g�}|�t|�d|f�qdS)zn
        If I{--wsgi} is given an invalid name, L{Options.parseOptions}
        raises L{UsageError}.
        z.nosuchthingzfoo.rVzNo such WSGI application: %rN)rrW�assertRaisesr
r r(�str)r"r#�name�excr$r$r%�test_invalidApplication�s�
�z$ServiceTests.test_invalidApplicationcCs.t�}|�t|jdg�}|�d|jd�dS)zp
        An L{UsageError} is raised when C{https} is requested but there is no
        support for SSL.
        �--https=443zSSL support not installedrN)rr[r
r r(�args)r"r#Z	exceptionr$r$r%�test_HTTPSFailureOnMissingSSL�s�z*ServiceTests.test_HTTPSFailureOnMissingSSLzOpenSSL.SSLNzSSL module is available.cCs>t�}|�dg�|�d|dd�|�d|dd�dS)zM
        When SSL support is present, it accepts the --https option.
        r`ZsslrKrZ443NrTrQr$r$r%� test_HTTPSAcceptedOnAvailableSSL�sz-ServiceTests.test_HTTPSAcceptedOnAvailableSSLzSSL module is not available.cCs0t�}|�ddddg�|�|dddg�dS)zE
        When --add-header is specific, the value is parsed.
        �--add-header�K1: V1�K2: V2ZextraHeaders��K1�V1��K2�V2N)rr r(rQr$r$r%�test_add_header_parsings

�z$ServiceTests.test_add_header_parsingcCs`t�}|�ddddg�t|�}|jdjj}|�|t�|�|j	ddg�|�|j
tj�dS)zj
        When --add-header is specified, the resource is a composition that adds
        headers.
        rdrerfrrgrjN)
rr rr0r1r2r'rr(Z_headersZ_originalResourcer
�Test)r"r#r:r2r$r$r%�test_add_header_resources
�z%ServiceTests.test_add_header_resource)rW�
__module__�__qualname__�__doc__r&r*r;rZ
providedByr�skipr@rArDrGrIrOrRrUrZr_rbrrcrmror$r$r$r%r#s>

�


�
�

rc@seZdZdd�ZdS)�AddHeadersResourceTestscCsZtt��dddg�}tg�}|�d|�|�|j�d�ddg�|�|j�d�d	g�d
S)zc
        When getChildWithDefault is invoked, it adds the headers to the
        response.
        rgrj)rh�V3�rhrirurkrlN)rr
rnrZgetChildWithDefaultr(ZresponseHeadersZ
getRawHeaders)r"r2Zrequestr$r$r%�test_getChildWithDefault(s�
�z0AddHeadersResourceTests.test_getChildWithDefaultN)rWrprqrwr$r$r$r%rt'srt)2rrZ
__future__rrr4r6Ztwisted.internetrrZtwisted.internet.interfacesrZtwisted.python.filepathrZtwisted.python.reflectrZtwisted.python.threadpoolr	Ztwisted.python.usager
Ztwisted.spread.pbrZtwisted.trial.unittestrZtwisted.webr
Ztwisted.web.distribrrZtwisted.web.scriptrZtwisted.web.serverrZtwisted.web.staticrrZtwisted.web.taprrrrZtwisted.web.test.requesthelperrZtwisted.web.twcgirZtwisted.web.wsgir�objectrYrrtr$r$r$r%�<module>s4