Current File : //proc/self/root/lib/python3/dist-packages/twisted/web/test/__pycache__/test_wsgi.cpython-312.pyc
�

Ϫ�fM'����dZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZmZddlmZmZdd	lmZdd
lmZddlmZmZddlmZdd
lmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*ddl+m,Z,ddl-m.Z.Gd�d�Z/Gd�d�Z0Gd�de!�Z1Gd�d�Z2Gd�de2e!�Z3Gd�d e2�Z4Gd!�d"e4e!�Z5Gd#�d$e4e!�Z6Gd%�d&e2e!�Z7Gd'�d(e2e!�Z8y))z 
Tests for L{twisted.web.wsgi}.
�N)�exc_info)�quote)�verifyObject)�reactor)�IPv4Address�IPv6Address)�Deferred�
gatherResults)�ConnectionLost)�EventLoggingObserver)�Logger�globalLogPublisher)�Failure)�getThreadID)�
ThreadPool)�TestCase)�http)�	IResource�Resource)�Request�Site�version)�DummyChannel)�WSGIResourcec�$�eZdZdZe�Zd�Zy)�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.
    c�j�	||i|��y#t$r|jjd�YywxYw)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)�
BaseException�_log�failure��self�f�a�kws    �</usr/lib/python3/dist-packages/twisted/web/test/test_wsgi.py�callInThreadz"SynchronousThreadPool.callInThread+s8��
	�
�q�K�B�K���	�
�I�I���N�
�		�s��$2�2N)�__name__�
__module__�__qualname__�__doc__r
rr'��r&rr!s����8�D�
r-rc��eZdZdZd�Zy)�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.
    c��||i|��y)ze
        Call C{f(*a, **kw)} in this thread which should also be the reactor
        thread.
        Nr,r!s    r&�callFromThreadz(SynchronousReactorThreads.callFromThreadEs��
	
�1���r-N�r(r)r*r+r1r,r-r&r/r/;s���r-r/c�$�eZdZd�Zd�Zd�Zd�Zy)�WSGIResourceTestsc�J�tt�t�d��|_y)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.
        c��y�Nr,��environ�
startResponses  r&�<lambda>z)WSGIResourceTests.setUp.<locals>.<lambda>W��r-N)rr/r�resource�r"s r&�setUpzWSGIResourceTests.setUpNs��%�%�'�!�#�/�
��
r-c��tt|j�|j|jj�y)zW
        L{WSGIResource} implements L{IResource} and stops resource traversal.
        N)rrr=�
assertTrue�isLeafr>s r&�test_interfacesz!WSGIResourceTests.test_interfacesZs(��	�Y��
�
�.�����
�
�,�,�-r-c	���|jt|jjdt	t�d��|jt|jjdt��y)z�
        A L{WSGIResource} cannot have L{IResource} children.  Its
        C{getChildWithDefault} and C{putChild} methods raise L{RuntimeError}.
        �fooFN)�assertRaises�RuntimeErrorr=�getChildWithDefaultrr�putChildrr>s r&�test_unsupportedz"WSGIResourceTests.test_unsupportedasS��
	
�����M�M�-�-���L�N�E�*�		
�	
���,��
�
�(>�(>���
�Sr-c����tj|t�}Gd�dt��Gd�dt�}�fd�}G�fd�d�}t|�t
�|�|_|jj|t�d��|jd	t|��|d
d}|j|j��|j��y)
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��eZdZdZy)�IWSGIResourceTests.test_applicationAndRequestThrow.<locals>.ArbitraryErrorz;
            An arbitrary error for this class
            N)r(r)r*r+r,r-r&�ArbitraryErrorrMvs��
r-rNc�"�eZdZdZd�Zd�Zd�Zy)�PWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequestzL
            An L{IRequest} request whose finish method throws.
            c�`�tj|g|��i|��d|_d|_d|_y)N�swww.example.com/stuff)r�__init__�prepath�postpath�uri)r"�args�kwargss   r&rSzYWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.__init__�s/��� � ��7��7��7�!��� "��
�3��r-c��y)zi
                Return loopback address.

                @return: loopback ip address.
                �	127.0.0.1r,r>s r&�getClientIPz\WSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.getClientIP�s��#r-c��tddd�S)z`
                Return a fake Address

                @return: A fake address
                �TCPrZi0u)rr>s r&�getHostzXWSGIResourceTests.test_applicationAndRequestThrow.<locals>.FinishThrowingRequest.getHost�s��#�5�+�u�=�=r-N)r(r)r*r+rSr[r^r,r-r&�FinishThrowingRequestrP{s��
�
4�
#�
>r-r_c������)z�
            An application object that throws an exception.

            @param environ: unused

            @param startResponse: unused
            r,)r9r:rNs  �r&�applicationzFWSGIResourceTests.test_applicationAndRequestThrow.<locals>.application�s���!�"�"r-c���eZdZdZ�fd�Zy)�QWSGIResourceTests.test_applicationAndRequestThrow.<locals>.ThrowingReactorThreadszt
            An L{IReactorThreads} implementation whose callFromThread raises
            an exception.
            c������)z�
                Raise an exception to the caller.

                @param f: unused

                @param a: unused

                @param kw: unused
                r,)r"r#r$r%rNs    �r&r1z`WSGIResourceTests.test_applicationAndRequestThrow.<locals>.ThrowingReactorThreads.callFromThread�s���%�&�&r-Nr2)rNs�r&�ThrowingReactorThreadsrc�s
���
�


'r-reF�r�log_failureN)r�createWithCleanupr�	Exceptionrrrr=�renderr�assertEquals�len�assertIsInstance�value�flushLoggedErrors)r"�logObserverr_rarer#rNs      @r&�test_applicationAndRequestThrowz1WSGIResourceTests.test_applicationAndRequestThrowns����+�<�<�T�CU�V��	�Y�	�
	>�G�	>�6	#�	'�	'�$%�"�$�&;�&=�{�
��
�	
�
�
���2�<�>�5�I�J����!�S��-�.���N�=�)�����a�g�g�~�6����~�.r-N)r(r)r*r?rCrJrqr,r-r&r4r4Ms��

�.�T�L/r-r4c�H�eZdZdZeZd�Zdgddfd�Zd�Ze	fd�Z
d�Zd
d	�Zy)�WSGITestsMixinz�
    @ivar channelFactory: A no-argument callable which will be invoked to
        create a new HTTP channel to associate with request objects.
    c�@�t�|_t�|_yr7)r�
threadpoolr/rr>s r&r?zWSGITestsMixin.setUp�s��/�1���0�2��r-NrRc�d�d�}t|j|j|��}
|j�|D]&}t	�}|j||�|
�|}
�(|�}t
|
�|_||d�}|	D]-\}}|jj||�||���/|jd�|
r6|jj|
�|jjd�ddj|D�cgc]}t||���c}�z}|�O|ddj|D��cgc],\}}djt||�t||�g���.c}}�zz
}|j!||�||�d||�z�|Scc}wcc}}w)	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).
        c�H�t|t�r|S|jd�S)Nz
iso-8859-1)�
isinstance�bytes�encode)�strings r&�
_toByteStringz4WSGITestsMixin.lowLevelRender.<locals>._toByteString�s"���&�%�(��
��}�}�\�2�2r-Fr�/�?�&�=sHTTP/)rrru�reverserrIr�site�requestHeaders�addRawHeader�	gotLength�content�write�seek�join�urlquote�requestReceived)r"�requestFactory�applicationFactory�channelFactory�methodr�resourceSegments�requestSegments�query�headers�body�safer|�root�seg�tmp�channel�request�k�vrVs                     r&�lowLevelRenderzWSGITestsMixin.lowLevelRender�s���T	3��D�L�L�$�/�/�;M�;O�P��� � �"�#�	�C��*�C��L�L��s�+�T�2��D�	�
!�"���D�z��� ��%�0���	T�D�A�q��"�"�/�/�
�a�0@�-�PQ�BR�S�	T����!����O�O�!�!�$�'��O�O� � ��#��C�H�H�_�M�c�h�s�D�1�M�N�N�����3����PU�V�f�q�!����8�A�t�,�h�q�$�.?�@�A�V���
�C�	����&�!�=��#5�x�-�PW�BX�7X�	
����N��Ws�F'
�1F,c���t���fd�}|jd|j�}|jt||g|��i|���S)Nc����fd�}|S)Nc�X��|\}}�j|�|dg�td�S�N�200 OKr,��callback�iter)rWr9r:�results   �r&razFWSGITestsMixin.render.<locals>.applicationFactory.<locals>.applications,���)-�&�������%��h��+��B�x�r-r,�rar�s �r&r�z1WSGITestsMixin.render.<locals>.applicationFactorys���
 ��r-r�)r	�popr�r�r)r"r$r%r�r�r�s     @r&rjzWSGITestsMixin.rendersL������	���� 0�$�2E�2E�F������G�%7��R�!�R�r�R��
r-c�.���t����fd�}�|fS)Nc�V���|i|��}|j�j��|Sr7)�notifyFinish�
chainDeferred)r$r%r��d�requestClasss   ��r&r�z<WSGITestsMixin.requestFactoryFactory.<locals>.requestFactory)s0���"�A�,��,�G�

� � �"�0�0��3��Nr-�r	)r"r�r�r�s ` @r&�requestFactoryFactoryz$WSGITestsMixin.requestFactoryFactory&s����J��	��.� � r-c�,�|jdd�dS)N�

rf)�split)r"�responses  r&�getContentFromResponsez%WSGITestsMixin.getContentFromResponse4s���~�~�k�1�-�a�0�0r-c�<���t����fd�}t|j|j|�}t	�}|jd|�|j
�}t|�|_Gd�dt�}||d��}|jd�|�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.
        c����	��|dg�td�}n	�||�}�j||f�|S#t$r'�j�|dg�td�cYSwxYw)Nr�r,z	500 Error)r�r�r�errback)r9r:r�rar�s   ��r&�outerApplicationz7WSGITestsMixin.prepareRequest.<locals>.outerApplicationJss���
��&�!�(�B�/�"�2�h�G�)�'�=�A�G�����-� 8�9����
!�
 ���� ��k�2�.��B�x��
 �s� 8�-A(�'A(sresc��eZdZdZdd�Zy)�4WSGITestsMixin.prepareRequest.<locals>.CannedRequestz�
            Convenient L{Request} derivative which has canned values for all
            of C{requestReceived}'s arguments.
            c�4�tj||||��S)N)�command�pathr)rr�)r"r�r�rs    r&r�zDWSGITestsMixin.prepareRequest.<locals>.CannedRequest.requestReceivedgs���.�.��'��g��r-N)�GET�/res�1.1)r(r)r*r+r�r,r-r&�
CannedRequestr�as��
�

r-r�F)�queuedr)r	rrrurrIr�rr�rr�)	r"rar�r=r�r�r�r�r�s	 `      @r&�prepareRequestzWSGITestsMixin.prepareRequest7s����"���
	� ����d�o�o�?O�P���z���
�
�f�h�'��%�%�'���D�z���		�G�		� ���6�����!�����r-r7)
r(r)r*r+rr�r?r�rjrr�r�r�r,r-r&rsrs�sA���
"�N�3���
�
�K�Z� 29�!�1�8r-rsc���eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!y )!�EnvironTestsz�
    Tests for the values in the C{environ} C{dict} passed to the application
    object by L{twisted.web.wsgi.WSGIResource}.
    c��������fd�}|S)Nc�<��|\}}�j|����Sr7��assertEqual)r�r9r:�keyr"rns   ���r&�assertEnvironKeyEqualz;EnvironTests.environKeyEqual.<locals>.assertEnvironKeyEqualys&���%+�"�G�]����W�S�\�5�1��Lr-r,)r"r�rnr�s``` r&�environKeyEqualzEnvironTests.environKeyEqualxs���	�
%�$r-c�^���jddgdg�}�fd�}|j|�|S)z�
        L{WSGIResource} calls the application object with an C{environ}
        parameter which is exactly of type C{dict}.
        �GET�1.1rRc���|\}}�jt|�t�|D]}�j|t��yr7)�assertIdentical�type�dictrm�str)r�r9r:�namer"s    �r&�
cbRenderedz3EnvironTests.test_environIsDict.<locals>.cbRendered�s@���%+�"�G�]�� � ��g���5��
1���%�%�d�C�0�
1r-)rj�addCallback)r"r�r�s`  r&�test_environIsDictzEnvironTests.test_environIsDict�s3���

�K�K��u�b�2�$�/��	1�	
�
�
�j�!��r-c���|jddgdg�}|j|jdd��|jddgdg�}|j|jdd��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�rR�REQUEST_METHOD�POST�rjr�r�r
)r"�get�posts   r&�test_requestMethodzEnvironTests.test_requestMethod�sw���k�k�%���R�D�1������,�,�-=�u�E�F��{�{�6�5�"�r�d�3������-�-�.>��G�H��c�4�[�)�)r-c���dD]l}|j�\}}|j|�|j|jdd��|j	|j|�t��ny)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�r�r�r�rm�successResultOfr�)r"r�r�r�s    r&� test_requestMethodIsNativeStringz-EnvironTests.test_requestMethodIsNativeString�sl��
$�	E�F�"�1�1�3�O�G�V��#�#�F�+����t�3�3�4D�e�L�M��!�!�$�"6�"6�v�">��D�		Er-c��|jddgdg�}|j|jdd��|jdddgdg�}|j|jdd��|jdddgdg�}|j|jdd��|jddddgddg�}|j|jdd��|jdddgdd	g�}|j|jdd��|jddgd
�gd
��}|j|jdd��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�rR�SCRIPT_NAMEr}�fooz/fooz/foo/�bar�r�r}sbar��/foo///barÿr�)r"r��
emptyChild�leaf�	container�internal�	unencodeds       r&�test_scriptNamezEnvironTests.test_scriptName�sV���{�{�5�%��b�T�2������-�-�m�R�@�A��[�[����t�b�T�:�
����t�3�3�M�3�G�H��{�{�5�%�%��5�'�:������-�-�m�V�D�E��K�K��u�u�b�k�E�2�;�G�	����d�2�2�=�'�J�K��;�;�u�e�e�W�u�e�n�E�����T�1�1�-��H�I��K�K��5�2�4L�
�	�
	���d�2�2�=�BR�S�T��d�J��i��9�U�V�Vr-c�D�|j�\}}|jd��|j|jdd��|j	|j|�t�|j�\}}|jt|jd��y)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�r�r�r�rmr�r�rF�	TypeError�r"r�r�s   r&�test_scriptNameIsNativeStringz*EnvironTests.test_scriptNameIsNativeString�s���
�-�-�/�������W��-����4�/�/�
�v�F�G����d�2�2�6�:�C�@��-�-�/�������)�W�%<�%<�6��Jr-c���|jdd�}|jddgdg�}|j|jdd��|jdddgdg�}|j|�|jdddgdg�}|j|�|jddddgddg�}|j|�|jdddgddg�}|j|jdd��|jdddgddg�}|j|jdd��|jddggd	��}|j|jdd
��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_INFOrRr�r�r}r�r�z/barr�r�)r�rjr�r
)	r"�assertKeyEmptyr�r�r�r��internalLeaf�internalContainerr�s	         r&�
test_pathInfozEnvironTests.test_pathInfo�sw���-�-�k�2�>���{�{�5�%��b�T�2������-�-�k�3�?�@��[�[����t�b�T�:�
����~�.��{�{�5�%�%��5�'�:������(��K�K��u�u�b�k�E�2�;�G�	����n�-��{�{�5�%�%��5�%�.�I��� � ��!5�!5�k�6�!J�K� �K�K��u�u�g��r�{�K���%�%�d�&:�&:�;��&L�M��K�K��u�b�2J�K�	����d�2�2�;�@P�Q�R��
�4��L�2C�Y�O�
�	
r-c�D�|j�\}}|jd��|j|jdd��|j	|j|�t�|j�\}}|jt|jd��y)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�s   r&�test_pathInfoIsNativeStringz(EnvironTests.test_pathInfoIsNativeString�s���
�-�-�/�������_��5����4�/�/��Z�H�I����d�2�2�6�:�C�@��-�-�/�������)�W�%<�%<�>��Rr-c�R�|jddgdgd�}|j|jdd��|jddgdgg�}|j|jdd��|jddgdgdg�}|j|jdd��|jddgdgdg�}|j|jdd	��|jddgdgd
gd��}|j|jdd
��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�rRN�QUERY_STRING�r�r��foo=bar)r}r}z%2F=%2F)r�z?barr~)r�zfoo=?barr�)r"�missing�empty�presentr��doubleQuestions      r&�test_queryStringzEnvironTests.test_queryString
s/���+�+�e�U�B���d�;�����D�0�0���D�E����E�5�"�r�d�B�7��
���$�.�.�~�r�B�C��+�+�e�U�B���~�6F�G�����D�0�0���K�L��K�K��u�b�2�$���E�	����d�2�2�>�9�M�N�
����5�"�r�d�_�$5�C�%�
��	�"�"�4�#7�#7��
�#S�T��g�u�g�y�.�Q�R�Rr-c�D�|j�\}}|jd��|j|jdd��|j	|j|�t�|j�\}}|jt|jd��y)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�rrz/res?foo=barNr�r�s   r&�test_queryStringIsNativeStringz+EnvironTests.test_queryStringIsNativeString&s���
�-�-�/�������_��5����4�/�/��	�J�K����d�2�2�6�:�C�@��-�-�/�������)�W�%<�%<�>��Rr-c��|jddgdg�}|j|jdd��|jddgdgddg�}|j|jdd��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�rR�CONTENT_TYPEN)�content-type�	x-foo/barr
r��r"rrs   r&�test_contentTypezEnvironTests.test_contentType5s����+�+�e�U�B���5�����D�0�0���D�E��+�+��5�"�r�d�D�+H�*I�
��	���D�0�0���M�N��g�w�/�0�0r-c��dD]�}|j�\}}|jjd|�|j�|j	|jdd��|j
|j|�t���y)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-Typerr
N�	r�r�r�r�r�r�rmr�r�)r"�contentTyper�r�s    r&�test_contentTypeIsNativeStringz+EnvironTests.test_contentTypeIsNativeStringEs��
5�	E�K�"�1�1�3�O�G�V��"�"�/�/���M��#�#�%����t�3�3�N�K�P�Q��!�!�$�"6�"6�v�">��D�	Er-c��|jddgdg�}|j|jdd��|jddgdgddg�}|j|jdd��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�rR�CONTENT_LENGTHN)�content-length�1234rr�rs   r&�test_contentLengthzEnvironTests.test_contentLengthQs����+�+�e�U�B���5�����D�0�0�1A�2�F�G��+�+��5�"�r�d�D�+E�*F�
��	���D�0�0�1A�6�J�K��g�w�/�0�0r-c��dD]�}|j�\}}|jjd|�|j�|j	|jdd��|j
|j|�t���y)z�
        The C{'CONTENT_LENGTH'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )s1234rsContent-LengthrrNr)r"�
contentLengthr�r�s    r&� test_contentLengthIsNativeStringz-EnvironTests.test_contentLengthIsNativeStringas���
-�	E�M�"�1�1�3�O�G�V��"�"�/�/�0A�=�Q��#�#�%����t�3�3�4D�f�M�N��!�!�$�"6�"6�v�">��D�	Er-c��|jddgdg�}|j|jdd��|jddgdgddg�}|j|jdd��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�rR�SERVER_NAMEz10.0.0.1N)�host�example.orgrr�rs   r&�test_serverNamezEnvironTests.test_serverNamems����+�+�e�U�B���5��	���D�0�0��
�K�L��+�+�e�U�B���d�=T�<U�V�����D�0�0��
�N�O��g�w�/�0�0r-c���dD]u�|j�\}}�fd�|_|j�|j|j	dd��|j|j
|�t��wy)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.comc����Sr7r,)�
serverNames�r&r;z<EnvironTests.test_serverNameIsNativeString.<locals>.<lambda>�s����r-rr"N)r��getRequestHostnamer�r�r�rmr�r�)r"r�r�r$s   @r&�test_serverNameIsNativeStringz*EnvironTests.test_serverNameIsNativeStringsv���
B�	E�J�"�1�1�3�O�G�V�*<�G�&��#�#�%����t�3�3�M�CU�V�W��!�!�$�"6�"6�v�">��D�	Er-c���d��fd�}||_|jddgdg�}|j|jdt	����|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).
        iB0c�p��t�}tj�|_�|j_|Sr7)rr]�	transport�port)r��
portNumbers �r&�makeChannelz1EnvironTests.test_serverPort.<locals>.makeChannel�s.���"�n�G� ,� 0� 0� 2�G��%/�G���"��Nr-r�r�rR�SERVER_PORT)r�rjr�r�r�)r"r,r�r+s   @r&�test_serverPortzEnvironTests.test_serverPort�sQ����
�	�*����K�K��u�b�2�$�/��	�
�
�d�*�*�=�#�j�/�J�K��r-c���|j�\}}|j�|j|jdd��|j	|j|�t�y)z�
        The C{'SERVER_PORT'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        r-�80Nr�r�s   r&�test_serverPortIsNativeStringz*EnvironTests.test_serverPortIsNativeString�sX��
�-�-�/�������!����4�/�/�
�t�D�E����d�2�2�6�:�C�@r-c���|jddgdg�}|j|jdd��|jddgdg�}|j|jdd��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.0rR�SERVER_PROTOCOLzHTTP/1.0r�zHTTP/1.1r�)r"�old�news   r&�test_serverProtocolz EnvironTests.test_serverProtocol�ss���k�k�%���R�D�1������,�,�->�
�K�L��k�k�%���R�D�1������,�,�->�
�K�L��c�3�Z�(�(r-c��dD]u}|j�\}}d�|_|jd��|j|j	dd��|j|j
|�t��wy)z�
        The C{'SERVER_PROTOCOL'} key of the C{environ} C{dict} passed to the
        application is always a native string.
        )r�r�c��yr7r,)�datas r&r;z@EnvironTests.test_serverProtocolIsNativeString.<locals>.<lambda>�r<r-r�)rr3r�N)r�r�r�r�r�rmr�r�)r"�serverProtocolr�r�s    r&�!test_serverProtocolIsNativeStringz.EnvironTests.test_serverProtocolIsNativeString�sx��
,�	E�N�"�1�1�3�O�G�V�.�G�M��#�#�F�#�3����t�3�3�4E�u�M�N��!�!�$�"6�"6�v�">��D�	Er-c�r�|jddgdg�}|j|jdd��|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�rR�REMOTE_ADDRz192.168.1.1�rjr�r�)r"r�s  r&�test_remoteAddrzEnvironTests.test_remoteAddr�s8��

�K�K��u�b�2�$�/��	�
�
�d�*�*�=�-�H�I��r-c�|�d�}|jddgdg|��}|j|jdd��|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.
        c�0�ttddd���S)Nr]�::1i�)�peer)rrr,r-r&r�z8EnvironTests.test_remoteAddrIPv6.<locals>.channelFactory�s���[���t�%D�E�Er-r�r�rR)r�r=rBr>)r"r�r�s   r&�test_remoteAddrIPv6z EnvironTests.test_remoteAddrIPv6�sB��	F�
�K�K��u�b�2�$�~�K�N��	�
�
�d�*�*�=�%�@�A��r-c	�����jddgdgdddg�}�fd�}|j|��jddgdgdddg�}|j�jd	d
���jddgdgddg�}|j�jdd
���jddgdgddg�}|j�jd	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�rRNr��baz�quuxc�d��|\}}�j|dd��j|dd�y)N�HTTP_FOOr��HTTP_BAZrHr�)r�r9r:r"s   �r&r�z-EnvironTests.test_headers.<locals>.cbRendered�s7���%+�"�G�]����W�Z�0�%�8����W�Z�0�&�9r-)r�rGrJzbar,baz)zfoo-barrG�HTTP_FOO_BARrG)r�zbar
	bazzbar 	bazr�)r"�singleValuer��
multiValue�
withHyphen�	multiLines`     r&�test_headerszEnvironTests.test_headers�s���
�k�k��5�"�r�d�D�>�?�*K�
��	:�
	���
�+��[�[��5�"�r�d�D�>�>�*J�
�
�	���t�3�3�J�	�J�K��[�[���r�B�4��@R�?S�T�
����t�3�3�N�E�J�K��K�K��u�b�2�$��?T�>U�V�	����d�2�2�:�{�K�L��k�:�z�9�M�N�Nr-c�r�|jddgdg�}|j|jdd��|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�rRzwsgi.version)rfrr>)r"�versionDeferreds  r&�test_wsgiVersionzEnvironTests.test_wsgiVersion�s;���+�+�e�U�B���=���#�#�D�$8�$8���$P�Q��r-c�r�|jddgdg�}|j|jdd��|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�rRz
wsgi.run_onceFr>)r"�onces  r&�test_wsgiRunOncezEnvironTests.test_wsgiRunOnce	s:��
�{�{�5�%��b�T�2������-�-�o�u�E�F��r-c�r�|jddgdg�}|j|jdd��|S)z~
        The C{'wsgi.multithread'} key of the C{environ} C{dict} passed to the
        application is set to C{True}.
        r�r�rRzwsgi.multithreadTr>)r"�threads  r&�test_wsgiMultithreadz!EnvironTests.test_wsgiMultithreads;��
���U�E�2��t�4�����4�/�/�0B�D�I�J��
r-c�r�|jddgdg�}|j|jdd��|S)z�
        The C{'wsgi.multiprocess'} key of the C{environ} C{dict} passed to the
        application is set to C{False}.
        r�r�rRzwsgi.multiprocessFr>)r"�processs  r&�test_wsgiMultiprocessz"EnvironTests.test_wsgiMultiprocesss;��
�+�+�e�U�B���5�����D�0�0�1D�e�L�M��r-c��d�}t|_|jddgdg�}|j|j	dd��||_|jddgdg�}|j|j	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.
        c�L�t�}tj�|_|Sr7)r�SSLr)�r�s r&r�z7EnvironTests.test_wsgiURLScheme.<locals>.channelFactory,s��"�n�G� ,� 0� 0� 2�G���Nr-r�r�rRzwsgi.url_schemer�https)rr�rjr�r�r
)r"r��httpDeferred�
httpsDeferreds    r&�test_wsgiURLSchemezEnvironTests.test_wsgiURLScheme$s���	�
+����{�{�5�%��b�T�:��� � ��!5�!5�6G��!P�Q�,������E�5�"�r�d�;�
��!�!�$�"6�"6�7H�'�"R�S��l�M�:�;�;r-c����tj�t���jddgdg�}��fd�}|j	|�|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�rRc����|\}}|d}|jd�|jdg�|j��j�ddd��j�ddd��j	�dd	��j�d
dd��j�d
dd��j	�d
d	��jt��d�y)
N�wsgi.errors�
some message
�another
message
r�message)ri�system�wsgi�isErrorrf)rj�)r��
writelines�flushr�rArl)r�r9�startApplication�errors�eventsr"s    ��r&�cbErrorsz.EnvironTests.test_wsgiErrors.<locals>.cbErrorsGs����(.�%�G�%��]�+�F��L�L�)�*����3�4�5��L�L�N����V�A�Y�y�1�3F�G����V�A�Y�x�0�&�9��O�O�F�1�I�i�0�1����V�A�Y�y�1�3J�K����V�A�Y�x�0�&�9��O�O�F�1�I�i�0�1����S��[�!�,r-)rrhrrjr�)r"rsrurts`  @r&�test_wsgiErrorszEnvironTests.test_wsgiErrors;sH���&�7�7��>P�Q�����U�E�2��t�4��	-�	���8�$��
r-c���|j�\}}|j�|j|�\}}|d}|jt|j
d�}|j
dt|��y)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.
        rhsfredz1write() argument must be str, not b'fred' (bytes)N)r�r�r�rFr�r�r�r�)r"r�r�r9�_rs�errors       r&�0test_wsgiErrorsAcceptsOnlyNativeStringsInPython3z=EnvironTests.test_wsgiErrorsAcceptsOnlyNativeStringsInPython3Xso���-�-�/�������!��)�)�&�1�
�����'���!�!�)�V�\�\�7�C�����?��U��	
r-N)"r(r)r*r+r�r�r�r�r�r�r�r�rr	rrrrr r&r.r1r6r;r?rDrQrTrWrZr]rervrzr,r-r&r�r�rs����
%��"*� 	E�W�<
K� 
�D
S�S�8
S�1� 
E�1� 
E�1�$
E��(A�)�
E��
�O�:����<�.�:
r-r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�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.
    c�F�t|jj�d���)Nz.getFile must be implemented)�NotImplementedError�	__class__r(r>s r&�getFileTypez InputStreamTestMixin.getFileTypeps%��!��~�~�&�&�'�'C�D�
�	
r-c���|j��G�fd�dt�}d�}||�\}}|j||tddgdgdg|�
|S)Nc���eZdZ�fd�Zy)�LInputStreamTestMixin._renderAndReturnReaderResult.<locals>.CustomizedRequestc�����|_yr7)r�)r"�lengthrs  �r&r�zVInputStreamTestMixin._renderAndReturnReaderResult.<locals>.CustomizedRequest.gotLengthys��� +�}��r-N)r(r)r*r�)rs�r&�CustomizedRequestr�xs���
-r-r�c�.���t����fd�}�|fS)Nc�����fd�}|S)Nc�j��|\}}�j�|d��|dg�td�S)Nz
wsgi.inputr�r,r�)rWr9r:�readerr�s   ��r&raz}InputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory.<locals>.applicationFactory.<locals>.application�s6���-1�*�G�]��O�O�F�7�<�+@�$A�B�!�(�B�/���8�Or-r,)rar�r�s ��r&r�zhInputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactory.<locals>.applicationFactory�s���$�#�"r-r�)r�r�r�s` @r&�appFactoryFactoryzLInputStreamTestMixin._renderAndReturnReaderResult.<locals>.appFactoryFactorys����Z�F�
#��-�-�-r-�PUTr�rR)r�rr�r)r"r�r�r�r�r��
appFactoryrs       @r&�_renderAndReturnReaderResultz1InputStreamTestMixin._renderAndReturnReaderResultusg����&�&�(��	-��	-�	.�*�&�1�
��:����������
�D����	
��r-c�h�d}|jd�|�}|j|j|�|S)zi
        Calling L{_InputStream.read} with no arguments returns the entire input
        stream.
        �some bytes are herec�"�|j�Sr7��read��inputs r&r;z3InputStreamTestMixin.test_readAll.<locals>.<lambda>�s��E�J�J�L�r-�r�r�r��r"ryr�s   r&�test_readAllz!InputStreamTestMixin.test_readAll�s5��
'���-�-�.H�%�P��	�
�
�d�&�&��.��r-c�h�d}|jd�|�}|j|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.c�$�|jd�S�N�r�r�s r&r;z4InputStreamTestMixin.test_readSome.<locals>.<lambda>�s��E�J�J�q�M�r-shelr�r�s   r&�
test_readSomez"InputStreamTestMixin.test_readSome�s5��!���-�-�.I�5�Q��	�
�
�d�&�&��/��r-c�n��d�|j�fd���}|j|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.
        r�c�>��|jt��dz�Sr�)r�rl)r�rys �r&r;z8InputStreamTestMixin.test_readMoreThan.<locals>.<lambda>�s���%�*�*�S��Z�!�^�4�r-r�)r"r�rys  @r&�test_readMoreThanz&InputStreamTestMixin.test_readMoreThan�s:���'���-�-�4�e�
��	
�
�
�d�&�&��.��r-c�r�d}d�}|j||�}|j|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, helloc�D�|jd�|j�Sr�r�r�s r&r�z1InputStreamTestMixin.test_readTwice.<locals>.read�s���J�J�q�M��:�:�<�r-r�Nr�)r"ryr�r�s    r&�test_readTwicez#InputStreamTestMixin.test_readTwice�sA��
%��	 �
�-�-�d�E�:��	�
�
�d�&�&��a�b�	�2��r-c�h�d}|jd�|�}|j|j|�|S)zy
        Calling L{_InputStream.read} with L{None} as an argument returns all
        bytes in the input stream.
        sthe entire streamc�$�|jd�Sr7r�r�s r&r;z4InputStreamTestMixin.test_readNone.<locals>.<lambda>�s��E�J�J�t�<L�r-r�r�s   r&�
test_readNonez"InputStreamTestMixin.test_readNone�s5��
%���-�-�.L�e�T��	�
�
�d�&�&��.��r-c�h�d}|jd�|�}|j|j|�|S)z�
        Calling L{_InputStream.read} with a negative integer as an argument
        returns all bytes in the input stream.
        sall of the inputc�$�|jd�S�N���r�r�s r&r;z8InputStreamTestMixin.test_readNegative.<locals>.<lambda>�s��E�J�J�r�N�r-r�r�s   r&�test_readNegativez&InputStreamTestMixin.test_readNegative�s5��
$���-�-�.J�E�R��	�
�
�d�&�&��.��r-c�h�d}|jd�|�}|j|jd�|S)zs
        Calling L{_InputStream.readline} with no argument returns one line from
        the input stream.
        shello
worldc�"�|j�Sr7��readliner�s r&r;z4InputStreamTestMixin.test_readline.<locals>.<lambda>�s
��E�N�N�<L�r-shello
r�r�s   r&�
test_readlinez"InputStreamTestMixin.test_readline�s5��
 ���-�-�.L�e�T��	�
�
�d�&�&�
�3��r-c�h�d}|jd�|�}|j|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
worldc�$�|jd�Sr�r�r�s r&r;z8InputStreamTestMixin.test_readlineSome.<locals>.<lambda>�s��E�N�N�1�<M�r-sgoor�r�s   r&�test_readlineSomez&InputStreamTestMixin.test_readlineSome�s5��"���-�-�.M�u�U��	�
�
�d�&�&��/��r-c�h�d}|jd�|�}|j|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 textc�$�|jd�S)N�r�r�s r&r;z<InputStreamTestMixin.test_readlineMoreThan.<locals>.<lambda>���E�N�N�2�<N�r-ssome lines
r�r�s   r&�test_readlineMoreThanz*InputStreamTestMixin.test_readlineMoreThan�s6��
'���-�-�.N�PU�V��	�
�
�d�&�&��8��r-c�l�d}d�}|j||�}|j|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 linec�B�|j�|j�Sr7r�r�s r&r�z9InputStreamTestMixin.test_readlineTwice.<locals>.readlines���N�N���>�>�#�#r-ssecond line
r�)r"ryr�r�s    r&�test_readlineTwicez'InputStreamTestMixin.test_readlineTwices<��
6��	$�
�-�-�h��>��	�
�
�d�&�&�(8�9��r-c�h�d}|jd�|�}|j|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 linec�$�|jd�Sr7r�r�s r&r;z8InputStreamTestMixin.test_readlineNone.<locals>.<lambda>s��E�N�N�4�<P�r-sthis is one line
r�r�s   r&�test_readlineNonez&InputStreamTestMixin.test_readlineNones7��
:���-�-�.P�RW�X��	�
�
�d�&�&�(=�>��r-c�h�d}|jd�|�}|j|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 twoc�$�|jd�Sr�r�r�s r&r;z<InputStreamTestMixin.test_readlineNegative.<locals>.<lambda>$r�r-sinput stream line one
r�r�s   r&�test_readlineNegativez*InputStreamTestMixin.test_readlineNegatives7��
3���-�-�.N�PU�V��	�
�
�d�&�&�(B�C��r-c�l�d}|jd�|�}|j|jgd��|S)z�
        Calling L{_InputStream.readlines} with no arguments returns a list of
        all lines from the input stream.
        salice
bob
carolc�"�|j�Sr7��	readlinesr�s r&r;z5InputStreamTestMixin.test_readlines.<locals>.<lambda>.s
��E�O�O�<M�r-)salice
sbob
scarolr�r�s   r&�test_readlinesz#InputStreamTestMixin.test_readlines(s6��
%���-�-�.M�u�U��	�
�
�d�&�&�(H�I��r-c�^��d}�jd�|�}�fd�}|j|�|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
0c�$�|jd�S)N�r�r�s r&r;z9InputStreamTestMixin.test_readlinesSome.<locals>.<lambda>9s��E�O�O�A�<N�r-c�4���j|ddddg�y)Nros123
s456
r�)�linesr"s �r&�cbLinesz8InputStreamTestMixin.test_readlinesSome.<locals>.cbLines;s ���
���U�2�A�Y��8�(<�=r-)r�r�)r"ryr�r�s`   r&�test_readlinesSomez'InputStreamTestMixin.test_readlinesSome2s6���$���-�-�.N�PU�V��	>�
	
�
�
�g���r-c�l�d}|jd�|�}|j|jgd��|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 potatoc�$�|jd�S)N�dr�r�s r&r;z=InputStreamTestMixin.test_readlinesMoreThan.<locals>.<lambda>Js��E�O�O�C�<P�r-)sone potato
stwo potato
sthree potator�r�s   r&�test_readlinesMoreThanz+InputStreamTestMixin.test_readlinesMoreThanCs<��8���-�-�.P�RW�X��	�
�
����Q�	
��r-c�p�d}d�}|j||�}|j|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
fooc�D�|jd�|j�S)N�)r�r�r�s r&r�z?InputStreamTestMixin.test_readlinesAfterRead.<locals>.readlinesXs���J�J�q�M��?�?�$�$r-sorld
rEr�)r"ryr�r�s    r&�test_readlinesAfterReadz,InputStreamTestMixin.test_readlinesAfterReadPs@��%��	%�
�-�-�i��?��	�
�
�d�&�&��F�(;�<��r-c�l�d}|jd�|�}|j|jddg�|S)zy
        Calling L{_InputStream.readlines} with L{None} as an argument returns
        all lines from the input.
        sone fish
two fish
c�$�|jd�Sr7r�r�s r&r;z9InputStreamTestMixin.test_readlinesNone.<locals>.<lambda>gs��%�/�/�$�/�r-s	one fish
s	two fish
r�r�s   r&�test_readlinesNonez'InputStreamTestMixin.test_readlinesNone`s>��
(���-�-�/��
��	
�
�
�d�&�&��
�(F�G��r-c�l�d}|jd�|�}|j|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
c�$�|jd�Sr�r�r�s r&r;z=InputStreamTestMixin.test_readlinesNegative.<locals>.<lambda>rs��E�O�O�B�<O�r-s	red fish
s
blue fish
r�r�s   r&�test_readlinesNegativez+InputStreamTestMixin.test_readlinesNegativels;��
)���-�-�.O�QV�W��	�
�
�d�&�&���(G�H��r-c�l�d}|jd�|�}|j|jddg�|S)zV
        Iterating over L{_InputStream} produces lines from the input stream.
        �green eggs
and ham
c��t|�Sr7)�listr�s r&r;z4InputStreamTestMixin.test_iterable.<locals>.<lambda>{s
��D��K�r-sgreen eggs
�and ham
r�r�s   r&�
test_iterablez"InputStreamTestMixin.test_iterablevs:��)���-�-�.G��O��	�
�
�d�&�&��,�(G�H��r-c�p�d}d�}|j||�}|j|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.
        r�c�:�|jd�t|�Sr�)r�r�r�s r&�iteratez<InputStreamTestMixin.test_iterableAfterRead.<locals>.iterate�s���J�J�q�M���;�r-sen eggs
r�r�)r"ryr�r�s    r&�test_iterableAfterReadz+InputStreamTestMixin.test_iterableAfterReads@��)��	�
�-�-�g�u�=��	�
�
�d�&�&��|�(D�E��r-N)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|isv���
�
%�N�	��
����� �
�����"�� 
���r-r|c��eZdZdZd�Zy)�InputStreamBytesIOTestszO
    Tests for L{_InputStream} when it is wrapped around an L{io.BytesIO}.
    c��ddlm}|S)Nr)�BytesIO)�ior�)r"r�s  r&r�z#InputStreamBytesIOTests.getFileType�s
����r-N�r(r)r*r+r�r,r-r&r�r��s���r-r�c��eZdZdZd�Zy)�InputStreamTemporaryFileTestszZ
    Tests for L{_InputStream} when it is wrapped around a L{tempfile.TemporaryFile}.
    c�"�tjSr7)�tempfile�
TemporaryFiler>s r&r�z)InputStreamTemporaryFileTests.getFileType�s���%�%�%r-Nr�r,r-r&r�r��s���&r-r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�StartResponseTestszl
    Tests for the I{start_response} parameter passed to the application object
    by L{WSGIResource}.
    c����t��d�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|S)z�
        The response status passed to the I{start_response} callable is written
        as the status of the response to the request.
        c��d�}|S)Nc�*�|dg�td�S)Nz107 Strange messager,�r�r8s  r&razOStartResponseTests.test_status.<locals>.applicationFactory.<locals>.application�s���3�R�8��B�x�r-r,�ras r&r�z:StartResponseTests.test_status.<locals>.applicationFactory����
 ��r-c����j�jjj�j	d��y)NsHTTP/1.1 107 Strange message�rAr)�written�getvalue�
startswith��ignoredr�r"s ��r&r�z2StartResponseTests.test_status.<locals>.cbRendered�s5����O�O��!�!�)�)�2�2�4�?�?�3��
r-c����Sr7r,ras�r&r;z0StartResponseTests.test_status.<locals>.<lambda>�����G�r-r�r�rRN�rr�r�r��r"r�r�r�r�r�s`    @r&�test_statuszStartResponseTests.test_status�sk���
�.��	�!�6�6�8���>�	�	
�
�
�j�!����������
�D���
	
��r-c����d��fd�}�j|�\}}|j��fd�}�j|t�j	|�S)z�
        The response status passed to the I{start_response} callable MUST be a
        native string in Python 2 and Python 3.
        s200 OKc�,��|�g�td�S)Nr,r�)r9r:�statuss  �r&razEStartResponseTests.test_statusMustBeNativeString.<locals>.application�s����&�"�%���8�Or-c�<���jdt|��y)Nz)status must be str, not b'200 OK' (bytes)�r�r��ryr"s �r&�checkMessagezFStartResponseTests.test_statusMustBeNativeString.<locals>.checkMessage�s������H�#�e�*�Ur-�r�r��
assertFailurer�r�)r"rar�r�rrs`    @r&�test_statusMustBeNativeStringz0StartResponseTests.test_statusMustBeNativeString�sW���
��	��-�-�k�:�������!�	V��!�!�&�)�4�@�@��N�Nr-c��������jtdd��t���fd�}�j�\}}���fd�}|j	|��j||�fd�ddgdgd	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.
        �datetimeToStringc��y)N�Tuesdayr,r,r-r&r;z1StartResponseTests._headersTest.<locals>.<lambda>�r<r-c����fd�}|S)Nc�,��|d��td�Sr�r�)r9r:�
appHeaderss  �r&razPStartResponseTests._headersTest.<locals>.applicationFactory.<locals>.application�s����h�
�3��B�x�r-r,)rars �r&r�z;StartResponseTests._headersTest.<locals>.applicationFactory�s���
 ��r-c�"���jjj�}|jdd�\}}|jd�dd}|j	��ddt
zdgz}|j	��j
||�y)Nr�rfs
s
Date: TuesdaysServer: sTransfer-Encoding: chunked)r)r�r�r��sortrr�)	r�r�r��rest�headerLines�allExpectedHeadersr��expectedHeadersr"s	      ���r&r�z3StartResponseTests._headersTest.<locals>.cbRendered�s�����(�(�0�0�9�9�;�H�$�N�N�;��:�M�G�T�!�-�-��0���4�K�����!0� ��g�%�-�4�"��

�#�#�%����[�*<�=r-c����Sr7r,ras�r&r;z1StartResponseTests._headersTest.<locals>.<lambda>rr-r�r�rRN)�patchrrr�r�r�)r"rrr�r�r�r�r�s```    @r&�_headersTestzStartResponseTests._headersTest�s}���	
�
�
�4�+�->�?��.��	�!�6�6�8���>�	>�	
�
�
�j�!����������
�D���
	
��r-c�.�|jddgddg�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}.
        rrFs	Baz: quuxsFoo: bar�rr>s r&rQzStartResponseTests.test_headerss&��� � �
�_�-��k�/J�
�	
r-c����dg��fd�}�j|�\}}|j��fd�}�j|t�j	|�S)zb
        The headers passed to the I{start_response} callable MUST be a
        sequence.
        �r�rnc�>��|dt���td�Sr�r�)r9r:r�s  �r&razBStartResponseTests.test_headersMustBeSequence.<locals>.application&s����(�D��M�2���8�Or-c�<���jt|�d�y)NzKheaders must be a list, not <(list_?|sequence)iterator .+> [(]\1iterator[)]��assertRegexr�r
s �r&rzCStartResponseTests.test_headersMustBeSequence.<locals>.checkMessage-s�������E�
�C�
r-r)r"rar�r�rr�s`    @r&�test_headersMustBeSequencez-StartResponseTests.test_headersMustBeSequencesY���
$�$��	��-�-�k�:�������!�	��!�!�&�)�4�@�@��N�Nr-c��d�}|j|�\}}tjd��5}|j�|j	|�}ddd�|jdt
��|jt|dj�|jdt|dj��y#1swY�pxYw)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.
        c�*�|dd�td�S)Nr�))�notr�r,r�r8s  r&razEStartResponseTests.test_headersShouldBePlainList.<locals>.applicationCs���(�$6�7���8�Or-T��recordNrfrz8headers should be a list, not (('not', 'list'),) (tuple)�r��warnings�catch_warningsr�r�r�rl�RuntimeWarning�categoryr�rk�r"rar�r��caughts     r&�test_headersShouldBePlainListz0StartResponseTests.test_headersShouldBePlainList6s���	��-�-�k�:����
�
$�
$�D�
1�	2�V��#�#�%��)�)�&�1�F�	2�	
����C��K�(��������);�);�<����F���q�	�!�!�"�	
�	2�	2���"B?�?Cc����d��fd�}�j|�\}}|j��fd�}�j|t�j	|�S)zb
        Each header passed to the I{start_response} callable MUST be a
        sequence.
        r"c�@��|dt��g�td�Sr�r�)r9r:�headers  �r&razFStartResponseTests.test_headersMustEachBeSequence.<locals>.applicationZs����(�T�&�\�N�3���8�Or-c�<���jt|�d�y)Nz[header must be a [(]str, str[)] tuple, not <(tuple_?|sequence)iterator .+> [(]\1iterator[)]r%r
s �r&rzGStartResponseTests.test_headersMustEachBeSequence.<locals>.checkMessageas�������E�
�D�
r-r)r"rar�r�rr8s`    @r&�test_headersMustEachBeSequencez1StartResponseTests.test_headersMustEachBeSequenceSsV���
"��	��-�-�k�:�������!�	��!�!�&�)�4�@�@��N�Nr-c��d�}|j|�\}}tjd��5}|j�|j	|�}ddd�|jdt
��|jt|dj�|jdt|dj��y#1swY�pxYw)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.
        c�0�|dddgg�td�S)Nr�r*�tupler,r�r8s  r&razEStartResponseTests.test_headersShouldEachBeTuple.<locals>.applicationws���(�e�W�%5�$6�7���8�Or-Tr+Nrfrz@header should be a (str, str) tuple, not ['not', 'tuple'] (list)r-r2s     r&�test_headersShouldEachBeTuplez0StartResponseTests.test_headersShouldEachBeTuplejs���	��-�-�k�:����
�
$�
$�D�
1�	2�V��#�#�%��)�)�&�1�F�	2�	
����C��K�(��������);�);�<����N���q�	�!�!�"�	
�	2�	2�r5c���d�}�j|�\}}|j��fd�}�j|t�j	|�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.
        c�,�|ddg�td�S)Nr�)�too�many�cooksr,r�r8s  r&razMStartResponseTests.test_headersShouldEachHaveKeyAndValue.<locals>.application�s���(�%=�$>�?���8�Or-c�<���jdt|��y)Nz?header must be a (str, str) tuple, not ('too', 'many', 'cooks')r	r
s �r&rzNStartResponseTests.test_headersShouldEachHaveKeyAndValue.<locals>.checkMessage�s������T��E�
�
r-r�r"rar�r�rs`    r&�%test_headersShouldEachHaveKeyAndValuez8StartResponseTests.test_headersShouldEachHaveKeyAndValue�sO���	��-�-�k�:�������!�	��!�!�&�)�4�@�@��N�Nr-c����d��fd�}�j|�\}}|j���fd�}�j|t�j	|�S)z�
        Each header key passed to the I{start_response} callable MUST be at
        native string in Python 2 and Python 3.
        skeyc�2��|d�dfg�td�S)Nr�rnr,r�)r9r:r�s  �r&razHStartResponseTests.test_headerKeyMustBeNativeString.<locals>.application�s����(�c�7�^�$4�5���8�Or-c�D���jd��d�t|��y)Nz&header must be (str, str) tuple, not (z
, 'value')r	)ryr�r"s ��r&rzIStartResponseTests.test_headerKeyMustBeNativeString.<locals>.checkMessage�s$������8���z�J��E�
�
r-r)r"rar�r�rr�s`    @r&� test_headerKeyMustBeNativeStringz3StartResponseTests.test_headerKeyMustBeNativeString�sV���
��	��-�-�k�:�������!�	��!�!�&�)�4�@�@��N�Nr-c����d��fd�}�j|�\}}|j���fd�}�j|t�j	|�S)z�
        Each header value passed to the I{start_response} callable MUST be at
        native string in Python 2 and Python 3.
        svaluec�2��|dd�fg�td�S)Nr�r�r,r�)r9r:rns  �r&razJStartResponseTests.test_headerValueMustBeNativeString.<locals>.application�s����(�e�U�^�$4�5���8�Or-c�D���jd��d�t|��y)Nz-header must be (str, str) tuple, not ('key', �)r	)ryr"rns ��r&rzKStartResponseTests.test_headerValueMustBeNativeString.<locals>.checkMessage�s$������?��y��J��E�
�
r-r)r"rar�r�rrns`    @r&�"test_headerValueMustBeNativeStringz5StartResponseTests.test_headerValueMustBeNativeString�sV���
��	��-�-�k�:�������!�	��!�!�&�)�4�@�@��N�Nr-c�*�|jdgdg�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 greatr r>s r&�#test_applicationProvidedContentTypez6StartResponseTests.test_applicationProvidedContentType�s#��� � �
2�3�
/�0�
�	
r-c�*�|jgd�g�S)z�
        If either I{Server} or I{Date} is included in the headers passed to the
        I{start_response} callable, they are disregarded.
        ))�serverr�)�Serverr�)�dater�)�dATEr�r r>s r&�%test_applicationProvidedServerAndDatez8StartResponseTests.test_applicationProvidedServerAndDate�s��
� � �T�VX�
�	
r-c�������t��g���fd���fd�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|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.
        c�l���j�jjj��yr7��appendr)r�r��r��intermediateValuess��r&r,z:StartResponseTests.test_delayedUntilReturn.<locals>.record��&����%�%�g�&7�&7�&?�&?�&H�&H�&J�Kr-c����fd�}|S)Nc3�:�K�|dddg�d����y�w)Nr�rrFr-r,�r9r:r,s  �r&raz[StartResponseTests.test_delayedUntilReturn.<locals>.applicationFactory.<locals>.application�s ������h���(I�J��	���s�r,�rar,s �r&r�zFStartResponseTests.test_delayedUntilReturn.<locals>.applicationFactory�s���
�
�r-c�,���j�dg�y)Nr-r��r�r]r"s ��r&r�z>StartResponseTests.test_delayedUntilReturn.<locals>.cbRendered�s������/�#��7r-c����Sr7r,ras�r&r;z<StartResponseTests.test_delayedUntilReturn.<locals>.<lambda>�rr-r�r�rRNr�r"r�r�r�r�r�r]r,s`    @@@r&�test_delayedUntilReturnz*StartResponseTests.test_delayedUntilReturn�sw����.����	L�	�!�6�6�8���>�	8�	
�
�
�j�!����������
�D���
	
��r-c�������t��g���fd���fd�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|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.
        c�l���j�jjj��yr7rZr\s��r&r,z;StartResponseTests.test_delayedUntilContent.<locals>.recordr^r-c����fd�}|S)Nc3�N�K�|ddg�d����d����y�w)Nr�rr-rEr,ras  �r&raz\StartResponseTests.test_delayedUntilContent.<locals>.applicationFactory.<locals>.applications(������h��(8�9��	���������"%r,rbs �r&r�zGStartResponseTests.test_delayedUntilContent.<locals>.applicationFactory����
��r-c�V���j�d��j�d�y)Nrrf)�assertFalserArds ��r&r�z?StartResponseTests.test_delayedUntilContent.<locals>.cbRendered!s)������/��2�3��O�O�.�q�1�2r-c����Sr7r,ras�r&r;z=StartResponseTests.test_delayedUntilContent.<locals>.<lambda>*rr-r�r�rRNrrfs`    @@@r&�test_delayedUntilContentz+StartResponseTests.test_delayedUntilContentsw����.����	L�	�!�6�6�8���>�	3�	
�
�
�j�!����������
�D���
	
��r-c�������t��g���fd���fd�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|S)	z�
        Content produced by the iterator returned by the application object is
        written to the request as it is produced.
        c�l���j�jjj��yr7rZr\s��r&r,z/StartResponseTests.test_content.<locals>.record>r^r-c����fd�}|S)Nc3�N�K�|ddg�d����d����y�w)Nr��r�6rE�barr,ras  �r&razPStartResponseTests.test_content.<locals>.applicationFactory.<locals>.applicationBs)������h�)@�(A�B���������rlr,rbs �r&r�z;StartResponseTests.test_content.<locals>.applicationFactoryArmr-c����j�j�d�d��j�j�d�d�y�NrrErfsfoobar�r�r�rds ��r&r�z3StartResponseTests.test_content.<locals>.cbRenderedM�I������T�8�8�9K�A�9N�O�QW�X�����+�+�,>�q�,A�B�I�
r-c����Sr7r,ras�r&r;z1StartResponseTests.test_content.<locals>.<lambda>Xrr-r�r�rRNrrfs`    @@@r&�test_contentzStartResponseTests.test_content5sw���
�.����	L�	�!�6�6�8���>�	�	
�
�
�j�!����������
�D���
	
��r-c����t��d�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|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.
        c��d�}|S)Nc�<�|dg�|dg�td�S)N�100 Fooz200 Barr,r�r8s  r&raz^StartResponseTests.test_multipleStartResponse.<locals>.applicationFactory.<locals>.applicationls���i��,��i��,��B�x�r-r,r�s r&r�zIStartResponseTests.test_multipleStartResponse.<locals>.applicationFactoryk���
 �
�r-c����j�jjj�j	d��y)NsHTTP/1.1 200 Bar
r�r�s ��r&r�zAStartResponseTests.test_multipleStartResponse.<locals>.cbRenderedu�3����O�O��!�!�)�)�2�2�4�?�?�@W�X�
r-c����Sr7r,ras�r&r;z?StartResponseTests.test_multipleStartResponse.<locals>.<lambda>rr-r�r�rRNrrs`    @r&�test_multipleStartResponsez-StartResponseTests.test_multipleStartResponsecsk����.��	�!�6�6�8���>�	�
	
�
�
�j�!����������
�D���
	
��r-c����t��d�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|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.
        c��d�}|S)Nc�L�|dgttd�df�td�S)Nr�r�r,)rir�r8s  r&razcStartResponseTests.test_startResponseWithException.<locals>.applicationFactory.<locals>.application�s#���i��i��5�9I�4�-P�Q��B�x�r-r,r�s r&r�zNStartResponseTests.test_startResponseWithException.<locals>.applicationFactory�r�r-c����j�jjj�j	d��y)NsHTTP/1.1 100 Foo
r�r�s ��r&r�zFStartResponseTests.test_startResponseWithException.<locals>.cbRendered�r�r-c����Sr7r,ras�r&r;zDStartResponseTests.test_startResponseWithException.<locals>.<lambda>�rr-r�r�rRNrrs`    @r&�test_startResponseWithExceptionz2StartResponseTests.test_startResponseWithException�sk����.��	�!�6�6�8���>�	�
	
�
�
�j�!����������
�D���
	
��r-c�$�����t��Gd�dt�}	|��#t$r
t��YnwxYwg���fd�}�j	�\}}����fd�}|j|��j
||�fd�ddgdgd	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��eZdZy)�PStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.SomeExceptionN)r(r)r*r,r-r&�
SomeExceptionr��s��r-r�c�����fd�}|S)Nc3��K�|dg�d��	|dg��y#t$r�jt��YywxYw�w)Nr�rEz500 ERR)rr[r)r9r:�excInfo�reraiseds  ��r&razjStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.applicationFactory.<locals>.application�sC������h��+���0�!�)�R��9��$�0��O�O�H�J�/�0�s$�A�
�A�"A�A�A�Ar,)rar�r�s ��r&r�zUStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.applicationFactory�s���
0��r-c����j�jjj�j	d���j�dd�d��j�dd�d��ddj}�d}�jtj|�dtj|�d�y)NsHTTP/1.1 200 OK
rrfro)	rAr)r�r�r�r��tb_next�	traceback�
extract_tb)r��tb1�tb2r�r�r�r"s   ����r&r�zMStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.cbRendered�s�����O�O��!�!�)�)�2�2�4�?�?�@V�W�
�
���X�a�[��^�W�Q�Z�8����X�a�[��^�W�Q�Z�8��1�+�a�.�(�(�C��!�*�C����Y�1�1�#�6�q�9�9�;O�;O�PS�;T�UV�;W�Xr-c����Sr7r,ras�r&r;zKStartResponseTests.test_startResponseWithExceptionTooLate.<locals>.<lambda>�rr-r�r�rRN)rrirrr�r�r�)	r"r�r�r�r�r�r�r�r�s	`     @@@r&�&test_startResponseWithExceptionTooLatez9StartResponseTests.test_startResponseWithExceptionTooLate�s�����.��	�I�	�	!��/�!���	!��j�G�	!����		�!�6�6�8���>�
	Y�	
�
�
�j�!����������
�D���
	
��s�&�<�<c�������t��g���fd���fd�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|S)	z�
        I{start_response} returns the I{write} callable which can be used to
        write bytes to the response body without buffering.
        c�l���j�jjj��yr7rZr\s��r&r,z-StartResponseTests.test_write.<locals>.record�r^r-c����fd�}|S)Nc�j��|ddg�}|d���|d���td�S)Nr�rvrErxr,r�)r9r:r�r,s   �r&razNStartResponseTests.test_write.<locals>.applicationFactory.<locals>.application�s4���%�i�2I�1J�K���f�
����f�
����B�x�r-r,rbs �r&r�z9StartResponseTests.test_write.<locals>.applicationFactory�s���
 ��r-c����j�j�d�d��j�j�d�d�yrzr{rds ��r&r�z1StartResponseTests.test_write.<locals>.cbRenderedr|r-c����Sr7r,ras�r&r;z/StartResponseTests.test_write.<locals>.<lambda>rr-r�r�rRNrrfs`    @@@r&�
test_writezStartResponseTests.test_write�sw���
�.����	L�		�!�6�6�8���>�	�	
�
�
�j�!����������
�D���
	
��r-c���d�}�j|�\}}|j��fd�}�j|t�j	|�S)zj
        The C{write} callable returned from C{start_response} only accepts
        byte strings.
        c�:�|dg�}|d�td�S)Nr��bogusr,r��r9r:r�s   r&razHStartResponseTests.test_writeAcceptsOnlyByteStrings.<locals>.application!s��!�(�B�/�E��'�N���8�Or-c�<���jdt|��y)Nz0Can only write bytes to a transport, not 'bogus'r	r
s �r&rzIStartResponseTests.test_writeAcceptsOnlyByteStrings.<locals>.checkMessage)s������B�C��J�
r-rrEs`    r&� test_writeAcceptsOnlyByteStringsz3StartResponseTests.test_writeAcceptsOnlyByteStringssO���	�
�-�-�k�:�������!�	�
�!�!�&�)�4�@�@��N�Nr-N)r(r)r*r+rrrrQr'r4r:r>rFrJrOrQrWrgrqr~r�r�r�r�r�r,r-r&r�r��s����
%�NO�&/�b
�O�.
�:O�.
�:O�*O�,O�,	
�
�)�V,�\,�\%�N$�L:�x-�^Or-r�c�^�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zy)�ApplicationTestszd
    Tests for things which are done to the application object and the iterator
    it returns.
    c��t|_t�|_|jj�|j	|jj
�yr7)rrru�start�
addCleanup�stopr>s r&�
enableThreadszApplicationTests.enableThreads7s8�����$�,���������������,�,�-r-c	������t��Gd�d�}|���fd�}�j�\}}���fd�}|j|��j||�fd�ddgdg�|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��eZdZd�Zd�Zd�Zy)�+ApplicationTests.test_close.<locals>.Resultc��d|_y)NT��openr>s r&rSz4ApplicationTests.test_close.<locals>.Result.__init__Es	�� ��	r-c3�VK�td�D]}|js�d|fz���y�w�Nr�s%d)�ranger�)r"�is  r&�__iter__z4ApplicationTests.test_close.<locals>.Result.__iter__Hs,�����q��+�A��y�y�#�q�d�l�*�+�s�)�)c��d|_y)NFr�r>s r&�closez1ApplicationTests.test_close.<locals>.Result.closeMs	��!��	r-N�r(r)r*rSr�r�r,r-r&�Resultr�Ds��
!�
+�

"r-r�c����fd�}|S)Nc���|ddg��S)Nr��r�3r,)r9r:r�s  �r&razLApplicationTests.test_close.<locals>.applicationFactory.<locals>.applicationSs����h�)@�(A�B��
r-r,r�s �r&r�z7ApplicationTests.test_close.<locals>.applicationFactoryRs���
��r-c�����j�j�jjj	��d��j�j�y)Ns012)r�r�r)r�r�ror�)r�r�r�r"s ���r&r�z/ApplicationTests.test_close.<locals>.cbRendered[sK�������+�+�G�,=�,=�,E�,E�,N�,N�,P�Q��
�
���V�[�[�)r-c����Sr7r,ras�r&r;z-ApplicationTests.test_close.<locals>.<lambda>es����r-r�r�rRr)r"r�r�r�r�r�r�r�s`     @@r&�
test_closezApplicationTests.test_close=su���
�.��
	"�
	"����	�!�6�6�8���>�	*�	
�
�
�j�!�����.����r�TV�SW�	
��r-c	������j�g��fd�}�j�\}}��fd�}|j|��j||tddgdg�|S)zu
        The application object is invoked and iterated in a thread which is not
        the reactor thread.
        c����fd�}|S)Nc�b���fd�}�jt��|ddg�|�S)Nc3�p�K�td�D]#}�jt��d|fz���%y�wr�)r�r[r)r��invokeds �r&r�zpApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory.<locals>.application.<locals>.resultts4�����"�1�X�+�����{�}�5�#�q�d�l�*�+�s�36r�r�)r[r)r9r:r�r�s   �r&raz`ApplicationTests.test_applicationCalledInThread.<locals>.applicationFactory.<locals>.applicationss-���+�
���{�}�-��h�)@�(A�B��x�r-r,)rar�s �r&r�zKApplicationTests.test_applicationCalledInThread.<locals>.applicationFactoryrs���
 ��r-c����jt����jtt	���d�y)Nrf)�assertNotInrr�rl�set�r�r�r"s ��r&r�zCApplicationTests.test_applicationCalledInThread.<locals>.cbRendered�s.������[�]�G�4����S��W��.��2r-r�r�rR)r�r�r�r�r)r"r�r�r�r�r�s`    @r&�test_applicationCalledInThreadz/ApplicationTests.test_applicationCalledInThreadjsl���
	
������	�!�6�6�8���>�	3�	
�
�
�j�!�����.��e�U�B�QS�PT�	
��r-c	������j�g�G�fd�dt�}d�}�j|�\}}��fd�}|j|��j	||t
ddgdg�|S)z�
        The I{write} callable returned by I{start_response} calls the request's
        C{write} method in the reactor thread.
        c���eZdZ�fd�Zy)�CApplicationTests.test_writeCalledFromThread.<locals>.ThreadVerifierc�b���jt��tj||�Sr7�r[rrr��r"ryr�s  �r&r�zIApplicationTests.test_writeCalledFromThread.<locals>.ThreadVerifier.write��"������{�}�-��}�}�T�5�1�1r-N�r(r)r*r��r�s�r&�ThreadVerifierr������
2r-r�c��d�}|S)Nc�:�|dg�}|d�td�S)Nr�rEr,r�r�s   r&raz\ApplicationTests.test_writeCalledFromThread.<locals>.applicationFactory.<locals>.application�s��%�h��3���f�
��B�x�r-r,r�s r&r�zGApplicationTests.test_writeCalledFromThread.<locals>.applicationFactory�r�r-c�N���jt��t�h�yr7�r�r�rr�s ��r&r�z?ApplicationTests.test_writeCalledFromThread.<locals>.cbRendered��������S��\�K�M�?�;r-r�r�rR�r�rr�r�r�r�r"r�r�r�r�r�r�s`     @r&�test_writeCalledFromThreadz+ApplicationTests.test_writeCalledFromThread�sz���
	
������	2�W�	2�
	�!�6�6�~�F���>�	<�	
�
�
�j�!�����.��e�U�B�QS�PT�	
��r-c	������j�g�G�fd�dt�}d�}�j|�\}}��fd�}|j|��j	||t
ddgdg�|S)z�
        Strings produced by the iterator returned by the application object are
        written to the request in the reactor thread.
        c���eZdZ�fd�Zy)�MApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.ThreadVerifierc�b���jt��tj||�Sr7r�r�s  �r&r�zSApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.ThreadVerifier.write�r�r-Nr�r�s�r&r�r��r�r-r�c��d�}|S)Nc3�&K�|dg�d��y�w)Nr�rEr,r8s  r&razfApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.applicationFactory.<locals>.application�s�����h��+���s�r,r�s r&r�zQApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.applicationFactory�s��
��r-c�N���jt��t�h�yr7r�r�s ��r&r�zIApplicationTests.test_iteratedValuesWrittenFromThread.<locals>.cbRendered�r�r-r�r�rRr�r�s`     @r&�$test_iteratedValuesWrittenFromThreadz5ApplicationTests.test_iteratedValuesWrittenFromThread�sz���
	
������	2�W�	2�
	�!�6�6�~�F���>�	<�	
�
�
�j�!�����.��e�U�B�QS�PT�	
��r-c	������j�g�G�fd�dt�}d�}�j|�\}}��fd�}|j|��j	||t
ddgdg�|S)zY
        The response status is set on the request object in the reactor thread.
        c���eZdZ�fd�Zy)�EApplicationTests.test_statusWrittenFromThread.<locals>.ThreadVerifierc�d���jt��tj|||�Sr7)r[rr�setResponseCode)r"�coderkr�s   �r&r�zUApplicationTests.test_statusWrittenFromThread.<locals>.ThreadVerifier.setResponseCode�s&������{�}�-��.�.�t�T�7�C�Cr-N)r(r)r*r�r�s�r&r�r��s	���
Dr-r�c��d�}|S)Nc�*�|dg�td�Sr�r�r8s  r&raz^ApplicationTests.test_statusWrittenFromThread.<locals>.applicationFactory.<locals>.application�s���h��+��B�x�r-r,r�s r&r�zIApplicationTests.test_statusWrittenFromThread.<locals>.applicationFactory�r�r-c�N���jt��t�h�yr7r�r�s ��r&r�zAApplicationTests.test_statusWrittenFromThread.<locals>.cbRendered�r�r-r�r�rRr�r�s`     @r&�test_statusWrittenFromThreadz-ApplicationTests.test_statusWrittenFromThread�s|���	
������	D�W�	D�
	�!�6�6�~�F���>�	<�	
�
�
�j�!�����.��e�U�B�QS�PT�	
��r-c	����Gd�dt�}d�_�fd���fd�}�j|�\}}�fd�}|j|��j	||t
ddgd	g��j
|t�S)
z�
        If the request connection is lost while the application object is being
        iterated, iteration is stopped.
        c��eZdZdZd�Zy)�SApplicationTests.test_connectionClosedDuringIteration.<locals>.UnreliableConnectionz�
            This is a request which pretends its connection is lost immediately
            after the first write is done to it.
            c�J�|jttd���y)NzNo more connection)�connectionLostrr)r"rys  r&r�zYApplicationTests.test_connectionClosedDuringIteration.<locals>.UnreliableConnection.write�s���#�#�G�N�;O�,P�$Q�Rr-N)r(r)r*r+r�r,r-r&�UnreliableConnectionr��s
��
�

Sr-r�Fc3�8�K�d��d�_td���w)NrETzShould not have gotten here)�badIterrir>s�r&�appIterzFApplicationTests.test_connectionClosedDuringIteration.<locals>.appIters������L��D�L��9�:�:�s�c����fd�}|S)Nc�$��|dg���S�Nr�r,)r9r:r�s  �r&razfApplicationTests.test_connectionClosedDuringIteration.<locals>.applicationFactory.<locals>.applications����h��+��y� r-r,)rar�s �r&r�zQApplicationTests.test_connectionClosedDuringIteration.<locals>.applicationFactorys���
!��r-c�>���j�jd�y)Nz!Should not have resumed iteration)ror�)r�r"s �r&r�zIApplicationTests.test_connectionClosedDuringIteration.<locals>.cbRendereds������T�\�\�+N�Or-r�r�rR)rr�r�r�r�rr
r)r"r�r�r�r�r�r�s`     @r&�$test_connectionClosedDuringIterationz5ApplicationTests.test_connectionClosedDuringIteration�s����	S�7�	S����	;�
	�!�6�6�7K�L���>�	P�	
�
�
�j�!�����.��e�U�B�QS�PT�	
��!�!�!�^�4�4r-c�����t���fd�}�j�\}}��fd�}|j|��j||�fd�ddgdgdg�	|S)Nc����Sr7r,r�s�r&r�zEApplicationTests._internalServerErrorTest.<locals>.applicationFactory�	����r-c�����jt�}�jt|�d��j	�j
jj�jd��y)Nrfs"HTTP/1.1 500 Internal Server Error)	rorGr�rlrAr)r�r�r�)r�rsr�r"s  ��r&r�z=ApplicationTests._internalServerErrorTest.<locals>.cbRendered"sY����+�+�L�9�F����S��[�!�,��O�O��!�!�)�)�2�2�4�?�?�9��
r-c����Sr7r,ras�r&r;z;ApplicationTests._internalServerErrorTest.<locals>.<lambda>1rr-r�r�rRr)r"rar�r�r�r�r�s``    @r&�_internalServerErrorTestz)ApplicationTests._internalServerErrorTestsi����.��	�!�6�6�8���>�	�	
�
�
�j�!����������
�D���
	
��r-c�*�d�}|j|�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.
        c��td���N� This application had some error.�rGr8s  r&razRApplicationTests.test_applicationExceptionBeforeStartResponse.<locals>.applicationBs���A�B�Br-�r
�r"ras  r&�,test_applicationExceptionBeforeStartResponsez=ApplicationTests.test_applicationExceptionBeforeStartResponse<s��	C��,�,�[�9�9r-c�*�d�}|j|�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.
        c�*�|dg�td���Nr�rrr8s  r&razQApplicationTests.test_applicationExceptionAfterStartResponse.<locals>.applicationNs���(�B�'��A�B�Br-rrs  r&�+test_applicationExceptionAfterStartResponsez<ApplicationTests.test_applicationExceptionAfterStartResponseGs��	C��,�,�[�9�9r-c�������	�
�t��tj�t���fd�}�j	�\}�	g�
�	�
fd�}����fd�}|j|��j
||�fd�ddgdgdg�	�j�jj��
djttd	���|S)
Nc����Sr7r,r�s�r&r�zBApplicationTests._connectionClosedTest.<locals>.applicationFactoryYrr-c�<���j�|i|����dSr�)r[)r$r%r��requestss  ��r&�requestFactoryWrapperzEApplicationTests._connectionClosedTest.<locals>.requestFactoryWrapperas#����O�O�N�A�4��4�5��B�<�r-c�f���jdt����d}|d}�j|jt��jt��jjj�}�j|jd���j�|�y)NrfrrgsHTTP/1.1 200 OK)rkrlrmrnrGror)r�r�rAr��assertIn)r��eventr#r�r�rp�responseContentr"s    ����r&�
ebRenderedz:ApplicationTests._connectionClosedTest.<locals>.ebRenderedes�������a��[�!1�2���N�E��m�$�A��!�!�!�'�'�<�8��"�"�<�0��(�(�0�0�9�9�;�H��O�O�H�/�/�0B�C�D��M�M�/�8�4r-c����Sr7r,ras�r&r;z8ApplicationTests._connectionClosedTest.<locals>.<lambda>vrr-r�r�rRrzAll gone)
rrrhrr��
addErrbackr�rAr)�disconnectedr�rr)r"rarr�r�rr r�rpr�rs```    @@@@r&�_connectionClosedTestz&ApplicationTests._connectionClosedTestTs�����.��*�<�<�T�CU�V��	�!�6�6�8���>���	 �
	5�	
���Z� ����!������
�D���
	
�	
����)�)�6�6�7����"�"�7�>�*�+E�#F�G��r-c�6��d��fd�}|j|��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 responsec3�<�K�|dg����td���wrr)r9r:rs  �r&razIApplicationTests.test_applicationExceptionAfterWrite.<locals>.application�s#������(�B�'�!�!��A�B�B�s��r$)r"rars  @r&�#test_applicationExceptionAfterWritez4ApplicationTests.test_applicationExceptionAfterWrite�s)���
O�	�	C�
�)�)�+��G�Gr-c�D��d�G�fd�d�}|j|��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.
        rEc�$��eZdZd�Z�fd�Zd�Zy)�DApplicationTests.test_applicationCloseException.<locals>.Applicationc��|dg�yrr,)r"r9r:s   r&rSzMApplicationTests.test_applicationCloseException.<locals>.Application.__init__�s���h��+r-c3��K����y�wr7r,)r"rs �r&r�zMApplicationTests.test_applicationCloseException.<locals>.Application.__iter__�s
�����%�%�s�	c��td��r
rr>s r&r�zJApplicationTests.test_applicationCloseException.<locals>.Application.close�s��"�#E�F�Fr-Nr�)rs�r&�Applicationr+�s���
,�
&�
Gr-r/r')r"r/rs  @r&�test_applicationCloseExceptionz/ApplicationTests.test_applicationCloseException�s+���!��	G�	G��)�)�+��G�Gr-N)r(r)r*r+r�r�r�r�r�r�rr
rrr$r(r0r,r-r&r�r�1sR���
.�+�Z!�F �D�B�@(5�T �D	:�:�0�dH�"Hr-r�)9r+r�r�r.�sysr�urllib.parserr��zope.interface.verifyr�twisted.internetr�twisted.internet.addressrr�twisted.internet.deferr	r
�twisted.internet.errorr�twisted.internet.testingr�twisted.loggerr
r�twisted.python.failurer�twisted.python.threadabler�twisted.python.threadpoolr�twisted.trial.unittestr�twisted.webr�twisted.web.resourcerr�twisted.web.serverrrr�twisted.web.test.test_webr�twisted.web.wsgirrr/r4rsr�r|r�r�r�r�r,r-r&�<module>rCs��������*�.�$�=�:�1�9�5�*�1�0�+��4�5�5�2�)���4��$m/��m/�`r�r�jt
�>�8�t
�nd�>�d�N	�2�H��&�$8�(�&�J
O���J
O�ZxH�~�x�xHr-
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!