HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/aiohttp/__pycache__/web_protocol.cpython-310.pyc
o

���gd�
@s$ddlZddlZddlZddlZddlZddlmZddlmZddl	m
Zddlm
Z
ddlmZddlmZmZmZmZmZmZmZmZmZmZmZddlZddlZdd	lmZm Z dd
l!m"Z"ddl#m$Z$ddlm%Z%m&Z&m'Z'm(Z(m)Z)dd
l*m+Z+ddl,m-Z-m.Z.ddl/m0Z0m1Z1ddl2m3Z3ddl4m5Z5m6Z6ddl7m8Z8ddl9m:Z:ddl;m<Z<m=Z=dZ>er�ddl?m@Z@ee(e1de dge:fZAee:gee=fZBe(dde'iidddde�Cd��
ZDGdd�deE�ZFGdd �d eE�ZGeG�ZHejIdddd!�Gd"d#�d#��ZJeee(eJfe1fZKGd$d�de"�ZLdS)%�N)�deque)�suppress)�escape)�
HTTPStatus)�Logger)�
TYPE_CHECKING�Any�	Awaitable�Callable�Deque�Optional�Sequence�Tuple�Type�Union�cast�)�AbstractAccessLogger�AbstractStreamWriter)�BaseProtocol)�ceil_timeout)�HttpProcessingError�HttpRequestParser�
HttpVersion10�RawRequestMessage�StreamWriter)�
BadHttpMethod)�
access_logger�
server_logger)�
EMPTY_PAYLOAD�StreamReader)�
tcp_keepalive)�
HTTPException�HTTPInternalServerError)�AccessLogger)�BaseRequest)�Response�StreamResponse)�RequestHandler�RequestPayloadError�PayloadAccessError)�Serverr(zasyncio.Task[None]�UNKNOWN�/TFc@�eZdZdZdS)r)zPayload parsing error.N��__name__�
__module__�__qualname__�__doc__�r4r4�?/usr/local/lib/python3.10/dist-packages/aiohttp/web_protocol.pyr)P�r)c@r.)r*z-Payload was accessed after response was sent.Nr/r4r4r4r5r*Tr6r*)�auto_attribs�frozen�slotsc@s&eZdZUeed<eed<eed<dS)�_ErrInfo�status�exc�messageN)r0r1r2�int�__annotations__�
BaseException�strr4r4r4r5r:[s
r:c!sFeZdZdZdZddeeeejdddddd	dd
d�dd
de	j
dedede
deede
dededededededededef �fdd�Zdefd d!�Zedefd"d#��Zd\d%eedd&fd'd(�Zd)e	jdd&f�fd*d+�Zd,eedd&f�fd-d.�Zd/edd&fd0d1�Zd]d2d3�Zd4edd&fd5d6�Z d7edd&fd8d9�Z!d]d:d;�Z"d]d<d=�Z#d>e$d?e%d@edd&fdAdB�Z&dCedDedd&fdEdF�Z'dCedDedd&fdGdH�Z(d]dIdJ�Z)d>e$dKedLe*e$ge+e%fde,e%effdMdN�Z-d]dOdP�Z.d>e$dQe%dKede,e%effdRdS�Z/	T	&	&d^d>e$dUed,eedVeede%f
dWdX�Z0dYe1de*e$ge+e%ffdZd[�Z2�Z3S)_r(ajHTTP protocol implementation.

    RequestHandler handles incoming HTTP request. It reads request line,
    request headers and request payload and calls handle_request() method.
    By default it always returns with 404 response.

    RequestHandler handles errors in incoming request, like bad
    status line, bad headers or incomplete payload. If any error occurs,
    connection gets closed.

    keepalive_timeout -- number of seconds before closing
                         keep-alive connection

    tcp_keepalive -- TCP keep-alive is on, default is on

    debug -- enable debug mode

    logger -- custom logger object

    access_log_class -- custom class for access_logger

    access_log -- custom logging object

    access_log_format -- access log format string

    loop -- Optional event loop

    max_line_size -- Optional maximum header line size

    max_field_size -- Optional maximum header field size

    max_headers -- Optional maximum header size

    timeout_ceil_threshold -- Optional value to specify
                              threshold to ceil() timeout
                              values

    )�_request_count�
_keepalive�_manager�_request_handler�_request_factory�_tcp_keepalive�_next_keepalive_close_time�_keepalive_handle�_keepalive_timeout�_lingering_time�	_messages�
_message_tail�_handler_waiter�_waiter�
_task_handler�_upgrade�_payload_parser�_request_parser�_reading_paused�logger�debug�
access_logr�_close�_force_close�_current_request�_timeout_ceil_threshold�_request_in_progressi.TFi�i�g$@i�)�keepalive_timeoutr!rU�access_log_classrW�access_log_formatrV�
max_line_size�max_headers�max_field_size�lingering_time�read_bufsize�auto_decompress�timeout_ceil_threshold�managerr+�loopr^r!rUr_rWr`rVrarbrcrdrerfrgc
st��|�d|_d|_d|_||_|j|_|j|_	||_
d|_d|_||_
t|
�|_t�|_d|_d|_d|_d|_d|_d|_t||||
||t|d�|_d|_zt|�|_WnttfycYnw||_|	|_||_ |rv|||�|_!nd|_!d|_"d|_#d|_$dS)NrFg�)rarcrb�payload_exceptionrfr])%�super�__init__rBrCrZrD�request_handlerrE�request_factoryrFrGrHrIrJ�floatrKrrLrMrOrNrPrQrRrr)rSr[�	TypeError�
ValueErrorrUrVrWrrXrYr\)�selfrhrir^r!rUr_rWr`rVrarbrcrdrerfrg��	__class__r4r5rm�s\
���
zRequestHandler.__init__�returncCs d�|jj|jdur
d�Sd�S)Nz<{} {}>�	connected�disconnected)�formatrur0�	transport�rsr4r4r5�__repr__�s��zRequestHandler.__repr__cCs|jS�N)rJr{r4r4r5r^sz RequestHandler.keepalive_timeout�.@�timeoutNc	�s��d|_|jdur|j��|jr^|j��|_z&t|�4IdH�|jIdHWd�IdHn1IdHs7wYWn tj	tj
fy]d|_tjdkr[t�
�}r[|��r[�Ynwz@t|�4IdH�+|jduru|j�t�	��|jdur�|j��s�t�|j�IdHWd�IdHn1IdHs�wYWntj	tj
fy�tjdkr�t�
�}r�|��r��Ynw|jdur�|j��|��dS)z�Do worker process exit preparations.

        We need to clean up everything and stop accepting requests.
        It is especially important for keep-alive connections.
        TN���)rYrI�cancelr\�_loop�
create_futurerNr�asyncio�CancelledError�TimeoutError�sys�version_info�current_task�
cancellingrZ�_cancelrP�done�shield�force_close)rsr�taskr4r4r5�shutdownsT�

(��

����	
�(��

����
	
zRequestHandler.shutdownrzcs�t��|�ttj|�}|jrt|�|jdusJ�|j�||�|j}t	j
dkr4tj|��|dd�}n|�
|���}||_dS)N�r��T�ri�eager_start)rl�connection_maderr��	TransportrGr!rDr�r�r��Task�start�create_taskrP)rsrz�real_transportrir�rtr4r5r�6s

zRequestHandler.connection_mader<cs�|jdurdS|j�||�|jj}|��t��|�d|_d|_d|_d|_|jdur2|j�	�|j
durE|dur?td�}|j
�|�|rQ|j
durQ|j
�	�d|_
|jdurc|j��d|_dSdS)NzConnection lost)rD�connection_lost�handler_cancellationr�rlrFrErSrIr�rZ�ConnectionResetErrorr�rPrR�feed_eof)rsr<r�rtr4r5r�Gs.







�zRequestHandler.connection_lost�parsercCs6|jdusJ�||_|jr|j�|j�d|_dSdS)Nrj)rRrM�	feed_data)rsr�r4r4r5�
set_parsergs
�zRequestHandler.set_parsercCsdSr}r4r{r4r4r5�eof_receivedqszRequestHandler.eof_received�datac

CsN|js|jrdS|jdur~|js~|jdusJ�z|j�|�\}}}Wn!tyC}ztd||jd�t	fg}d}d}WYd}~nd}~ww|pGdD]\}}|j
d7_
|j�||f�qH|j
}|rn|durn|��sn|�d�||_|rz|r|||_dSdSdS|jdur�|jr�|r�|j|7_dS|r�|j�|�\}	}|	r�|��dSdSdS)Ni�)r;r<r=Frjr4r)rYrXrRrQrSr�rr:r=rrBrL�appendrOr��
set_resultrM�close)
rsr��messages�upgraded�tailr<�msg�payload�waiter�eofr4r4r5�
data_receivedts>���

��zRequestHandler.data_received�valcCs$||_|jr|j��d|_dSdS)zMSet keep-alive connection mode.

        :param bool val: new state.
        N)rCrIr�)rsr�r4r4r5�
keep_alive�s


�zRequestHandler.keep_alivecCsd|_|jr
|j��dSdS)z�Close connection.

        Stop accepting new pipelining messages and close
        connection when handlers done processing messages.
        TN)rXrOr�r{r4r4r5r��s�zRequestHandler.closecCs8d|_|jr|j��|jdur|j��d|_dSdS)zForcefully close connection.TN)rYrOr�rzr�r{r4r4r5r��s



�zRequestHandler.force_close�request�response�timecCs8|jdur|jjr|j�|||j��|�dSdSdSr})r�enabled�logr�r�)rsr�r�r�r4r4r5�
log_access�s�zRequestHandler.log_access�args�kwcOs |jr|jj|i|��dSdSr})rVrU�rsr�r�r4r4r5�	log_debug�s�zRequestHandler.log_debugcOs|jj|i|��dSr})rU�	exceptionr�r4r4r5�
log_exception�szRequestHandler.log_exceptioncCsjd|_|js	|jsdS|j}|��}|j}||kr#|�||j�|_dS|jr1|j�	�s3|�
�dSdSdSr})rIrYrCr�r�rH�call_at�_process_keepaliverOr�r�)rsri�now�
close_timer4r4r5r��s�z!RequestHandler._process_keepalive�
start_timernc
�s��d|_z�zz||_||�IdH}Wd|_nd|_wWnwty;}z|}|�|||�IdH\}}WYd}~ntd}~wtjyC�tjyn}z|jd|d�|�|d�}|�|||�IdH\}}WYd}~nAd}~wt	y�}z|�|d|�}|�|||�IdH\}}WYd}~nd}~wwt
|dd�r�t�dt
�|�|||�IdH\}}Wd|_|jdur�|j�d�||fSd|_|jdur�|j�d�ww)	NTzRequest handler timed out.��exc_infoi����__http_exception__Fzlreturning HTTPException object is deprecated (#2415) and will be removed, please raise the exception instead)r\rZr"�finish_responser�r�r�r��handle_error�	Exception�getattr�warnings�warn�DeprecationWarningrNr�)rsr�r�rn�respr<�resetr4r4r5�_handle_request�sL�$�$�$����
�
�zRequestHandler._handle_requestc
�s<�|j}t�|�}|dusJ�|j}|dusJ�|j}d}|jdus$J�|jdus+J�|j�s�|jsGz|�	�|_
|j
IdHWd|_
nd|_
w|j��\}}|��}|j
d7_
t||�}	t|t�rk|�|�}
t}n|j}
|�||||	|�}�zȐz[|�|||
�}tjdkr�tj||dd�}
n|�|�}
z	|
IdH\}}WnJty�|�d�YWW|jdur�|dur�|�d��n�|js�|jr�|js�|dur�|��}||}||_|jdur�|�||j �|_�n��n��n�w~
|�r6|�d�WW|jdu�r|du�r|�d��n�|j�s4|j�r2|j�s2|du�r0|��}||}||_|jdu�r0|�||j �|_�nT�nR�nPt!|j"�|_|�#��s�|j$}|j�s�|�r�|�d	|�|��}||}zB|�#��s�||k�r�t%||�4IdH�|�&�IdHWd�IdHn1IdH�s�wY|��}|�#��s�||k�sdWn!tj'tj(f�y�tjd
k�r�t��}�r�|�)��r��Ynw|�#��s�|j�s�|�d�|�*�|�+t,�Wn,tj'�y�|�d��t-�y}z|j.d|d
�|�/�WYd}~nd}~wwW|jdu�r|du�r|�d�no|j�s@|j�r?|j�s?|du�r>|��}||}||_|jdu�r>|�||j �|_nDnFnB|jdu�rR|du�rR|�d�w|j�s�|j�r}|j�s}|du�r||��}||}||_|jdu�r||�||j �|_wYnw|jr/|j�s�d|_0|jdu�r�|j�*�dSdSdS)a_Process incoming request.

        It reads request line, request headers and request payload, then
        calls handle_request() method. Subclass has to override
        handle_request(). start() handles various exceptions in request
        or response handling. Connection is being closed always unless
        keep_alive(True) specified.
        Nrr�Tr�z&Ignored premature client disconnectionz'Ignored premature client disconnection.z(Ignored premature client disconnection 2z'Start lingering close timer for %s sec.r�zUncompleted request.zUnhandled exceptionr�)1r�r�r�rDrJrFrErYrLr�rO�popleftr��requests_countr�
isinstancer:�_make_error_handler�ERRORr�r�r�r�r��ConnectionErrorr�rzrCrXrHrIr�r��boolr��is_eofrKr�readanyr�r�r�r��
set_exception�_PAYLOAD_ACCESS_ERRORr�r�r�rP)rsri�handlerrhr^r�r=r�r��writerrnr��coror�r�r�r�rd�end_t�tr<r4r4r5r�s"�	







2
����
,
����
�*���
����	

���
����

�
��e�zRequestHandler.startr�c	�s�|��|jdur |j�d�d|_|jr |j�|j�d|_z|j}Wn-tyR|dur6|�d�n|�d�	|��t
�}t|j|j
|j|jd�}|j}Ynwz||�IdH|��IdHWntyw|�|||�|dfYSw|�|||�|dfS)aPrepare the response and write_eof, then log access.

        This has to
        be called within the context of any exception so the access logger
        can get exception information. Returns True if the client disconnects
        prematurely.
        NFrjz+Missing return statement on request handlerz7Web-handler should return a response instance, got {!r})r;�reason�text�headersT)�_finishrS�set_upgradedrQrMr��prepare�AttributeErrorr�ryr#r&r;r�r�r��	write_eofr�r�)rsr�r�r��prepare_methr<r4r4r5r�~s@�


��
�
�zRequestHandler.finish_responser�r;r=c
Cs|jdkrt|t�r|jjd|j|d�n	|jd|j|d�|jjdkr(t	d��d}|t
jkrd�t
j�}t
jj
}d}|jrVtt��t��}Wd�n1sQwYd	|j�d
d�vru|rkt|�}d|�d
�}dj||d�}d	}n
|ry|}|d|}t|||d�}	|	��|	S)z�Handle errors.

        Returns HTTP response with specific status code. Logs additional
        information. It always closes current connection.
        rzError handling request from %sr�rzMResponse is sent already, cannot send another response with the error messagez
text/plainz{0.value} {0.phrase}Nz	text/html�Accept�z<h2>Traceback:</h2>
<pre>z</pre>zV<html><head><title>{title}</title></head><body>
<h1>{title}</h1>
{msg}
</body></html>
)�titler�z

)r;r��content_type)rBr�rrUrV�remoter�r��output_sizer�r�INTERNAL_SERVER_ERRORry�descriptionrr��	traceback�
format_excr��get�html_escaper&r�)
rsr�r;r<r=�ctr�r��tbr�r4r4r5r��sD���


��zRequestHandler.handle_error�err_infocsdtdtf��fdd�}|S)Nr�rvc�s���|�j�j�j�Sr})r�r;r<r=)r��r�rsr4r5r��s��z3RequestHandler._make_error_handler.<locals>.handler)r%r')rsr�r�r4r�r5r��sz"RequestHandler._make_error_handler)r~)rvN)r�NN)4r0r1r2r3�	__slots__rr$r�
LOG_FORMATr��AbstractEventLooprpr�rrrrAr>rmr|�propertyr^rr��
BaseTransportr�r@r�rr�r��bytesr�r�r�r�r%r'r�r�r�r�r
r	rr�r�r�r�r:r��
__classcell__r4r4rtr5r(es�'%������	�
���
�������N2 

'



	���
�
���

�
+}���

�-�����
�>��)Mr��asyncio.streamsr�r�r��collectionsr�
contextlibr�htmlrr��httpr�loggingr�typingrrr	r
rrr
rrrr�attr�yarl�abcrr�
base_protocolr�helpersrrrrrr�http_exceptionsrr�rr�streamsrr �tcp_helpersr!�web_exceptionsr"r#�web_logr$�web_requestr%�web_responser&r'�__all__�
web_serverr+�_RequestFactory�_RequestHandler�URLr�r�r)r*r��sr:�_MsgTyper(r4r4r4r5�<module>st4����