403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.117.145.188
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python38/lib64/python3.8/site-packages/aiohttp/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python38/lib64/python3.8/site-packages/aiohttp/__pycache__/test_utils.cpython-38.pyc
U

'�7`O�@s dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZddl
mZddlmZmZmZmZmZmZmZmZddl	mZddlmZmZddlmZddlZdd	lm Z m!Z!m"Z"d
dl#m$Z$m%Z%d
dl
m&Z&d
d
l'm Z d
dl(m)Z)d
dl*m+Z+d
dl,m-Z-m.Z.d
dl/m0Z0d
dl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9d
dl:m;Z;e�rxddl<m=Z=ndZ=ej>dk�o�ej?dkZ@eAejd�dd�ZBeAeCejd�dd�ZDeCd�dd�ZEGd d!�d!e�ZFGd"d#�d#eF�ZGGd$d%�d%eF�ZHGd&d'�d'�ZIGd(d)�d)e	jJ�ZKeeeed*�d+d,�ZLegejMfZNejOejPd-feNeQeejMd.�d/d0��ZRejPfeNejMd1�d2d3�ZSdEejMeQdd4�d5d6�ZTejUd�d7d8�ZVdFee=ejWd9�d:d;�ZXdGe+e-d
d
�d-de+e+e+e+dd<d=d>�eAeAeee-eQeeeeeee=eCee5d?�d@dA�ZYe+e+feeedB�dCdD�ZZdS)HzUtilities shared by tests.�N)�ABC�abstractmethod)�
TracebackType)�
TYPE_CHECKING�Any�Callable�Iterator�List�Optional�Type�Union)�mock)�CIMultiDict�CIMultiDictProxy)�URL)�ClientResponse�_RequestContextManager�_WSRequestContextManager�)�
ClientSession�hdrs)�AbstractCookieJar)r)�ClientWebSocketResponse)�sentinel)�HttpVersion�RawRequestMessage)�Signal)�Application�	AppRunner�
BaseRunner�Request�Server�ServerRunner�SockSite�UrlMappingMatchInfo)�_RequestHandler)�
SSLContext�posix�cygwin)�host�returncCs
t|d�S)Nr)�get_port_socket)r)�r,�E/opt/alt/python38/lib64/python3.8/site-packages/aiohttp/test_utils.py�get_unused_port_socket7sr.)r)�portr*cCs8t�tjtj�}tr&|�tjtjd�|�||f�|S)Nr)�socket�AF_INET�SOCK_STREAM�
REUSE_ADDRESS�
setsockopt�
SOL_SOCKET�SO_REUSEADDR�bind)r)r/�sr,r,r-r+;s
r+�r*c
Cs>t�tjtj��$}|�d�|��dW5QR�SQRXdS)z1Return a port that is unused on the current host.)�	127.0.0.1rrN)r0r1r2r7�getsockname)r8r,r,r-�unused_portFs
r<c	@s0eZdZdZeddddd�eeefee	j
eeeee
dd�dd�Zd#ee	j
e
dd�d	d
�Zee
ed�dd
��Zeed�dd�Zeed�dd��Zeed�dd��Zeed�dd��Zdd�dd�Zdd�dd�Zeeeeeeedd�dd�Zdd�dd �Z eeeeeeedd�d!d"�Z!dS)$�BaseTestServerFNr:)�scheme�loopr)r/�skip_url_asserts)r>r?r)r/r@�kwargsr*cKs4||_d|_d|_||_||_d|_||_||_dS)NF)�_loop�runner�_rootr)r/�_closedr>r@)�selfr>r?r)r/r@rAr,r,r-�__init__Ps
zBaseTestServer.__init__)r?rAr*c�s|jr
dS||_|�dd�|_|jf|�IdH|_|j��IdH|jsNd|_t|j|j�}|�	�dd�\|_|_t
|j||jd�}|��IdH|j}|dk	s�t
�|j}|dk	s�t
�|d�	�d|_|jtkr�|jr�d}nd}||_t|j�d|j�d	|j���|_dS)
N�sslr�)�sockZssl_contextr�https�httpz://�:)rCrB�popZ_ssl�_make_runner�setupr/r+r)r;r#�start�_server�AssertionError�socketsr>rrrD)rFr?rA�_sock�site�serverrTr>r,r,r-�start_servercs.
zBaseTestServer.start_server�rAr*c�sdS�Nr,�rFrAr,r,r-rOszBaseTestServer._make_runner��pathr*cCsJ|jdk	st�t|�}|js4|��r(t�|j�|�Stt|j�|�SdSrZ)rDrSrr@�is_absolute�join�str)rFr]�urlr,r,r-�make_url�szBaseTestServer.make_urlr9cCs
|jdk	SrZ)rC�rFr,r,r-�started�szBaseTestServer.startedcCs|jSrZ)rErcr,r,r-�closed�szBaseTestServer.closedcCs&|j}|dk	st�|jdk	s t�|jSrZ)rCrSrW)rFrCr,r,r-�handler�szBaseTestServer.handlerc�s@|jr<|js<|jdk	st�|j��IdHd|_d|_d|_dS)a`Close all fixtures created by the test client.

        After that point, the TestClient is no longer usable.

        This is an idempotent function: running close multiple times
        will not have any additional effects.

        close is also run when the object is garbage collected, and on
        exit when used as a context manager.

        NT)rdrerCrS�cleanuprDr/rErcr,r,r-�close�szBaseTestServer.closecCstd��dS�NzUse async with instead��	TypeErrorrcr,r,r-�	__enter__�szBaseTestServer.__enter__)�exc_type�	exc_value�	tracebackr*cCsdSrZr,�rFrmrnror,r,r-�__exit__�szBaseTestServer.__exit__c�s|j|jd�IdH|S�N�r?)rXrBrcr,r,r-�
__aenter__�szBaseTestServer.__aenter__c�s|��IdHdSrZ�rhrpr,r,r-�	__aexit__�szBaseTestServer.__aexit__)N)"�__name__�
__module__�__qualname__�__test__rrr`�objectr
�asyncio�AbstractEventLoop�int�boolrrGrXrrrOrrb�propertyrdrer!rfrhrlr�
BaseExceptionrrqrtrvr,r,r,r-r=MsV�
���	
�	
�r=csPeZdZeddd�eeeefeee	e
d��fdd�Ze
ed�dd	�Z
�ZS)
�
TestServerr:N�r>r)r/)�appr>r)r/rAcs$||_t�jf|||d�|��dS�Nr�)r��superrG)rFr�r>r)r/rA��	__class__r,r-rG�s	zTestServer.__init__rYc�st|jf|�SrZ)rr�r[r,r,r-rO�szTestServer._make_runner)rwrxryrrrr`r{r
r~rrGrrO�
__classcell__r,r,r�r-r��s�
�r�csVeZdZeddd�eeeefeee	e
dd��fdd�Zdee
e
d�d	d
�Z�ZS)�
RawTestServerr:Nr�)rfr>r)r/rAr*cs$||_t�jf|||d�|��dSr�)�_handlerr�rG)rFrfr>r)r/rAr�r,r-rG�s	zRawTestServer.__init__T)�debugrAr*c�s.t|jf|j|d�|��}t|fd|i|��S)N)r?r�r�)r!r�rBr")rFr�rAZsrvr,r,r-rO�szRawTestServer._make_runner)T)rwrxryrr%rr`r{r
r~rrGrr"rOr�r,r,r�r-r��s�
�r�c@s�eZdZdZdZddd�eeeeej	e
dd�dd�Zdd�d	d
�Ze
ed�dd��Ze
eed�d
d��Ze
ed�dd��Ze
ed�dd��Ze
ed�dd��Zeed�dd�Zeee
ed�dd�Zeee
ed�dd�Zee
ed�dd�Zee
ed�d d!�Zee
ed�d"d#�Zee
ed�d$d%�Z ee
ed�d&d'�Z!ee
ed�d(d)�Z"ee
ed�d*d+�Z#ee
e$d�d,d-�Z%ee
e&d�d.d/�Z'dd�d0d1�Z(dd�d2d3�Z)ee*e+ee+ee,dd4�d5d6�Z-dd�d7d8�Z.ee*e+ee+ee,dd4�d9d:�Z/dS);�
TestClientzb
    A test client implementation.

    To write functional tests for aiohttp based servers.

    FN)�
cookie_jarr?)rWr�r?rAr*cKsht|t�stdt|���||_||_|dkr<tjd|d�}tf||d�|��|_	d|_
g|_g|_dS)Nz2server must be TestServer instance, found type: %rT)Zunsafer?)r?r�F)
�
isinstancer=rk�typerRrB�aiohttpZ	CookieJarr�_sessionrE�
_responses�_websockets)rFrWr�r?rAr,r,r-rG�s

�zTestClient.__init__r9c�s|jj|jd�IdHdSrr)rRrXrBrcr,r,r-rXszTestClient.start_servercCs|jjSrZ)rRr)rcr,r,r-r)szTestClient.hostcCs|jjSrZ)rRr/rcr,r,r-r/szTestClient.portcCs|jSrZ)rRrcr,r,r-rWszTestClient.servercCst|jdd�S)Nr�)�getattrrRrcr,r,r-r�szTestClient.appcCs|jS)z�An internal aiohttp.ClientSession.

        Unlike the methods on the TestClient, client session requests
        do not automatically include the host in the url queried, and
        will require an absolute path to the resource.

        )r�rcr,r,r-�sessions	zTestClient.sessionr\cCs|j�|�SrZ)rRrb)rFr]r,r,r-rb)szTestClient.make_url)�methodr]rAr*c�s.|jj||�|�f|�IdH}|j�|�|SrZ)r��requestrbr��append)rFr�r]rA�respr,r,r-�_request,szTestClient._requestcKst|j||f|��S)z�Routes a request to tested http server.

        The interface is identical to aiohttp.ClientSession.request,
        except the loop kwarg is overridden by the instance used by the
        test server.

        )rr�)rFr�r]rAr,r,r-r�2szTestClient.request)r]rAr*cKst|jtj|f|��S)zPerform an HTTP GET request.)rr�rZMETH_GET�rFr]rAr,r,r-�get<szTestClient.getcKst|jtj|f|��S)zPerform an HTTP POST request.)rr�rZ	METH_POSTr�r,r,r-�post@szTestClient.postcKst|jtj|f|��S)z Perform an HTTP OPTIONS request.)rr�rZMETH_OPTIONSr�r,r,r-�optionsDszTestClient.optionscKst|jtj|f|��S)zPerform an HTTP HEAD request.)rr�rZ	METH_HEADr�r,r,r-�headHszTestClient.headcKst|jtj|f|��S)zPerform an HTTP PUT request.)rr�rZMETH_PUTr�r,r,r-�putLszTestClient.putcKst|jtj|f|��S�zPerform an HTTP PATCH request.)rr�rZ
METH_PATCHr�r,r,r-�patchPszTestClient.patchcKst|jtj|f|��Sr�)rr�rZMETH_DELETEr�r,r,r-�deleteTszTestClient.deletecKst|j|f|��S)zjInitiate websocket connection.

        The api corresponds to aiohttp.ClientSession.ws_connect.

        )r�_ws_connectr�r,r,r-�
ws_connectXszTestClient.ws_connectc�s,|jj|�|�f|�IdH}|j�|�|SrZ)r�r�rbr�r�)rFr]rA�wsr,r,r-r�`szTestClient._ws_connectc�s^|jsZ|jD]}|��q|jD]}|��IdHq |j��IdH|j��IdHd|_dS)aHClose all fixtures created by the test client.

        After that point, the TestClient is no longer usable.

        This is an idempotent function: running close multiple times
        will not have any additional effects.

        close is also run on exit when used as a(n) (asynchronous)
        context manager.

        NT)rEr�rhr�r�rR)rFr�r�r,r,r-rhes


zTestClient.closecCstd��dSrirjrcr,r,r-rlzszTestClient.__enter__)rm�exc�tbr*cCsdSrZr,�rFrmr�r�r,r,r-rq}szTestClient.__exit__c�s|��IdH|SrZ)rXrcr,r,r-rt�szTestClient.__aenter__c�s|��IdHdSrZrur�r,r,r-rv�szTestClient.__aexit__)0rwrxry�__doc__rzr=r
rr|r}rrGrXr�r`r)r~r/rWrr�rr�rrbrr�rr�r�r�r�r�r�r�r�rr�rr�rhrlrr�rrqrtrvr,r,r,r-r��s^��


�	
�r�c@s�eZdZdZed�dd�Zed�dd�Zdd�dd	�Zdd�d
d�Zdd�dd
�Z	dd�dd�Z
eed�dd�Zee
d�dd�ZdS)�AioHTTPTestCaseaA base class to allow for unittest web applications using
    aiohttp.

    Provides the following:

    * self.client (aiohttp.test_utils.TestClient): an aiohttp test client.
    * self.loop (asyncio.BaseEventLoop): the event loop in which the
        application and server are running.
    * self.app (aiohttp.web.Application): the application returned by
        self.get_application()

    Note that the TestClient's methods are asynchronous: you have to
    execute function on the test client using asynchronous methods.
    r9c�s|��S)zy
        This method should be overridden
        to return the aiohttp.web.Application
        object to test.

        )�get_apprcr,r,r-�get_application�szAioHTTPTestCase.get_applicationcCstd��dS)zqObsolete method used to constructing web application.

        Use .get_application() coroutine instead

        z+Did you forget to define get_application()?N)�RuntimeErrorrcr,r,r-r��szAioHTTPTestCase.get_appNcCslt�|_|j�|���|_|j�|�|j��|_|j�|�|j��|_|j�|j�	��|j�|�
��dSrZ)�setup_test_loopr?�run_until_completer�r��
get_serverrW�
get_client�clientrX�
setUpAsyncrcr,r,r-�setUp�szAioHTTPTestCase.setUpc�sdSrZr,rcr,r,r-r��szAioHTTPTestCase.setUpAsynccCs0|j�|���|j�|j���t|j�dSrZ)r?r��
tearDownAsyncr�rh�teardown_test_looprcr,r,r-�tearDown�szAioHTTPTestCase.tearDownc�sdSrZr,rcr,r,r-r��szAioHTTPTestCase.tearDownAsync)r�r*c�st||jd�S)zReturn a TestServer instance.rs)r�r?)rFr�r,r,r-r��szAioHTTPTestCase.get_server)rWr*c�st||jd�S)zReturn a TestClient instance.rs)r�r?)rFrWr,r,r-r��szAioHTTPTestCase.get_client)rwrxryr�rr�r�r�r�r�r�r�r�r�r�r,r,r,r-r��s	r�)�func�argsrAr*cs.tj�f|�|�ttttd��fdd��}|S)z�A decorator dedicated to use with asynchronous methods of an
    AioHTTPTestCase.

    Handles executing an asynchronous function, using
    the self.loop of the AioHTTPTestCase.
    )rF�
inner_args�inner_kwargsr*cs|j��|f|�|��SrZ)r?r�)rFr�r��r�r,r-�new_func�sz#unittest_run_loop.<locals>.new_func)�	functools�wrapsr)r�r�rAr�r,r�r-�unittest_run_loop�sr�F)�loop_factory�fastr*ccst|�}|Vt||d�dS)zzA contextmanager that creates an event_loop, for test purposes.

    Handles the creation and cleanup of a test loop.
    )r�N)r�r�)r�r�r?r,r,r-�loop_context�sr�)r�r*c	Cs�|�}z|jj}d|k}Wntk
r2d}YnXt�|�tjdkr�|s�t��}t��}|�	|�t
�t��|�
|�W5QRX|S)z�Create and return an asyncio.BaseEventLoop
    instance.

    The caller should also call teardown_test_loop,
    once they are done with the loop.
    ZuvloopT�win32)r�rx�AttributeErrorr|�set_event_loop�sys�platformZget_event_loop_policyZSafeChildWatcherZattach_loop�
contextlib�suppress�NotImplementedErrorZset_child_watcher)r�r?�moduleZskip_watcher�policyZwatcherr,r,r-r��s	


r�)r?r�r*cCsB|��}|s(|�|j�|��|��|s4t��t�d�dS)zHTeardown and cleanup an event_loop created
    by setup_test_loop.

    N)	Z	is_closedZ	call_soon�stopZrun_foreverrh�gcZcollectr|r�)r?r�rer,r,r-r�sr�cCs^tttd�dd�}tttdd�dd�}t��}i|_||_||_d|_t|�|_	|j	�
�|S)N)r��keyr*cSs
|j|SrZ��
__app_dict)r�r�r,r,r-�get_dictsz"_create_app_mock.<locals>.get_dict)r�r��valuer*cSs||j|<dSrZr�)r�r�r�r,r,r-�set_dict!sz"_create_app_mock.<locals>.set_dictF)rr`r
�	MagicMockr��__getitem__�__setitem__Z_debugrZon_response_prepareZfreeze)r�r�r�r,r,r-�_create_app_mocks

r�)�
sslcontextr*cs,t��}tttd��fdd�}||j_|S)N)r�r*cs|dkr�SdSdS)Nr�r,)r��r�r,r-�get_extra_info2sz)_create_transport.<locals>.get_extra_info)r
�Mockr`r
r&r��side_effect)r��	transportr�r,r�r-�_create_transport/sr�i.)�
match_info�version�closingr��writer�protocolr��payloadr��client_max_sizer?)r�r]�headersr�r�r�r�r�r�r�r�r�r�r?r*cCstt��}|
dkr t��}
d|
j_|tdd�kr2d}|rZtt|��}tdd�|��D��}ntt��}d}d|�	t
jd���k}t
||||||d	d	|t|��
}|d
kr�t�}|	tkr�t|�}	|tkr�t��}|	|_|tk�rt��}td
�|_td
�|_td
�|_td
�|_|	|_|	|_||_|
tk�r.t��}
t||
||||
|d�}t|tk�rTin|t���}|�|�||_|S)z�Creates mocked web.Request testing purposes.

    Useful in unit tests, when spinning full web server is overkill or
    specific conditions and errors are hard to trigger.

    .r,rTcss&|]\}}|�d�|�d�fVqdS)zutf-8N)�encode)�.0�k�vr,r,r-�	<genexpr>^sz&make_mocked_request.<locals>.<genexpr>�chunked�FN)r�)r
r�Z
create_future�return_valuerrr�tuple�itemsr�rZTRANSFER_ENCODING�lowerrrr�rr�r��make_mocked_coroZ
write_headers�writeZ	write_eofZdrainr�r r$Zadd_appZ_match_info)r�r]r�r�r�r�r�r�r�r�r�r�r�r?ZtaskZraw_hdrsr��message�reqr,r,r-�make_mocked_request<sx�

�





��
r�)r��raise_exceptionr*cs$tttd���fdd�}tj|d�S)zCreates a coroutine mock.)r�rAr*c�s(�tk	r��t���s�S�IdHdSrZ)r�inspect�isawaitable)r�rA�r�r�r,r-�	mock_coro�s

z#make_mocked_coro.<locals>.mock_coro)r�)rr
r�)r�r�r�r,r�r-r��sr�)F)N)N)[r�r|r�r�r�r��osr0r�Zunittest�abcrr�typesr�typingrrrrr	r
rrr
Z	multidictrrZyarlrr�Zaiohttp.clientrrrr�rrrZ
client_reqrepZ	client_wsrZhelpersrrLrrZsignalsrZwebrrrr r!r"r#r$Zweb_protocolr%rHr&�namer�r3r`r.r~r+r<r=r�r�r�ZTestCaser�r�r}Z
_LOOP_FACTORY�contextmanagerZnew_event_looprr�r�r�r�r�r�r�r�r�r,r,r,r-�<module>s�((
|(@��
�����]��

Youez - 2016 - github.com/yon3zu
LinuXploit