%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fp/��^�dZddlmZddlZddlZddlmZddlmZddl	m
Z
mZddlm
Z
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1e2�Z3Gd�de�Z4Gd�de�Z5y)z
Tests for L{twisted.web.tap}.
�)�annotationsN)�cast)�skipIf)�	endpoints�reactor)�IReactorCore�IReactorUNIX)�FilePath)�
requireModule)�
ThreadPool)�
UsageError)�PBServerFactory)�TestCase)�demo)�ResourcePublisher�
UserDirectory)�PythonScript)�Site)�Data�File)�Options�_AddHeadersResource�makePersonalServerFactory�makeService)�DummyRequest)�	CGIScript)�WSGIResourcec��eZdZdZdd�Zdd�Zeeje	�d�dd��Z
dd�Zdd�Zdd�Z
dd	�Zeeje	�d�dd
��Zeeje	�d�dd��Zdd�Zdd
�Zdd�Zdd�Zeed�dud�dd��Zeed�dud�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zy)�ServiceTestszD
    Tests for the service creation APIs in L{twisted.web.tap}.
    c��t|j��}|j�t�}|j	d|j
g�|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"s    �;/usr/lib/python3/dist-packages/twisted/web/test/test_tap.py�_pathOptionzServiceTests._pathOption-sN������
�&���
�
���)�����h��	�	�2�3��v����T�z��c��|j�\}}|j|t�|j|j|j�y)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&r"s   r)�	test_pathzServiceTests.test_path>s>��
�%�%�'�
��d����d�D�)�������D�I�I�.r+z0The reactor does not support UNIX domain socketsc��t|j��}|j�|j�}t�}|j	dd|zd|j
g�t
|�}|j�|j|j�|j|jdjjt�|j|jdjjj
|j
�|j!t"j
j%|��|j!t'j(t#j&|�j*��y)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:r!rN)r
r#r$rr%r&r�startService�
addCleanup�stopServicer-�services�factory�resourcerr.�
assertTrue�os�exists�stat�S_ISSOCK�st_mode)r'r&�portr(�services     r)�test_pathServerzServiceTests.test_pathServerGs
������
�&���
�
���{�{�}���)�����h��$���$�)�)�L�M��g�&����������+�+�,����g�.�.�q�1�9�9�B�B�D�I�����)�)�!�,�4�4�=�=�B�B�D�I�I�N���������t�,�-�����
�
�b�g�g�d�m�&;�&;�<�=r+c��|j�\}}|jd�jd�|j|j	dd�t
�y)z�
        The I{--path} option creates a root resource which serves a
        L{CGIScript} instance for any child with the C{".cgi"} extension.
        zfoo.cgir+N)r*�child�
setContentr-�getChildrr/s   r)�test_cgiProcessorzServiceTests.test_cgiProcessor]sH��
�%�%�'�
��d��
�
�9��(�(��-����d�m�m�I�t�<�i�Hr+c��|j�\}}|jd�jd�|j|j	dd�t
�y)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*rDrEr-rFrr/s   r)�test_epyProcessorzServiceTests.test_epyProcessorfsH��
�%�%�'�
��d��
�
�9��(�(��-����d�m�m�I�t�<�l�Kr+c�*�|j�\}}|jd�jd�|jdd�}|j	|t
�|j
|jd�|j
|jd�y)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')
N�contentzmajor/minor)	r*rDrErFr-rr.�data�type)r'r&r"rDs    r)�test_rpyProcessorzServiceTests.test_rpyProcessoros|���%�%�'�
��d��
�
�9��(�(�
;�	
��
�
�i��.�����e�T�*�������Y�/�������]�3r+c��ttdd��}t|�}|j|t�|j|j
t�|j|j
j|�y)z�
        L{makePersonalServerFactory} returns a PB server factory which has
        as its root object a L{ResourcePublisher}.
        sfoo barz
text/plainN)	rrrr-rr"r�assertIdentical�site)r'rQ�
serverFactorys   r)�test_makePersonalServerFactoryz+ServiceTests.test_makePersonalServerFactorysb���D��\�2�3��1�$�7�
����m�_�=����m�0�0�2C�D����]�/�/�4�4�d�;r+c��|j�}t�}|jdd|zdg�t|�}|j	�|j|j�|jtjj|��|jtjtj|�j��y)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.
        r2r3�
--personalN)r#rr%rr4r5r6r:r;r&r<r=r>r?)r'r@r(rAs    r)�test_personalServerz ServiceTests.test_personalServer�s����{�{�}���)�����h��$���E�F��g�&����������+�+�,���������t�,�-�����
�
�b�g�g�d�m�&;�&;�<�=r+c��t�}|jdg�tjj	tjjdtj��}|j|ddd|���y)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.
        rU�~�portsrr3N)	rr%r;r&�
expanduser�joinr�userSocketNamer.)r'r(r&s   r)�test_defaultPersonalPathz%ServiceTests.test_defaultPersonalPath�sd���)�����l�^�,��w�w�!�!�"�'�'�,�,�s�M�4P�4P�"Q�R�������)�!�,��d�V�n�=r+c��t�}|jg�|jtj|ddd�ddd�y)zl
        If the I{--port} option is not specified, L{Options} defaults the port
        to C{8080}.
        rYrN�)�TCP)i�N)rr%r.r�_parseServer�r'r(s  r)�test_defaultPortzServiceTests.test_defaultPort�sK��
�)�����R� �����"�"�7�7�#3�A�#6��=�b�q�A�CX�	
r+c��t�}|jgd��|jd|dd�|jd|dd�y)zQ
        If the I{--http} option is given twice, there are two listeners
        )�--listenztcp:8001reztcp:8002�8001rYr�8002�N�rr%�assertInrbs  r)�
test_twoPortszServiceTests.test_twoPorts�sJ���)�����M�N��
�
�f�g�g�.�q�1�2��
�
�f�g�g�.�q�1�2r+c��t�}|jdtdzg�|d}|j|t�|j|jt�|jt|jt��|j|jt�|j|jj�tt t�j#d�|j|jj�|j|jj$�tt t�j#d�|j|jj$�y)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.applicationr"�startup�shutdownN)rr%�__name__r:rrP�_reactorr�
isinstance�_threadpoolr�_application�application�assertFalse�startedrr�fireSystemEvent�joined)r'r(r"s   r)�	test_wsgizServiceTests.test_wsgi�s
���)�����h��>�(A�B�C��v�������l�+����T�]�]�G�4����
�4�#3�#3�Z�@�A����T�.�.��<�	
����)�)�1�1�2��\�7�#�3�3�I�>�����(�(�0�0�1�����)�)�0�0�1��\�7�#�3�3�J�?�����(�(�/�/�0r+c��t�}tdzdfD]C}|jt|jd|g�}|jt
|�d|����Ey)zn
        If I{--wsgi} is given an invalid name, L{Options.parseOptions}
        raises L{UsageError}.
        z.nosuchthingzfoo.rmzNo such WSGI application: N)rrp�assertRaisesr
r%r.�str)r'r(�name�excs    r)�test_invalidApplicationz$ServiceTests.test_invalidApplication�sb��
�)����.��7�	N�D��#�#�J��0D�0D�x�QU�FV�W�C����S��X�)C�D�8�'L�M�	Nr+zOpenSSL.SSLNzSSL module is available.c��t�}|jt|jdg�}|j	d|j
d�y)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(�	exceptions   r)�test_HTTPSFailureOnMissingSSLz*ServiceTests.test_HTTPSFailureOnMissingSSL�sA���)���%�%�j�'�2F�2F���X�	����4�i�n�n�Q�6G�Hr+zSSL module is not available.c��t�}|jdg�|jd|dd�|jd|dd�y)zM
        When SSL support is present, it accepts the --https option.
        r��sslrYr�443Nrirbs  r)� test_HTTPSAcceptedOnAvailableSSLz-ServiceTests.test_HTTPSAcceptedOnAvailableSSL�sK��
�)�����m�_�-��
�
�e�W�W�-�a�0�1��
�
�e�W�W�-�a�0�1r+c�l�t�}|jgd��|j|dddg�y)zE
        When --add-header is specific, the value is parsed.
        ��--add-headerzK1: V1r�zK2: V2�extraHeaders��K1�V1��K2�V2N)rr%r.rbs  r)�test_add_header_parsingz$ServiceTests.test_add_header_parsing�s4���)�����Q�R������0�<��2N�Or+c�V�t�}|jgd��t|�}|jdjj
}|j
|t�|j|jddg�|j
|jtj�y)zj
        When --add-header is specified, the resource is a composition that adds
        headers.
        r�rr�r�N)
rr%rr7r8r9r-rr.�_headers�_originalResourcer�Test)r'r(rAr9s    r)�test_add_header_resourcez%ServiceTests.test_add_header_resources���
�)�����Q�R��g�&���#�#�A�&�.�.�7�7�����h�(;�<�����*�*�\�<�,H�I����h�8�8�$�)�)�Dr+c�(�t�}|jdg�t|�|j|jg�}|j|ddt�|j|ddd�|jt|�d�y)z7
        Passing --notracebacks is deprecated.
        z--notracebacksr�category�messagez/--notracebacks was deprecated in Twisted 19.7.0rhN)rr%r�
flushWarnings�test_noTracebacksDeprecationr.�DeprecationWarning�len)r'r(�warningss   r)r�z)ServiceTests.test_noTracebacksDeprecations����)�����.�/�0��G���%�%�t�'H�'H�&I�J������!��Z�0�2D�E�����Q�K�	�"�$U�	
�	
����X���*r+c��t�}|jdg�t|�}|j|jdj
j�y)zm
        Passing --display-tracebacks will enable traceback rendering on the
        generated Site.
        z--display-tracebacksrN)rr%rr:r7r8�displayTracebacks�r'r(rAs   r)�test_displayTracebacksz#ServiceTests.test_displayTracebackssJ��
�)�����4�5�6��g�&������(�(��+�3�3�E�E�Fr+c��t�}|jg�t|�}|j|jdj
j�y)zt
        Not passing --display-tracebacks will leave traceback rendering on the
        generated Site off.
        rN)rr%rrvr7r8r�r�s   r)�test_displayTracebacksNotGivenz+ServiceTests.test_displayTracebacksNotGiven(sH��
�)�����R� ��g�&������)�)�!�,�4�4�F�F�Gr+)�returnztuple[FilePath[str], File]�r��None)rp�
__module__�__qualname__�__doc__r*r0rr	�
providedByrrBrGrIrNrSrVr]rcrkrzr�rr�r�r�r�r�r�r��r+r)rr(s6����"/��#�L�#�#�G�,�,�:��>�	�>�$I�L�4� <��#�L�#�#�G�,�,�:��
>�	�
>��#�L�#�#�G�,�,�:��	>�	�	>�	
�3�1�,N��M�-�(��4�6P�Q�	I�R�	I��M�-�(�D�0�2P�Q�	2�R�	2�P�E�
+�G�Hr+rc��eZdZdd�Zy)�AddHeadersResourceTestsc�0�ttj�gd��}tg�}|j	d|�|j|jjd�ddg�|j|jjd�dg�y)	zc
        When getChildWithDefault is invoked, it adds the headers to the
        response.
        )r�r�)r��V3�r�r�r�r�r�N)rrr�r�getChildWithDefaultr.�responseHeaders�
getRawHeaders)r'r9�requests   r)�test_getChildWithDefaultz0AddHeadersResourceTests.test_getChildWithDefault4s~��
'��I�I�K�C�
���r�"���$�$�R��1�����0�0�>�>�t�D�t�T�l�S�����0�0�>�>�t�D�t�f�Mr+Nr�)rpr�r�r�r�r+r)r�r�3s��Nr+r�)6r��
__future__rr;r=�typingr�unittestr�twisted.internetrr�twisted.internet.interfacesrr	�twisted.python.filepathr
�twisted.python.reflectr�twisted.python.threadpoolr�twisted.python.usager
�twisted.spread.pbr�twisted.trial.unittestr�twisted.webr�twisted.web.distribrr�twisted.web.scriptr�twisted.web.serverr�twisted.web.staticrr�twisted.web.taprrrr�twisted.web.test.requesthelperr�twisted.web.twcgir�twisted.web.wsgir�objectrurr�r�r+r)�<module>r�s}���#�	����/�B�,�0�0�+�-�+��@�+�#�)���8�'�)��h��HH�8�HH�VN�h�Nr+

Zerion Mini Shell 1.0