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

��W[�1�@s�dZeZddlmZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
ddlmZddlmZddlmZdd	lmZmZdd
lmZddlmZddlmZmZdd
lmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-ddl.m/Z/ddl0m1Z1m2Z2Gdd�d�Z3Gdd�d�Z4Gdd�de�Z5Gdd�d�Z6Gdd�de6e�Z7Gdd �d e6�Z8Gd!d"�d"e8e�Z9Gd#d$�d$e8e�Z:Gd%d&�d&e8e�Z;Gd'd(�d(e8e�Z<Gd)d*�d*e6e�Z=Gd+d,�d,e6e�Z>dS)-z 
Tests for L{twisted.web.wsgi}.
�)�exc_infoN)�verifyObject)�
intToBytes�urlquote�_PY3)�Failure)�getThreadID)�
ThreadPool)�Deferred�
gatherResults)�reactor)�ConnectionLost)�TestCase�SkipTest)�http)�	IResource�Resource)�Request�Site�version)�WSGIResource)�DummyChannel)�globalLogPublisher�Logger)�EventLoggingObserver)�IPv4Address�IPv6Addressc@seZdZdZe�Zdd�ZdS)�SynchronousThreadPoola
    A single-threaded implementation of part of the L{ThreadPool} interface.
    This implementation calls functions synchronously rather than running
    them in a thread pool.  It is used to make the tests which are not
    directly for thread-related behavior deterministic.
    cOs,z|||�Wn|j�d�YnXdS)zp
        Call C{f(*a, **kw)} in this thread rather than scheduling it to be
        called in a thread.
        z<Callable passed to SynchronousThreadPool.callInThread failedN)�_logZfailure��self�f�a�kw�r$�</usr/lib/python3/dist-packages/twisted/web/test/test_wsgi.py�callInThread-s�z"SynchronousThreadPool.callInThreadN)�__name__�
__module__�__qualname__�__doc__rrr&r$r$r$r%r$src@seZdZdZdd�ZdS)�SynchronousReactorThreadsa�
    A single-threaded implementation of part of the L{IReactorThreads}
    interface.  This implementation assumes that it will only be invoked
    from the reactor thread, so it calls functions synchronously rather than
    trying to schedule them to run in the reactor thread.  It is used in
    conjunction with L{SynchronousThreadPool} to make the tests which are
    not directly for thread-related behavior deterministic.
    cOs|||�dS)ze
        Call C{f(*a, **kw)} in this thread which should also be the reactor
        thread.
        Nr$rr$r$r%�callFromThreadGsz(SynchronousReactorThreads.callFromThreadN�r'r(r)r*r,r$r$r$r%r+>sr+c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�WSGIResourceTestscCstt�t�dd��|_dS)z�
        Create a L{WSGIResource} with synchronous threading objects and a no-op
        application object.  This is useful for testing certain things about
        the resource implementation which are unrelated to WSGI.
        cSsdS�Nr$��environ�
startResponser$r$r%�<lambda>Y�z)WSGIResourceTests.setUp.<locals>.<lambda>N)rr+r�resource�r r$r$r%�setUpQs
�zWSGIResourceTests.setUpcCstt|j�|�|jj�dS)zW
        L{WSGIResource} implements L{IResource} and stops resource traversal.
        N)rrr5�
assertTrueZisLeafr6r$r$r%�test_interfaces\sz!WSGIResourceTests.test_interfacescCs6|�t|jjdtt�d��|�t|jjdt��dS)z�
        A L{WSGIResource} cannot have L{IResource} children.  Its
        C{getChildWithDefault} and C{putChild} methods raise L{RuntimeError}.
        �fooFN)�assertRaises�RuntimeErrorr5ZgetChildWithDefaultrr�putChildrr6r$r$r%�test_unsupportedds
��z"WSGIResourceTests.test_unsupportedcs�t�|t�}Gdd�dt��Gdd�dt�}�fdd�}G�fdd�d�}t|�t�|�|_|j�|t	�d	��|�
d
t|��|dd}|�|j
��|���d
S)z�
        If an exception is thrown by the application, and then in the
        exception handling code, verify it should be propagated to the
        provided L{ThreadPool}.
        c@seZdZdZdS)zIWSGIResourceTests.test_applicationAndRequestThrow.<locals>.ArbitraryErrorz;
            An arbitrary error for this class
            N)r'r(r)r*r$r$r$r%�ArbitraryError~sr?c@s(eZdZdZdd�Zdd�Zdd�ZdS)	zPWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequestzL
            An L{IRequest} request whose finish method throws.
            c_s(tj|f|�|�d|_d|_d|_dS)N�swww.example.com/stuff)r�__init__ZprepathZpostpath�uri)r �args�kwargsr$r$r%rA�szYWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.__init__cSsdS)zi
                Return loopback address.

                @return: loopback ip address.
                �	127.0.0.1r$r6r$r$r%�getClientIP�sz\WSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.getClientIPcSstddd�S)z`
                Return a fake Address

                @return: A fake address
                �TCPrEi0u)rr6r$r$r%�getHost�szXWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.getHostN)r'r(r)r*rArFrHr$r$r$r%�FinishThrowingRequest�s	rIcs
���dS)z�
            An application object that throws an exception.

            @param environ: unused

            @param startResponse: unused
            Nr$r0�r?r$r%�application�szFWSGIResourceTests.test_applicationAndRequestThrow.<locals>.applicationcseZdZdZ�fdd�ZdS)zQWSGIResourceTests.test_applicationAndRequestThrow.<locals>.ThrowingReactorThreadszt
            An L{IReactorThreads} implementation whose callFromThread raises
            an exception.
            cs
���dS)z�
                Raise an exception to the caller.

                @param f: unused

                @param a: unused

                @param kw: unused
                Nr$rrJr$r%r,�s
z`WSGIResourceTests.test_applicationAndRequestThrow.<locals>.ThrowingReactorThreads.callFromThreadNr-r$rJr$r%�ThrowingReactorThreads�srLF�r�log_failureN)r�createWithCleanupr�	Exceptionrrrr5�renderr�assertEquals�len�assertIsInstance�value�flushLoggedErrors)r �logObserverrIrKrLr!r$rJr%�test_applicationAndRequestThrowss$��z1WSGIResourceTests.test_applicationAndRequestThrowN)r'r(r)r7r9r>rXr$r$r$r%r.Psr.c@sTeZdZdZeZdd�Zdgddfdd�Zdd	�Ze	fd
d�Z
dd
�Zddd�ZdS)�WSGITestsMixinz�
    @ivar channelFactory: A no-argument callable which will be invoked to
        create a new HTTP channel to associate with request objects.
    cCst�|_t�|_dSr/)r�
threadpoolr+rr6r$r$r%r7�szWSGITestsMixin.setUpNr@csdd�}t|j|j|��}
|��|D]}t�}|�||�|
�|}
q&|�}t|
�|_||d�}|	D]\}}|j�	||�||��qd|�
d�|
r�|j�|
�|j�
d�dd��fdd�|D��}|dk	r�|d	d
��fdd�|D��7}|�||�||�d||��|S)
a�
        @param method: A C{str} giving the request method to use.

        @param version: A C{str} like C{'1.1'} giving the request version.

        @param resourceSegments: A C{list} of unencoded path segments which
            specifies the location in the resource hierarchy at which the
            L{WSGIResource} will be placed, eg C{['']} for I{/}, C{['foo',
            'bar', '']} for I{/foo/bar/}, etc.

        @param requestSegments: A C{list} of unencoded path segments giving the
            request URI.

        @param query: A C{list} of two-tuples of C{str} giving unencoded query
            argument keys and values.

        @param headers: A C{list} of two-tuples of C{str} giving request header
            names and corresponding values.

        @param safe: A C{str} giving the bytes which are to be considered
            I{safe} for inclusion in the request URI and not quoted.

        @return: A L{Deferred} which will be called back with a two-tuple of
            the arguments passed which would be passed to the WSGI application
            object for this configuration and request (ie, the environment and
            start_response callable).
        cSst|t�r|S|�d�SdS)Nz
iso-8859-1)�
isinstance�bytes�encode)�stringr$r$r%�
_toByteString�s
z4WSGITestsMixin.lowLevelRender.<locals>._toByteStringFr�/csg|]}t|���qSr$)r)�.0�seg��safer$r%�
<listcomp>sz1WSGITestsMixin.lowLevelRender.<locals>.<listcomp>N�?�&cs*g|]"\}}d�t|��t|��g��qS)�=)�joinr)ra�k�vrcr$r%res�sHTTP/)rrrZ�reverserr=r�site�requestHeaders�addRawHeader�	gotLength�content�write�seekri�requestReceived)r �requestFactory�applicationFactory�channelFactory�methodrZresourceSegmentsZrequestSegmentsZquery�headersZbodyrdr_�rootrbZtmp�channel�requestrjrkrBr$rcr%�lowLevelRender�sD	�

�
�
�zWSGITestsMixin.lowLevelRendercs:t���fdd�}|�d|j�}|jt||f|�|��S)Ncs�fdd�}|S)Ncs$|\}}��|�|dg�td�S�N�200 OKr$��callback�iter�rCr1r2��resultr$r%rKs

zFWSGITestsMixin.render.<locals>.applicationFactory.<locals>.applicationr$�rKr�r$r%rvsz1WSGITestsMixin.render.<locals>.applicationFactoryrw)r
�poprwr}r)r r"r#rvrwr$r�r%rQs���zWSGITestsMixin.rendercst����fdd�}�|fS)Ncs�||�}|�����|Sr/)ZnotifyFinishZ
chainDeferred)r"r#r|��d�requestClassr$r%ru+s
z<WSGITestsMixin.requestFactoryFactory.<locals>.requestFactory�r
)r r�rur$r�r%�requestFactoryFactory)sz$WSGITestsMixin.requestFactoryFactorycCs|�dd�dS)N�

rM)�split)r �responser$r$r%�getContentFromResponse6sz%WSGITestsMixin.getContentFromResponsecsvt����fdd�}t|j|j|�}t�}|�d|�|��}t|�|_Gdd�dt	�}||dd�}|�
d�|�fS)	aj
        Prepare a L{Request} which, when a request is received, captures the
        C{environ} and C{start_response} callable passed to a WSGI app.

        @param application: An optional WSGI application callable that accepts
            the familiar C{environ} and C{start_response} args and returns an
            iterable of body content. If not supplied, C{start_response} will
            be called with a "200 OK" status and no headers, and no content
            will be yielded.

        @return: A two-tuple of (C{request}, C{deferred}). The former is a
            Twisted L{Request}. The latter is a L{Deferred} which will be
            called back with a two-tuple of the arguments passed to a WSGI
            application (i.e. the C{environ} and C{start_response} callable),
            or will errback with any error arising within the WSGI app.
        cshz*�dkr|dg�td�}n
�||�}Wn&���|dg�td�YSX��||f�|SdS)Nrr$z	500 Error)r�Zerrbackr�)r1r2rq�rKr�r$r%�outerApplicationMs


z7WSGITestsMixin.prepareRequest.<locals>.outerApplicationsresc@seZdZdZddd�ZdS)	z4WSGITestsMixin.prepareRequest.<locals>.CannedRequestz�
            Convenient L{Request} derivative which has canned values for all
            of C{requestReceived}'s arguments.
            �GET�/res�1.1cSstj||||d�S)N)�command�pathr)rrt)r r�r�rr$r$r%rtjs�zDWSGITestsMixin.prepareRequest.<locals>.CannedRequest.requestReceivedN)r�r�r�)r'r(r)r*rtr$r$r$r%�
CannedRequestes
�r�F)Zqueuedr)r
rrrZrr=rwrrmrrp)r rKr�r5rzr{r�r|r$r�r%�prepareRequest:s�


zWSGITestsMixin.prepareRequest)N)
r'r(r)r*rrwr7r}rQrr�r�r�r$r$r$r%rY�s�
D
rYc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@S)A�EnvironTestsz�
    Tests for the values in the C{environ} C{dict} passed to the application
    object by L{twisted.web.wsgi.WSGIResource}.
    cs���fdd�}|S)Ncs|\}}��|����Sr/��assertEqual�r�r1r2��keyr rUr$r%�assertEnvironKeyEqual|sz;EnvironTests.environKeyEqual.<locals>.assertEnvironKeyEqualr$)r r�rUr�r$r�r%�environKeyEqual{szEnvironTests.environKeyEqualcs,��ddgdg�}�fdd�}|�|�|S)z�
        L{WSGIResource} calls the application object with an C{environ}
        parameter which is exactly of type C{dict}.
        �GET�1.1r@cs2|\}}��t|�t�|D]}��|t�qdSr/)ZassertIdentical�type�dictrT�str)r�r1r2�namer6r$r%�
cbRendered�sz3EnvironTests.test_environIsDict.<locals>.cbRendered)rQ�addCallback)r r�r�r$r6r%�test_environIsDict�s
zEnvironTests.test_environIsDictcCsT|�ddgdg�}|�|�dd��|�ddgdg�}|�|�dd��t||g�S)z�
        The C{'REQUEST_METHOD'} key of the C{environ} C{dict} passed to the
        application contains the HTTP method in the request (RFC 3875, section
        4.1.12).
        r�r�r@�REQUEST_METHODZPOST�rQr�r�r)r �getZpostr$r$r%�test_requestMethod�s
zEnvironTests.test_requestMethodcCsHdD]>}|��\}}|�|�|�|�dd��|�|�|�t�qdS)z�
        The C{'REQUEST_METHOD'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )r�r�r�r�N�r�rtr�r�rT�successResultOfr�)r rxr|r�r$r$r%� test_requestMethodIsNativeString�s

z-EnvironTests.test_requestMethodIsNativeStringcCs|�ddgdg�}|�|�dd��|�dddgdg�}|�|�dd��|�dddgdg�}|�|�dd��|�ddddgddg�}|�|�dd��|�dddgdd	g�}|�|�dd��|�ddddd
gddd
g�}|�|�dd��t||||||g�S)z�
        The C{'SCRIPT_NAME'} key of the C{environ} C{dict} passed to the
        application contains the I{abs_path} (RFC 2396, section 3) to this
        resource (RFC 3875, section 4.1.13).
        r�r�r@�SCRIPT_NAMEr`�fooz/fooz/foo/�bar�bar��/foo///barÿr�)r rz�
emptyChild�leaf�	containerZinternal�	unencodedr$r$r%�test_scriptName�s6�
��zEnvironTests.test_scriptNamecCs�|��\}}|jdd�|�|�dd��|�|�|�t�tr`|��\}}|jt	|jdd�n<|��\}}|jdd�|�|�dd��|�|�|�t�dS)z�
        The C{'SCRIPT_NAME'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        r��r�r�z/resN�
r�rtr�r�rTr�r�rr;�	TypeError�r r|r�r$r$r%�test_scriptNameIsNativeString�sz*EnvironTests.test_scriptNameIsNativeStringc	Cs|�dd�}|�ddgdg�}|�|�dd��|�dddgdg�}|�|�|�dddgdg�}|�|�|�ddddgddg�}|�|�|�dddgddg�}|�|�dd��|�dddgddg�}|�|�dd��|�ddgddd	g�}|�|�dd
��t||||||g�S)z�
        The C{'PATH_INFO'} key of the C{environ} C{dict} passed to the
        application contains the suffix of the request URI path which is not
        included in the value for the C{'SCRIPT_NAME'} key (RFC 3875, section
        4.1.5).
        �	PATH_INFOr@r�r�r`r�r�z/barr�r�)r�rQr�r)	r ZassertKeyEmptyrzr�r�r�ZinternalLeafZinternalContainerr�r$r$r%�
test_pathInfo�s2



��zEnvironTests.test_pathInfocCs�|��\}}|jdd�|�|�dd��|�|�|�t�tr`|��\}}|jt	|jdd�n<|��\}}|jdd�|�|�dd��|�|�|�t�dS)z
        The C{'PATH_INFO'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        s/res/foo/barr�r�z/foo/barz/res/foo/barNr�r�r$r$r%�test_pathInfoIsNativeString
s�z(EnvironTests.test_pathInfoIsNativeStringcCs�|�ddgdgd�}|�|�dd��|�ddgdgg�}|�|�dd��|�ddgdgdg�}|�|�dd��|�ddgdgdg�}|�|�dd	��|jddgdgd
gdd�}|�|�dd
��t|||||g�S)z�
        The C{'QUERY_STRING'} key of the C{environ} C{dict} passed to the
        application contains the portion of the request URI after the first
        I{?} (RFC 3875, section 4.1.7).
        r�r�r@N�QUERY_STRING�r�r��foo=bar)r`r`z%2F=%2F)r�z?barrfrczfoo=?barr�)r �missing�empty�presentr�ZdoubleQuestionr$r$r%�test_queryString!s4�
��zEnvironTests.test_queryStringcCs�|��\}}|jdd�|�|�dd��|�|�|�t�tr`|��\}}|jt	|jdd�n<|��\}}|jdd�|�|�dd��|�|�|�t�dS)z�
        The C{'QUERY_STRING'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        s/res?foo=barr�r�r�z/res?foo=barNr�r�r$r$r%�test_queryStringIsNativeString?s�z+EnvironTests.test_queryStringIsNativeStringcCsZ|�ddgdg�}|�|�dd��|�ddgdgddg�}|�|�dd��t||g�S)z�
        The C{'CONTENT_TYPE'} key of the C{environ} C{dict} passed to the
        application contains the value of the I{Content-Type} request header
        (RFC 3875, section 4.1.3).
        r�r�r@�CONTENT_TYPEN)�content-type�	x-foo/barr�r��r r�r�r$r$r%�test_contentTypeVs�zEnvironTests.test_contentTypecCsTdD]J}|��\}}|j�d|�|��|�|�dd��|�|�|�t�qdS)z�
        The C{'CONTENT_TYPE'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )s	x-foo/barr�sContent-Typer�r�N�	r�rnrortr�r�rTr�r�)r �contentTyper|r�r$r$r%�test_contentTypeIsNativeStringfsz+EnvironTests.test_contentTypeIsNativeStringcCsZ|�ddgdg�}|�|�dd��|�ddgdgddg�}|�|�dd��t||g�S)z�
        The C{'CONTENT_LENGTH'} key of the C{environ} C{dict} passed to the
        application contains the value of the I{Content-Length} request header
        (RFC 3875, section 4.1.2).
        r�r�r@�CONTENT_LENGTHN)�content-length�1234r�r�r�r$r$r%�test_contentLengthss�zEnvironTests.test_contentLengthcCsTdD]J}|��\}}|j�d|�|��|�|�dd��|�|�|�t�qdS)z�
        The C{'CONTENT_LENGTH'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )s1234r�sContent-Lengthr�r�Nr�)r Z
contentLengthr|r�r$r$r%� test_contentLengthIsNativeString�sz-EnvironTests.test_contentLengthIsNativeStringcCsZ|�ddgdg�}|�|�dd��|�ddgdgddg�}|�|�dd��t||g�S)	a_
        The C{'SERVER_NAME'} key of the C{environ} C{dict} passed to the
        application contains the best determination of the server hostname
        possible, using either the value of the I{Host} header in the request
        or the address the server is listening on if that header is not
        present (RFC 3875, section 4.1.14).
        r�r�r@�SERVER_NAMEz10.0.0.1N)Zhost�example.orgr�r�r�r$r$r%�test_serverName�s�zEnvironTests.test_serverNamecsTdD]J�|��\}}�fdd�|_|��|�|�dd��|�|�|�t�qdS)z�
        The C{'SERVER_NAME'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )shost.example.com�host.example.comcs�Sr/r$r$�Z
serverNamer$r%r3�r4z<EnvironTests.test_serverNameIsNativeString.<locals>.<lambda>r�r�N)r�ZgetRequestHostnamertr�r�rTr�r�r�r$r�r%�test_serverNameIsNativeString�sz*EnvironTests.test_serverNameIsNativeStringcsBd��fdd�}||_|�ddgdg�}|�|�dt����|S)z�
        The C{'SERVER_PORT'} key of the C{environ} C{dict} passed to the
        application contains the port number of the server which received the
        request (RFC 3875, section 4.1.15).
        iB0cst�}t��|_�|j_|Sr/)rrG�	transportZport�r{�Z
portNumberr$r%�makeChannel�s
z1EnvironTests.test_serverPort.<locals>.makeChannelr�r�r@�SERVER_PORT)rwrQr�r�r�)r r�r�r$r�r%�test_serverPort�szEnvironTests.test_serverPortcCs<|��\}}|��|�|�dd��|�|�|�t�dS)z�
        The C{'SERVER_PORT'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        r�Z80Nr�r�r$r$r%�test_serverPortIsNativeString�sz*EnvironTests.test_serverPortIsNativeStringcCsT|�ddgdg�}|�|�dd��|�ddgdg�}|�|�dd��t||g�S)z�
        The C{'SERVER_PROTOCOL'} key of the C{environ} C{dict} passed to the
        application contains the HTTP version number received in the request
        (RFC 3875, section 4.1.16).
        r�z1.0r@�SERVER_PROTOCOLzHTTP/1.0r�zHTTP/1.1r�)r �old�newr$r$r%�test_serverProtocol�s
z EnvironTests.test_serverProtocolcCsTdD]J}|��\}}dd�|_|jdd�|�|�dd��|�|�|�t�qdS)	z�
        The C{'SERVER_PROTOCOL'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )r�r�cSsdSr/r$)�datar$r$r%r3�r4z@EnvironTests.test_serverProtocolIsNativeString.<locals>.<lambda>r�)rr�r�N)r�rrrtr�r�rTr�r�)r ZserverProtocolr|r�r$r$r%�!test_serverProtocolIsNativeString�s
z.EnvironTests.test_serverProtocolIsNativeStringcCs(|�ddgdg�}|�|�dd��|S)z�
        The C{'REMOTE_ADDR'} key of the C{environ} C{dict} passed to the
        application contains the address of the client making the request.
        r�r�r@�REMOTE_ADDRz192.168.1.1�rQr�r��r r�r$r$r%�test_remoteAddr�szEnvironTests.test_remoteAddrcCs4dd�}|jddgdg|d�}|�|�dd��|S)	z�
        The C{'REMOTE_ADDR'} key of the C{environ} C{dict} passed to
        the application contains the address of the client making the
        request when connecting over IPv6.
        cSsttddd�d�S)NrG�::1i�)Zpeer)rrr$r$r$r%rwsz8EnvironTests.test_remoteAddrIPv6.<locals>.channelFactoryr�r�r@)rwr�r�r�)r rwr�r$r$r%�test_remoteAddrIPv6�sz EnvironTests.test_remoteAddrIPv6c	s���ddgdgdddg�}�fdd�}|�|���ddgdgddd	g�}|���d
d����ddgdgddg�}|���d
d����ddgdgddg�}|���d
d��t||||g�S)z�
        HTTP request headers are copied into the C{environ} C{dict} passed to
        the application with a C{HTTP_} prefix added to their names.
        r�r�r@Nr���baz�quuxcs,|\}}��|dd���|dd�dS)N�HTTP_FOOr�ZHTTP_BAZr�r�r�r6r$r%r�sz-EnvironTests.test_headers.<locals>.cbRendered)r�r�r�zbar,baz)zfoo-barr�ZHTTP_FOO_BARr�)r�zbar
	bazzbar 	bazr�)r ZsingleValuer�Z
multiValueZ
withHyphenZ	multiLiner$r6r%�test_headers
sL�
���zEnvironTests.test_headerscCs(|�ddgdg�}|�|�dd��|S)z�
        The C{'wsgi.version'} key of the C{environ} C{dict} passed to the
        application has the value C{(1, 0)} indicating that this is a WSGI 1.0
        container.
        r�r�r@zwsgi.version)rMrr�)r ZversionDeferredr$r$r%�test_wsgiVersion&szEnvironTests.test_wsgiVersioncCs(|�ddgdg�}|�|�dd��|S)z|
        The C{'wsgi.run_once'} key of the C{environ} C{dict} passed to the
        application is set to C{False}.
        r�r�r@z
wsgi.run_onceFr�)r �oncer$r$r%�test_wsgiRunOnce1szEnvironTests.test_wsgiRunOncecCs(|�ddgdg�}|�|�dd��|S)z~
        The C{'wsgi.multithread'} key of the C{environ} C{dict} passed to the
        application is set to C{True}.
        r�r�r@zwsgi.multithreadTr�)r �threadr$r$r%�test_wsgiMultithread;sz!EnvironTests.test_wsgiMultithreadcCs(|�ddgdg�}|�|�dd��|S)z�
        The C{'wsgi.multiprocess'} key of the C{environ} C{dict} passed to the
        application is set to C{False}.
        r�r�r@zwsgi.multiprocessFr�)r Zprocessr$r$r%�test_wsgiMultiprocessEsz"EnvironTests.test_wsgiMultiprocesscCshdd�}t|_|�ddgdg�}|�|�dd��||_|�ddgdg�}|�|�dd��t||g�S)	z�
        The C{'wsgi.url_scheme'} key of the C{environ} C{dict} passed to the
        application has the request URL scheme.
        cSst�}t��|_|Sr/)rZSSLr�r�r$r$r%rwVs
z7EnvironTests.test_wsgiURLScheme.<locals>.channelFactoryr�r�r@zwsgi.url_schemerZhttps)rrwrQr�r�r)r rwZhttpDeferredZ
httpsDeferredr$r$r%�test_wsgiURLSchemeOszEnvironTests.test_wsgiURLSchemecs:t��t����ddgdg�}��fdd�}|�|�|S)a`
        The C{'wsgi.errors'} key of the C{environ} C{dict} passed to the
        application is a file-like object (as defined in the U{Input and Errors
        Streams<http://www.python.org/dev/peps/pep-0333/#input-and-error-streams>}
        section of PEP 333) which converts bytes written to it into events for
        the logging system.
        r�r�r@cs�|\}}|d}|�d�|�dg�|�����ddd����ddd����dd	����d
dd����d
dd����d
d	���t��d�dS)
N�wsgi.errors�
some message
�another
message
r�message)r��systemZwsgiZisErrorrM)r�)rr�
writelines�flushr�r8rS)r�r1ZstartApplication�errors�Zeventsr r$r%�cbErrorsts
z.EnvironTests.test_wsgiErrors.<locals>.cbErrors)rrOrrQr�)r rrr$rr%�test_wsgiErrorsfs�
zEnvironTests.test_wsgiErrorsc	Cs�trtd��|��\}}|��|�|�\}}|d}tjdd��}|�d�W5QRX|�dt	|��|�t
|dj�|�dt|dj
��d	S)
a-
        The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
        expects writes of only native strings in Python 2. Some existing WSGI
        applications may write non-native (i.e. C{unicode}) strings so, for
        compatibility, these elicit only a warning in Python 2.
        zNot relevant in Python 3r�T��recordZfredrMrz5write() argument should be str, not u'fred' (unicode)N)rrr�rtr��warnings�catch_warningsrrr�rS�UnicodeWarning�categoryr�r)r r|r�r1�_r�caughtr$r$r%�0test_wsgiErrorsExpectsOnlyNativeStringsInPython2�s�z=EnvironTests.test_wsgiErrorsExpectsOnlyNativeStringsInPython2cCsZtstd��|��\}}|��|�|�\}}|d}|�t|jd�}|�dt	|��dS)z�
        The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
        permits writes of only native strings in Python 3, and raises
        C{TypeError} for writes of non-native strings.
        zRelevant only in Python 3r�sfredz1write() argument must be str, not b'fred' (bytes)N)
rrr�rtr�r;r�rrr�r�)r r|r�r1rr�errorr$r$r%�0test_wsgiErrorsAcceptsOnlyNativeStringsInPython3�s�z=EnvironTests.test_wsgiErrorsAcceptsOnlyNativeStringsInPython3N)#r'r(r)r*r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	rrr$r$r$r%r�vs@ $




r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.S)/�InputStreamTestMixinz�
    A mixin for L{TestCase} subclasses which defines a number of tests against
    L{_InputStream}.  The subclass is expected to create a file-like object to
    be wrapped by an L{_InputStream} under test.
    cCstd|jjf��dS)Nz%s.getFile must be implemented)�NotImplementedError�	__class__r'r6r$r$r%�getFileType�s�z InputStreamTestMixin.getFileTypecsR|���G�fdd�dt�}dd�}||�\}}|�||tddgdgdg|�
|S)NcseZdZ�fdd�ZdS)zLInputStreamTestMixin._renderAndReturnReaderResult.<locals>.CustomizedRequestcs��|_dSr/)rq)r Zlength�r�r$r%rp�szVInputStreamTestMixin._renderAndReturnReaderResult.<locals>.CustomizedRequest.gotLengthN)r'r(r)rpr$rr$r%�CustomizedRequest�srcst����fdd�}�|fS)Ncs��fdd�}|S)Ncs,|\}}���|d��|dg�td�S)Nz
wsgi.inputrr$r�r���readerr�r$r%rK�s
z}InputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory.<locals>.applicationFactory.<locals>.applicationr$r�rr$r%rv�szhInputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory.<locals>.applicationFactoryr�)rrvr$rr%�appFactoryFactory�szLInputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactoryZPUTr�r@)rrr}r)r rrqrrr�Z
appFactoryr$rr%�_renderAndReturnReaderResult�s"
�z1InputStreamTestMixin._renderAndReturnReaderResultcCs&d}|�dd�|�}|�|j|�|S)zi
        Calling L{_InputStream.read} with no arguments returns the entire input
        stream.
        �some bytes are herecSs|��Sr/��read��inputr$r$r%r3�r4z3InputStreamTestMixin.test_readAll.<locals>.<lambda>�rr�r��r r\r�r$r$r%�test_readAll�sz!InputStreamTestMixin.test_readAllcCs&d}|�dd�|�}|�|jd�|S)z�
        Calling L{_InputStream.read} with an integer returns that many bytes
        from the input stream, as long as it is less than or equal to the total
        number of bytes available.
        s
hello, world.cSs
|�d�S�N�r r"r$r$r%r3�r4z4InputStreamTestMixin.test_readSome.<locals>.<lambda>shelr$r%r$r$r%�
test_readSome�sz"InputStreamTestMixin.test_readSomecs*d�|��fdd���}|�|j��|S)z�
        Calling L{_InputStream.read} with an integer that is greater than the
        total number of bytes in the input stream returns all bytes in the
        input stream.
        rcs|�t��d�Sr')r!rSr"�r\r$r%r3�r4z8InputStreamTestMixin.test_readMoreThan.<locals>.<lambda>r$r�r$r*r%�test_readMoreThan�s
�z&InputStreamTestMixin.test_readMoreThancCs2d}dd�}|�||�}|�|j|dd��|S)z�
        Calling L{_InputStream.read} a second time returns bytes starting from
        the position after the last byte returned by the previous read.
        ssome bytes, hellocSs|�d�|��Sr'r r"r$r$r%r!s
z1InputStreamTestMixin.test_readTwice.<locals>.readr(Nr$)r r\r!r�r$r$r%�test_readTwice�s
z#InputStreamTestMixin.test_readTwicecCs&d}|�dd�|�}|�|j|�|S)zy
        Calling L{_InputStream.read} with L{None} as an argument returns all
        bytes in the input stream.
        sthe entire streamcSs
|�d�Sr/r r"r$r$r%r3r4z4InputStreamTestMixin.test_readNone.<locals>.<lambda>r$r%r$r$r%�
test_readNone
s�z"InputStreamTestMixin.test_readNonecCs&d}|�dd�|�}|�|j|�|S)z�
        Calling L{_InputStream.read} with a negative integer as an argument
        returns all bytes in the input stream.
        sall of the inputcSs
|�d�S�N���r r"r$r$r%r3r4z8InputStreamTestMixin.test_readNegative.<locals>.<lambda>r$r%r$r$r%�test_readNegatives�z&InputStreamTestMixin.test_readNegativecCs&d}|�dd�|�}|�|jd�|S)zs
        Calling L{_InputStream.readline} with no argument returns one line from
        the input stream.
        shello
worldcSs|��Sr/��readliner"r$r$r%r3)r4z4InputStreamTestMixin.test_readline.<locals>.<lambda>shello
r$r%r$r$r%�
test_readline"s�z"InputStreamTestMixin.test_readlinecCs&d}|�dd�|�}|�|jd�|S)a
        Calling L{_InputStream.readline} with an integer returns at most that
        many bytes, even if it is not enough to make up a complete line.

        COMPATIBILITY NOTE: the size argument is excluded from the WSGI
        specification, but is provided here anyhow, because useful libraries
        such as python stdlib's cgi.py assume their input file-like-object
        supports readline with a size argument. If you use it, be aware your
        application may not be portable to other conformant WSGI servers.
        s
goodbye
worldcSs
|�d�Sr'r1r"r$r$r%r3;r4z8InputStreamTestMixin.test_readlineSome.<locals>.<lambda>sgoor$r%r$r$r%�test_readlineSome.s�z&InputStreamTestMixin.test_readlineSomecCs&d}|�dd�|�}|�|jd�|S)z�
        Calling L{_InputStream.readline} with an integer which is greater than
        the number of bytes in the next line returns only the next line.
        ssome lines
of textcSs
|�d�S)N�r1r"r$r$r%r3Gr4z<InputStreamTestMixin.test_readlineMoreThan.<locals>.<lambda>ssome lines
r$r%r$r$r%�test_readlineMoreThan@s�z*InputStreamTestMixin.test_readlineMoreThancCs*d}dd�}|�||�}|�|jd�|S)z�
        Calling L{_InputStream.readline} a second time returns the line
        following the line returned by the first call.
        s first line
second line
last linecSs|��|��Sr/r1r"r$r$r%r2Rsz9InputStreamTestMixin.test_readlineTwice.<locals>.readlinessecond line
r$)r r\r2r�r$r$r%�test_readlineTwiceLs
z'InputStreamTestMixin.test_readlineTwicecCs&d}|�dd�|�}|�|jd�|S)z~
        Calling L{_InputStream.readline} with L{None} as an argument returns
        one line from the input stream.
        s%this is one line
this is another linecSs
|�d�Sr/r1r"r$r$r%r3ar4z8InputStreamTestMixin.test_readlineNone.<locals>.<lambda>sthis is one line
r$r%r$r$r%�test_readlineNoneZs�z&InputStreamTestMixin.test_readlineNonecCs&d}|�dd�|�}|�|jd�|S)z�
        Calling L{_InputStream.readline} with a negative integer as an argument
        returns one line from the input stream.
        sinput stream line one
line twocSs
|�d�Sr.r1r"r$r$r%r3mr4z<InputStreamTestMixin.test_readlineNegative.<locals>.<lambda>sinput stream line one
r$r%r$r$r%�test_readlineNegativefs�z*InputStreamTestMixin.test_readlineNegativecCs,d}|�dd�|�}|�|jdddg�|S)z�
        Calling L{_InputStream.readlines} with no arguments returns a list of
        all lines from the input stream.
        salice
bob
carolcSs|��Sr/��	readlinesr"r$r$r%r3yr4z5InputStreamTestMixin.test_readlines.<locals>.<lambda>salice
sbob
scarolr$r%r$r$r%�test_readlinesrs�z#InputStreamTestMixin.test_readlinescs.d}��dd�|�}�fdd�}|�|�|S)z�
        Calling L{_InputStream.readlines} with an integer as an argument
        returns a list of lines from the input stream with the argument serving
        as an approximate bound on the total number of bytes to read.
        s
123
456
789
0cSs
|�d�S)N�r:r"r$r$r%r3�r4z9InputStreamTestMixin.test_readlinesSome.<locals>.<lambda>cs��|dd�ddg�dS)Nrs123
s456
r�)�linesr6r$r%�cbLines�sz8InputStreamTestMixin.test_readlinesSome.<locals>.cbLines)rr�)r r\r�r?r$r6r%�test_readlinesSome~s�
z'InputStreamTestMixin.test_readlinesSomecCs,d}|�dd�|�}|�|jdddg�|S)z�
        Calling L{_InputStream.readlines} with an integer which is greater than
        the total number of bytes in the input stream returns a list of all
        lines from the input.
        s"one potato
two potato
three potatocSs
|�d�S)N�dr:r"r$r$r%r3�r4z=InputStreamTestMixin.test_readlinesMoreThan.<locals>.<lambda>sone potato
stwo potato
sthree potator$r%r$r$r%�test_readlinesMoreThan�s��z+InputStreamTestMixin.test_readlinesMoreThancCs.d}dd�}|�||�}|�|jddg�|S)z�
        Calling L{_InputStream.readlines} after a call to L{_InputStream.read}
        returns lines starting at the byte after the last byte returned by the
        C{read} call.
        shello
world
foocSs|�d�|��S)N�)r!r;r"r$r$r%r;�s
z?InputStreamTestMixin.test_readlinesAfterRead.<locals>.readlinessorld
r:r$)r r\r;r�r$r$r%�test_readlinesAfterRead�s
z,InputStreamTestMixin.test_readlinesAfterReadcCs*d}|�dd�|�}|�|jddg�|S)zy
        Calling L{_InputStream.readlines} with L{None} as an argument returns
        all lines from the input.
        sone fish
two fish
cSs
|�d�Sr/r:r"r$r$r%r3�r4z9InputStreamTestMixin.test_readlinesNone.<locals>.<lambda>s	one fish
s	two fish
r$r%r$r$r%�test_readlinesNone�s�z'InputStreamTestMixin.test_readlinesNonecCs*d}|�dd�|�}|�|jddg�|S)z�
        Calling L{_InputStream.readlines} with a negative integer as an
        argument returns a list of all lines from the input.
        sred fish
blue fish
cSs
|�d�Sr.r:r"r$r$r%r3�r4z=InputStreamTestMixin.test_readlinesNegative.<locals>.<lambda>s	red fish
s
blue fish
r$r%r$r$r%�test_readlinesNegative�s�z+InputStreamTestMixin.test_readlinesNegativecCs*d}|�dd�|�}|�|jddg�|S)zV
        Iterating over L{_InputStream} produces lines from the input stream.
        �green eggs
and ham
cSst|�Sr/)�listr"r$r$r%r3�r4z4InputStreamTestMixin.test_iterable.<locals>.<lambda>sgreen eggs
�and ham
r$r%r$r$r%�
test_iterable�sz"InputStreamTestMixin.test_iterablecCs.d}dd�}|�||�}|�|jddg�|S)z�
        Iterating over L{_InputStream} after calling L{_InputStream.read}
        produces lines from the input stream starting from the first byte after
        the last byte returned by the C{read} call.
        rGcSs|�d�t|�Sr')r!rHr"r$r$r%�iterate�s
z<InputStreamTestMixin.test_iterableAfterRead.<locals>.iteratesen eggs
rIr$)r r\rKr�r$r$r%�test_iterableAfterRead�s
z+InputStreamTestMixin.test_iterableAfterReadN)r'r(r)r*rrr&r)r+r,r-r0r3r4r6r7r8r9r<r@rBrDrErFrJrLr$r$r$r%r�s.

rc@seZdZdZdd�ZdS)�InputStreamStringIOTestsz�
    Tests for L{_InputStream} when it is wrapped around a
    L{StringIO.StringIO}.

    This is only available in Python 2.
    cCs6zddlm}Wntk
r,td��YnX|SdS)Nr��StringIOz#StringIO.StringIO is not available.)rO�ImportErrorr�r rOr$r$r%r�s
z$InputStreamStringIOTests.getFileTypeN�r'r(r)r*rr$r$r$r%rM�srMc@seZdZdZdd�ZdS)�InputStreamCStringIOTestsz�
    Tests for L{_InputStream} when it is wrapped around a
    L{cStringIO.StringIO}.

    This is only available in Python 2.
    cCs6zddlm}Wntk
r,td��YnX|SdS)NrrNz$cStringIO.StringIO is not available.)�	cStringIOrOrPrrQr$r$r%r�s
z%InputStreamCStringIOTests.getFileTypeNrRr$r$r$r%rS�srSc@seZdZdZdd�ZdS)�InputStreamBytesIOTestszO
    Tests for L{_InputStream} when it is wrapped around an L{io.BytesIO}.
    cCsddlm}|S)Nr)�BytesIO)�iorV)r rVr$r$r%rsz#InputStreamBytesIOTests.getFileTypeNrRr$r$r$r%rUsrUc@seZdZdZdd�ZdS)�InputStreamTemporaryFileTestszZ
    Tests for L{_InputStream} when it is wrapped around a L{tempfile.TemporaryFile}.
    cCstjSr/)�tempfileZ
TemporaryFiler6r$r$r%rsz)InputStreamTemporaryFileTests.getFileTypeNrRr$r$r$r%rXsrXc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,S)-�StartResponseTestszl
    Tests for the I{start_response} parameter passed to the application object
    by L{WSGIResource}.
    csZt��dd�}���\}}��fdd�}|�|���||�fdd�ddgd	gd
g�	|S)z�
        The response status passed to the I{start_response} callable is written
        as the status of the response to the request.
        cSsdd�}|S)NcSs|dg�td�S)Nz107 Strange messager$�r�r0r$r$r%rK!s
zOStartResponseTests.test_status.<locals>.applicationFactory.<locals>.applicationr$r�r$r$r%rv sz:StartResponseTests.test_status.<locals>.applicationFactorycs���jj���d��dS)NsHTTP/1.1 107 Strange message�r8r��written�getvalue�
startswith��ignored�r{r r$r%r�'s
��z2StartResponseTests.test_status.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3/r4z0StartResponseTests.test_status.<locals>.<lambda>r�r�r@N�rr�r�r}�r rvr�rur�r$rbr%�test_statuss"

�zStartResponseTests.test_statuscsLtrdnd��fdd�}��|�\}}|���fdd�}��|t��|�S)z�
        The response status passed to the I{start_response} callable MUST be a
        native string in Python 2 and Python 3.
        s200 OKrcs|�g�td�S)Nr$r[r0)�statusr$r%rK;s
zEStartResponseTests.test_statusMustBeNativeString.<locals>.applicationcs*tr��dt|��n��dt|��dS)Nz)status must be str, not b'200 OK' (bytes)z+status must be str, not u'200 OK' (unicode)�rr�r��rr6r$r%�checkMessageBs��zFStartResponseTests.test_statusMustBeNativeString.<locals>.checkMessage�rr�rt�
assertFailurer�r��r rKr|r�rir$)r rfr%�test_statusMustBeNativeString4sz0StartResponseTests.test_statusMustBeNativeStringcsr��tddd��t���fdd�}���\}}���fdd�}|�|���||�fdd�d	d
gdgdg�	|S)
a
        Verify that if the response headers given by C{appHeaders} are passed
        to the I{start_response} callable, then the response header lines given
        by C{expectedHeaders} plus I{Server} and I{Date} header lines are
        included in the response.
        ZdatetimeToStringcSsdS)NZTuesdayr$r$r$r$r%r3Ur4z1StartResponseTests._headersTest.<locals>.<lambda>cs�fdd�}|S)Ncs|d��td�Sr~r[r0��
appHeadersr$r%rKZs
zPStartResponseTests._headersTest.<locals>.applicationFactory.<locals>.applicationr$r�rnr$r%rvYsz;StartResponseTests._headersTest.<locals>.applicationFactorycs`�jj��}|�dd�\}}|�d�dd�}|���ddtdg}|����||�dS)Nr�rMs
s
Date: TuesdaysServer: sTransfer-Encoding: chunked)r�r]r^r��sortrr�)rar�ry�restZheaderLinesZallExpectedHeaders)r{�expectedHeadersr r$r%r�`s�z3StartResponseTests._headersTest.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3pr4r�r�r@N)Zpatchrrr�r�r})r rorrrvr�rur�r$)ror{rrr r%�_headersTestMs$

�zStartResponseTests._headersTestcCs|�ddgddg�S)z�
        The headers passed to the I{start_response} callable are included in
        the response as are the required I{Date} and I{Server} headers and the
        necessary connection (hop to hop) header I{Transfer-Encoding}.
        r�r�s	Baz: quuxsFoo: bar�rsr6r$r$r%r�ts�zStartResponseTests.test_headerscsFdg��fdd�}��|�\}}|���fdd�}��|t��|�S)zb
        The headers passed to the I{start_response} callable MUST be a
        sequence.
        �r�rUcs|dt���td�Sr~r[r0)ryr$r%rK�szBStartResponseTests.test_headersMustBeSequence.<locals>.applicationcs��t|�d�dS)NzKheaders must be a list, not <(list_?|sequence)iterator .+> [(]\1iterator[)]�ZassertRegexr�rhr6r$r%ri�s�zCStartResponseTests.test_headersMustBeSequence.<locals>.checkMessage�r�rtrkr�r�rlr$)ryr r%�test_headersMustBeSequencesz-StartResponseTests.test_headersMustBeSequencec	Cs|dd�}|�|�\}}tjdd��}|��|�|�}W5QRX|�dt|��|�t|dj�|�dt	|dj
��dS)	a�
        According to PEP-3333, the headers passed to the I{start_response}
        callable MUST be a plain list:

          The response_headers argument ... must be a Python list; i.e.
          type(response_headers) is ListType

        However, for bug-compatibility, any sequence is accepted. In both
        Python 2 and Python 3, only a warning is issued when a sequence other
        than a list is encountered.
        cSs|dd�td�S)Nr))�notrHr$r[r0r$r$r%rK�s
zEStartResponseTests.test_headersShouldBePlainList.<locals>.applicationTr
rMrz8headers should be a list, not (('not', 'list'),) (tuple)N�r�rr
rtr�r�rS�RuntimeWarningrr�r�r rKr|r�rr$r$r%�test_headersShouldBePlainList�s�z0StartResponseTests.test_headersShouldBePlainListcsDd��fdd�}��|�\}}|���fdd�}��|t��|�S)zb
        Each header passed to the I{start_response} callable MUST be a
        sequence.
        rucs|dt��g�td�Sr~r[r0)�headerr$r%rK�szFStartResponseTests.test_headersMustEachBeSequence.<locals>.applicationcs��t|�d�dS)Nz[header must be a [(]str, str[)] tuple, not <(tuple_?|sequence)iterator .+> [(]\1iterator[)]rvrhr6r$r%ri�s�zGStartResponseTests.test_headersMustEachBeSequence.<locals>.checkMessagerwrlr$)r~r r%�test_headersMustEachBeSequence�sz1StartResponseTests.test_headersMustEachBeSequencec	Cs|dd�}|�|�\}}tjdd��}|��|�|�}W5QRX|�dt|��|�t|dj�|�dt	|dj
��dS)	a�
        According to PEP-3333, each header passed to the I{start_response}
        callable should be a tuple:

          The response_headers argument is a list of (header_name,
          header_value) tuples

        However, for bug-compatibility, any 2 element sequence is also
        accepted. In both Python 2 and Python 3, only a warning is issued when
        a sequence other than a tuple is encountered.
        cSs|dddgg�td�S)Nrry�tupler$r[r0r$r$r%rK�szEStartResponseTests.test_headersShouldEachBeTuple.<locals>.applicationTr
rMrz@header should be a (str, str) tuple, not ['not', 'tuple'] (list)Nrzr|r$r$r%�test_headersShouldEachBeTuple�s�z0StartResponseTests.test_headersShouldEachBeTuplecs<dd�}��|�\}}|���fdd�}��|t��|�S)z�
        Each header passed to the I{start_response} callable MUST hold a key
        and a value, and ONLY a key and a value.
        cSs|ddg�td�S)Nr)ZtooZmanyZcooksr$r[r0r$r$r%rK�szMStartResponseTests.test_headersShouldEachHaveKeyAndValue.<locals>.applicationcs��dt|��dS)Nz?header must be a (str, str) tuple, not ('too', 'many', 'cooks')�r�r�rhr6r$r%ri�s�zNStartResponseTests.test_headersShouldEachHaveKeyAndValue.<locals>.checkMessagerwrlr$r6r%�%test_headersShouldEachHaveKeyAndValue�s
z8StartResponseTests.test_headersShouldEachHaveKeyAndValuecsNtrdnd��fdd�}��|�\}}|����fdd�}��|t��|�S)z�
        Each header key passed to the I{start_response} callable MUST be at
        native string in Python 2 and Python 3.
        skeyr�cs|d�dfg�td�S)NrrUr$r[r0)r�r$r%rK�szHStartResponseTests.test_headerKeyMustBeNativeString.<locals>.applicationcs��d�ft|��dS)Nz2header must be (str, str) tuple, not (%r, 'value')r�rh�r�r r$r%ris�zIStartResponseTests.test_headerKeyMustBeNativeString.<locals>.checkMessagerjrlr$r�r%� test_headerKeyMustBeNativeString�sz3StartResponseTests.test_headerKeyMustBeNativeStringcsNtrdnd��fdd�}��|�\}}|����fdd�}��|t��|�S)z�
        Each header value passed to the I{start_response} callable MUST be at
        native string in Python 2 and Python 3.
        svaluerUcs|dd�fg�td�S)Nrr�r$r[r0)rUr$r%rKszJStartResponseTests.test_headerValueMustBeNativeString.<locals>.applicationcs��d�ft|��dS)Nz0header must be (str, str) tuple, not ('key', %r)r�rh�r rUr$r%ris�zKStartResponseTests.test_headerValueMustBeNativeString.<locals>.checkMessagerjrlr$r�r%�"test_headerValueMustBeNativeString
sz5StartResponseTests.test_headerValueMustBeNativeStringcCs|�dgdg�S)z�
        If I{Content-Type} is included in the headers passed to the
        I{start_response} callable, one I{Content-Type} header is included in
        the response.
        )r�zmonkeys are greatsContent-Type: monkeys are greatrtr6r$r$r%�#test_applicationProvidedContentType#s�z6StartResponseTests.test_applicationProvidedContentTypecCs|�ddddgg�S)z�
        If either I{Server} or I{Date} is included in the headers passed to the
        I{start_response} callable, they are disregarded.
        )Zserverr�)ZServerr�)�dater�)ZdATEr�rtr6r$r$r%�%test_applicationProvidedServerAndDate.s��z8StartResponseTests.test_applicationProvidedServerAndDatecspt��g���fdd���fdd�}���\}}��fdd�}|�|���||�fdd�d	d
gdgdg�	|S)
a
        Nothing is written in response to a request when the I{start_response}
        callable is invoked.  If the iterator returned by the application
        object produces only empty strings, the response is written after the
        last element is produced.
        cs���jj���dSr/��appendr�r]r^r$�r{�intermediateValuesr$r%rCsz:StartResponseTests.test_delayedUntilReturn.<locals>.recordcs�fdd�}|S)Nc3s|dddg�dV��dS)Nrr�r�r4r$r0r
r$r%rKGsz[StartResponseTests.test_delayedUntilReturn.<locals>.applicationFactory.<locals>.applicationr$r�r
r$r%rvFszFStartResponseTests.test_delayedUntilReturn.<locals>.applicationFactorycs���dg�dS)Nr4r�r`�r�r r$r%r�Nsz>StartResponseTests.test_delayedUntilReturn.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3Tr4z<StartResponseTests.test_delayedUntilReturn.<locals>.<lambda>r�r�r@Nrcrdr$�r{r�rr r%�test_delayedUntilReturn9s&

�z*StartResponseTests.test_delayedUntilReturncspt��g���fdd���fdd�}���\}}��fdd�}|�|���||�fdd�d	d
gdgdg�	|S)
a
        Nothing is written in response to a request when the I{start_response}
        callable is invoked.  Once a non-empty string has been produced by the
        iterator returned by the application object, the response status and
        headers are written.
        cs���jj���dSr/r�r$r�r$r%rcsz;StartResponseTests.test_delayedUntilContent.<locals>.recordcs�fdd�}|S)Nc3s(|ddg�dV��dV��dS)Nrr�r4r:r$r0r
r$r%rKgs
z\StartResponseTests.test_delayedUntilContent.<locals>.applicationFactory.<locals>.applicationr$r�r
r$r%rvfszGStartResponseTests.test_delayedUntilContent.<locals>.applicationFactorycs ���d����d�dS)NrrM)�assertFalser8r`r�r$r%r�psz?StartResponseTests.test_delayedUntilContent.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3wr4z=StartResponseTests.test_delayedUntilContent.<locals>.<lambda>r�r�r@Nrcrdr$r�r%�test_delayedUntilContentYs&	

�z+StartResponseTests.test_delayedUntilContentcspt��g���fdd���fdd�}���\}}��fdd�}|�|���||�fdd�d	d
gdgdg�	|S)
z�
        Content produced by the iterator returned by the application object is
        written to the request as it is produced.
        cs���jj���dSr/r�r$r�r$r%r�sz/StartResponseTests.test_content.<locals>.recordcs�fdd�}|S)Nc3s(|ddg�dV��dV��dS)Nr�r��6r:�barr$r0r
r$r%rK�s
zPStartResponseTests.test_content.<locals>.applicationFactory.<locals>.applicationr$r�r
r$r%rv�sz;StartResponseTests.test_content.<locals>.applicationFactorycs0�����d�d������d�d�dS�Nrr:rMsfoobar�r�r�r`r�r$r%r��s��z3StartResponseTests.test_content.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3�r4z1StartResponseTests.test_content.<locals>.<lambda>r�r�r@Nrcrdr$r�r%�test_content|s&	

�zStartResponseTests.test_contentcsZt��dd�}���\}}��fdd�}|�|���||�fdd�ddgd	gd
g�	|S)z�
        If the I{start_response} callable is invoked multiple times before a
        data for the response body is produced, the values from the last call
        are used.
        cSsdd�}|S)NcSs|dg�|dg�td�S)N�100 Fooz200 Barr$r[r0r$r$r%rK�s

z^StartResponseTests.test_multipleStartResponse.<locals>.applicationFactory.<locals>.applicationr$r�r$r$r%rv�szIStartResponseTests.test_multipleStartResponse.<locals>.applicationFactorycs���jj���d��dS)NsHTTP/1.1 200 Bar
r\r`rbr$r%r��s
��zAStartResponseTests.test_multipleStartResponse.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3�r4z?StartResponseTests.test_multipleStartResponse.<locals>.<lambda>r�r�r@Nrcrdr$rbr%�test_multipleStartResponse�s"

�z-StartResponseTests.test_multipleStartResponsecsZt��dd�}���\}}��fdd�}|�|���||�fdd�ddgd	gd
g�	|S)z�
        If the I{start_response} callable is invoked with a third positional
        argument before the status and headers have been written to the
        response, the status and headers become the newly supplied values.
        cSsdd�}|S)NcSs|dgttd�df�td�S)Nr�r�r$)rPr�r0r$r$r%rK�szcStartResponseTests.test_startResponseWithException.<locals>.applicationFactory.<locals>.applicationr$r�r$r$r%rv�szNStartResponseTests.test_startResponseWithException.<locals>.applicationFactorycs���jj���d��dS)NsHTTP/1.1 100 Foo
r\r`rbr$r%r��s
��zFStartResponseTests.test_startResponseWithException.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3�r4zDStartResponseTests.test_startResponseWithException.<locals>.<lambda>r�r�r@Nrcrdr$rbr%�test_startResponseWithException�s"

�z2StartResponseTests.test_startResponseWithExceptioncs�t��Gdd�dt�}z
|��Wnt��YnXg���fdd�}���\}}����fdd�}|�|���||�fdd�d	d
gdgdg�	|S)
z�
        If the I{start_response} callable is invoked with a third positional
        argument after the status and headers have been written to the
        response, the supplied I{exc_info} values are re-raised to the
        application.
        c@seZdZdS)zPStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.SomeExceptionN)r'r(r)r$r$r$r%�
SomeException�sr�cs��fdd�}|S)Nc3s>|dg�dVz|dg��Wn��t��YnXdS)Nrr:z500 ERR)r�rr0��excInfo�reraisedr$r%rK�s
zjStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.applicationFactory.<locals>.applicationr$r�r�r$r%rv�szUStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.applicationFactorycs����jj���d�����dd�d����dd�d��ddj}�d}��t�|�t	t
krvdndt�|�d�dS)NsHTTP/1.1 200 OK
rrMr)r8r�r]r^r_r��tb_next�	traceback�
extract_tbr�r\)raZtb1Ztb2�r{r�r�r r$r%r��s���zMStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3
r4zKStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.<lambda>r�r�r@N)rrPrr�r�r})r r�rvr�rur�r$r�r%�&test_startResponseWithExceptionTooLate�s.



�z9StartResponseTests.test_startResponseWithExceptionTooLatecspt��g���fdd���fdd�}���\}}��fdd�}|�|���||�fdd�d	d
gdgdg�	|S)
z�
        I{start_response} returns the I{write} callable which can be used to
        write bytes to the response body without buffering.
        cs���jj���dSr/r�r$r�r$r%rsz-StartResponseTests.test_write.<locals>.recordcs�fdd�}|S)Ncs0|ddg�}|d���|d���td�S)Nr�r�r:r�r$r[�r1r2rrr
r$r%rKszNStartResponseTests.test_write.<locals>.applicationFactory.<locals>.applicationr$r�r
r$r%rvsz9StartResponseTests.test_write.<locals>.applicationFactorycs0�����d�d������d�d�dSr�r�r`r�r$r%r�(s��z1StartResponseTests.test_write.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r33r4z/StartResponseTests.test_write.<locals>.<lambda>r�r�r@Nrcrdr$r�r%�
test_writes&


�zStartResponseTests.test_writecs<dd�}��|�\}}|���fdd�}��|t��|�S)zj
        The C{write} callable returned from C{start_response} only accepts
        byte strings.
        cSs|dg�}|d�td�S)NrZbogusr$r[r�r$r$r%rK=s
zHStartResponseTests.test_writeAcceptsOnlyByteStrings.<locals>.applicationcs*tr��dt|��n��dt|��dS)Nz0Can only write bytes to a transport, not 'bogus'z1Can only write bytes to a transport, not u'bogus'rgrhr6r$r%riEs��zIStartResponseTests.test_writeAcceptsOnlyByteStrings.<locals>.checkMessagerwrlr$r6r%� test_writeAcceptsOnlyByteStrings8s

z3StartResponseTests.test_writeAcceptsOnlyByteStringsN)r'r(r)r*rermrsr�rxr}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r$r$r$r%rZs,' #%8&rZc@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�ApplicationTestszd
    Tests for things which are done to the application object and the iterator
    it returns.
    cCs*t|_t�|_|j��|�|jj�dSr/)rr	rZ�startZ
addCleanup�stopr6r$r$r%�
enableThreadsXs
zApplicationTests.enableThreadsc	spt��Gdd�d�}|���fdd�}���\}}���fdd�}|�|���||�fdd�d	d
gdg�|S)z�
        If the application object returns an iterator which also has a I{close}
        method, that method is called after iteration is complete.
        c@s$eZdZdd�Zdd�Zdd�ZdS)z+ApplicationTests.test_close.<locals>.ResultcSs
d|_dS)NT��openr6r$r$r%rAgsz4ApplicationTests.test_close.<locals>.Result.__init__css"td�D]}|jrt|�VqdSr')�ranger�r)r �ir$r$r%�__iter__jsz4ApplicationTests.test_close.<locals>.Result.__iter__cSs
d|_dS)NFr�r6r$r$r%�closeosz1ApplicationTests.test_close.<locals>.Result.closeN�r'r(r)rAr�r�r$r$r$r%�Resultfsr�cs�fdd�}|S)Ncs|ddg��S)Nr�r��3r$r0r�r$r%rKtszLApplicationTests.test_close.<locals>.applicationFactory.<locals>.applicationr$r�r�r$r%rvssz7ApplicationTests.test_close.<locals>.applicationFactorycs*�����jj���d����j�dS)Ns012)r�r�r�r]r^r�r�r`�r{r�r r$r%r�zs
��z/ApplicationTests.test_close.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3�r4z-ApplicationTests.test_close.<locals>.<lambda>r�r�r@rc)r r�rvr�rur�r$r�r%�
test_close_s"

�zApplicationTests.test_closec	sX���g��fdd�}���\}}��fdd�}|�|���||tddgdg�|S)zu
        The application object is invoked and iterated in a thread which is not
        the reactor thread.
        cs�fdd�}|S)Ncs*�fdd�}��t��|ddg�|�S)Nc3s(td�D]}��t��t|�VqdSr')r�r�rr)r���invokedr$r%r��szpApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory.<locals>.application.<locals>.resultrr�)r�r)r1r2r�r�r$r%rK�sz`ApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory.<locals>.applicationr$r�r�r$r%rv�szKApplicationTests.test_applicationCalledInThread.<locals>.applicationFactorycs&��t�����tt���d�dS)NrM)ZassertNotInrr�rS�setr`�r�r r$r%r��szCApplicationTests.test_applicationCalledInThread.<locals>.cbRenderedr�r�r@)r�r�r�r}rrdr$r�r%�test_applicationCalledInThread�s 
�z/ApplicationTests.test_applicationCalledInThreadc	sj���g�G�fdd�dt�}dd�}��|�\}}��fdd�}|�|���||tddgd	g�|S)
z�
        The I{write} callable returned by I{start_response} calls the request's
        C{write} method in the reactor thread.
        cseZdZ�fdd�ZdS)zCApplicationTests.test_writeCalledFromThread.<locals>.ThreadVerifiercs��t��t�||�Sr/�r�rrrr�r r\r�r$r%rr�szIApplicationTests.test_writeCalledFromThread.<locals>.ThreadVerifier.writeN�r'r(r)rrr$r�r$r%�ThreadVerifier�sr�cSsdd�}|S)NcSs|dg�}|d�td�S)Nrr:r$r[r�r$r$r%rK�s
z\ApplicationTests.test_writeCalledFromThread.<locals>.applicationFactory.<locals>.applicationr$r�r$r$r%rv�szGApplicationTests.test_writeCalledFromThread.<locals>.applicationFactorycs��t��tt�g��dSr/�r�r�rr`r�r$r%r��sz?ApplicationTests.test_writeCalledFromThread.<locals>.cbRenderedr�r�r@�r�rr�r�r}r�r r�rvr�rur�r$r�r%�test_writeCalledFromThread�s"
�z+ApplicationTests.test_writeCalledFromThreadc	sj���g�G�fdd�dt�}dd�}��|�\}}��fdd�}|�|���||tddgd	g�|S)
z�
        Strings produced by the iterator returned by the application object are
        written to the request in the reactor thread.
        cseZdZ�fdd�ZdS)zMApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.ThreadVerifiercs��t��t�||�Sr/r�r�r�r$r%rr�szSApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.ThreadVerifier.writeNr�r$r�r$r%r��sr�cSsdd�}|S)Ncss|dg�dVdS)Nrr:r$r0r$r$r%rK�s
zfApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.applicationFactory.<locals>.applicationr$r�r$r$r%rv�szQApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.applicationFactorycs��t��tt�g��dSr/r�r`r�r$r%r��szIApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.cbRenderedr�r�r@r�r�r$r�r%�$test_iteratedValuesWrittenFromThread�s"
�z5ApplicationTests.test_iteratedValuesWrittenFromThreadc	sj���g�G�fdd�dt�}dd�}��|�\}}��fdd�}|�|���||tddgd	g�|S)
zY
        The response status is set on the request object in the reactor thread.
        cseZdZ�fdd�ZdS)zEApplicationTests.test_statusWrittenFromThread.<locals>.ThreadVerifiercs��t��t�|||�Sr/)r�rr�setResponseCode)r �coderr�r$r%r��szUApplicationTests.test_statusWrittenFromThread.<locals>.ThreadVerifier.setResponseCodeN)r'r(r)r�r$r�r$r%r��sr�cSsdd�}|S)NcSs|dg�td�Sr~r[r0r$r$r%rK�s
z^ApplicationTests.test_statusWrittenFromThread.<locals>.applicationFactory.<locals>.applicationr$r�r$r$r%rv�szIApplicationTests.test_statusWrittenFromThread.<locals>.applicationFactorycs��t��tt�g��dSr/r�r`r�r$r%r��szAApplicationTests.test_statusWrittenFromThread.<locals>.cbRenderedr�r�r@r�r�r$r�r%�test_statusWrittenFromThread�s"
�z-ApplicationTests.test_statusWrittenFromThreadc	svGdd�dt�}d�_�fdd���fdd�}��|�\}}�fdd	�}|�|���||td
dgdg���|t�S)
z�
        If the request connection is lost while the application object is being
        iterated, iteration is stopped.
        c@seZdZdZdd�ZdS)zSApplicationTests.test_connectionClosedDuringIteration.<locals>.UnreliableConnectionz�
            This is a request which pretends its connection is lost immediately
            after the first write is done to it.
            cSs|�ttd���dS)NzNo more connection)�connectionLostrr
r�r$r$r%rrszYApplicationTests.test_connectionClosedDuringIteration.<locals>.UnreliableConnection.writeN)r'r(r)r*rrr$r$r$r%�UnreliableConnectionsr�Fc3sdVd�_td��dS)Nr:TzShould not have gotten here)�badIterrPr$r6r$r%�appIterszFApplicationTests.test_connectionClosedDuringIteration.<locals>.appItercs�fdd�}|S)Ncs|dg���S�Nrr$r0�r�r$r%rKs
zfApplicationTests.test_connectionClosedDuringIteration.<locals>.applicationFactory.<locals>.applicationr$r�r�r$r%rvszQApplicationTests.test_connectionClosedDuringIteration.<locals>.applicationFactorycs���jd�dS)Nz!Should not have resumed iteration)r�r�r`r6r$r%r� szIApplicationTests.test_connectionClosedDuringIteration.<locals>.cbRenderedr�r�r@)rr�r�r�r}rrkr
)r r�rvr�rur�r$)r�r r%�$test_connectionClosedDuringIterations"
�z5ApplicationTests.test_connectionClosedDuringIterationcs^t���fdd�}���\}}��fdd�}|�|���||�fdd�ddgd	gdg�	|S)
Ncs�Sr/r$r$r�r$r%rv.szEApplicationTests._internalServerErrorTest.<locals>.applicationFactorycs6��t�}��t|�d����jj���d��dS)NrMs"HTTP/1.1 500 Internal Server Error)	rVr<r�rSr8r�r]r^r_)rarrbr$r%r�2s
��z=ApplicationTests._internalServerErrorTest.<locals>.cbRenderedcs�Sr/r$r$r�r$r%r3=r4z;ApplicationTests._internalServerErrorTest.<locals>.<lambda>r�r�r@rc)r rKrvr�rur�r$)rKr{r r%�_internalServerErrorTest+s"

�z)ApplicationTests._internalServerErrorTestcCsdd�}|�|�S)z�
        If the application raises an exception before calling I{start_response}
        then the response status is I{500} and the exception is logged.
        cSstd��dS�N� This application had some error.�r<r0r$r$r%rKGszRApplicationTests.test_applicationExceptionBeforeStartResponse.<locals>.application�r��r rKr$r$r%�,test_applicationExceptionBeforeStartResponseBsz=ApplicationTests.test_applicationExceptionBeforeStartResponsecCsdd�}|�|�S)z�
        If the application calls I{start_response} but then raises an exception
        before any data is written to the response then the response status is
        I{500} and the exception is logged.
        cSs|dg�td��dS�Nrr�r�r0r$r$r%rKRs
zQApplicationTests.test_applicationExceptionAfterStartResponse.<locals>.applicationr�r�r$r$r%�+test_applicationExceptionAfterStartResponseLsz<ApplicationTests.test_applicationExceptionAfterStartResponsecs�t��t��t���fdd�}���\}�g���fdd�}����fdd�}|�|���||�fdd�d	d
gdgdg�	���jj	��d�
ttd
���|S)Ncs�Sr/r$r$r�r$r%rv`szBApplicationTests._connectionClosedTest.<locals>.applicationFactorycs���||���dSr.)r�)r"r#)ru�requestsr$r%�requestFactoryWrappergszEApplicationTests._connectionClosedTest.<locals>.requestFactoryWrappercsd��dt����d}|d}��|jt���t��jj��}��	|�
d�����|�dS)NrMrrNsHTTP/1.1 200 OK)rRrSrTrUr<rVr�r]r^r8r_ZassertIn)raZeventr!r�)r{rW�responseContentr r$r%�
ebRenderedks
z:ApplicationTests._connectionClosedTest.<locals>.ebRenderedcs�Sr/r$r$r�r$r%r3zr4z8ApplicationTests._connectionClosedTest.<locals>.<lambda>r�r�r@rzAll gone)
rrrOrr�Z
addErrbackr}r8r�Zdisconnectedr�rr
)r rKr�rvr�r�r�r$)rKr{rWrur�r�r r%�_connectionClosedTestXs2�

�z&ApplicationTests._connectionClosedTestcsd��fdd�}|�|��S)z�
        If the application raises an exception after the response status has
        already been sent then the connection is closed and the exception is
        logged.
        s?Some bytes, triggering the server to start sending the responsec3s|dg��Vtd��dSr�r�r0�r�r$r%rK�s
zIApplicationTests.test_applicationExceptionAfterWrite.<locals>.application)r�r�r$r�r%�#test_applicationExceptionAfterWrite�s�z4ApplicationTests.test_applicationExceptionAfterWritecs$d�G�fdd�dt�}|�|��S)z�
        If the application returns a closeable iterator and the C{close} method
        raises an exception when called then the connection is still closed and
        the exception is logged.
        r:cs(eZdZdd�Z�fdd�Zdd�ZdS)zDApplicationTests.test_applicationCloseException.<locals>.ApplicationcSs|dg�dSr�r$)r r1r2r$r$r%rA�szMApplicationTests.test_applicationCloseException.<locals>.Application.__init__c3s
�VdSr/r$r6r�r$r%r��szMApplicationTests.test_applicationCloseException.<locals>.Application.__iter__cSstd��dSr�r�r6r$r$r%r��szJApplicationTests.test_applicationCloseException.<locals>.Application.closeNr�r$r�r$r%�Application�sr�)�objectr�)r r�r$r�r%�test_applicationCloseException�s
z/ApplicationTests.test_applicationCloseExceptionN)r'r(r)r*r�r�r�r�r�r�r�r�r�r�r�r�r�r$r$r$r%r�Ss*  %
,r�)?r*r�Z
__metaclass__�sysrrYr�rZzope.interface.verifyrZtwisted.python.compatrrrZtwisted.python.failurerZtwisted.python.threadablerZtwisted.python.threadpoolr	Ztwisted.internet.deferr
rZtwisted.internetrZtwisted.internet.errorr
Ztwisted.trial.unittestrrZtwisted.webrZtwisted.web.resourcerrZtwisted.web.serverrrrZtwisted.web.wsgirZtwisted.web.test.test_webrZtwisted.loggerrrZtwisted.test.proto_helpersrZtwisted.internet.addressrrrr+r.rYr�rrMrSrUrXrZr�r$r$r$r%�<module>sZz-@/
	C