HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/h11/__pycache__/_connection.cpython-310.pyc
o

��h�h�@snddlmZmZmZmZmZmZmZmZm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZddlmZmZmZddlmZmZddlmZddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*dd	l+m,Z,m-Z-gd
�Z.Gdd�de*e*d
�Z/Gdd�de*e*d
�Z0dZ1de
eefde2fdd�Z3de4de
eefdee5e
edee6fffdd�Z7Gdd�d�Z8dS)�)
�Any�Callable�cast�Dict�List�Optional�overload�Tuple�Type�Union�)�ConnectionClosed�Data�EndOfMessage�Event�InformationalResponse�Request�Response)�get_comma_header�has_expect_100_continue�set_comma_header)�READERS�ReadersType)�
ReceiveBuffer)
�_SWITCH_CONNECT�_SWITCH_UPGRADE�CLIENT�ConnectionState�DONE�ERROR�MIGHT_SWITCH_PROTOCOL�	SEND_BODY�SERVER�SWITCHED_PROTOCOL)�LocalProtocolError�RemoteProtocolError�Sentinel)�WRITERS�WritersType)�
Connection�	NEED_DATA�PAUSEDc@�eZdZdS)r*N��__name__�
__module__�__qualname__�r1r1�E/usr/local/CyberPanel/lib/python3.10/site-packages/h11/_connection.pyr*3�r*)�	metaclassc@r,)r+Nr-r1r1r1r2r+7r3r+i@�event�returncCs0t|jd�}d|vrdSt|dd�dkrdSdS)N�
connection�closeF�http_version�1.1T)r�headers�getattr)r5�
connectionr1r1r2�_keep_aliveTsr>�request_methodr1cCs�t|�ttfvs
J�t|�tur4|jdvs+|dks+|dkr-d|jkr)dkr-dSndS|jdks4J�t|jd�}|rE|dgksCJ�d	St|jd
�}|rVdt|d�ffSt|�tur^dSd
S)N)��i0�HEAD�CONNECT���,)�content-length)r�transfer-encoding�chunked)�chunkedr1�content-lengthrEr)�http/1.0r1)�typerr�status_coderr;�int)r?r5�transfer_encodings�content_lengthsr1r1r2�
_body_framing]s&
�rPc@sReZdZdZefdeededdfdd�Ze	de
eeeeffdd	��Ze	deefd
d��Ze	deefdd
��Z
e	defdd��Zd6dd�Zdeeddfdd�Zdedeeefdd�Zdeededdfdd�Zdeedeedeeefdeedeffdd�Z	d7de
eeeefdeeddfdd �Ze	deeeffd!d"��Zd#eddfd$d%�Z deeee!ee"ffd&d'�Z#deeee!ee"ffd(d)�Z$e%de&ddfd*d+��Z'e%dee(e)e*e+e,fdefd,d+��Z'e%dedeefd-d+��Z'dedeefd.d+�Z'dedee-efd/d0�Z.d6d1d2�Z/d3e*de*fd4d5�Z0dS)8r)aBAn object encapsulating the state of an HTTP connection.

    Args:
        our_role: If you're implementing a client, pass :data:`h11.CLIENT`. If
            you're implementing a server, pass :data:`h11.SERVER`.

        max_incomplete_event_size (int):
            The maximum number of bytes we're willing to buffer of an
            incomplete event. In practice this mostly sets a limit on the
            maximum size of the request/response line + headers. If this is
            exceeded, then :meth:`next_event` will raise
            :exc:`RemoteProtocolError`.

    �our_role�max_incomplete_event_sizer6NcCs�||_|ttfvrtd|����||_||turt|_nt|_t�|_|�|jdt	�|_
|�|jdt�|_t
�|_d|_d|_d|_d|_dS)Nzexpected CLIENT or SERVER, not F)�_max_incomplete_event_sizerr"�
ValueErrorrQ�
their_roler�_cstate�_get_io_objectr'�_writerr�_readerr�_receive_buffer�_receive_buffer_closed�their_http_version�_request_method�"client_is_waiting_for_100_continue)�selfrQrRr1r1r2�__init__�s 
zConnection.__init__cCst|jj�S)z�A dictionary like::

           {CLIENT: <client state>, SERVER: <server state>}

        See :ref:`state-machine` for details.

        )�dictrV�states�r_r1r1r2rb�s	zConnection.statescC�|jj|jS)zjThe current state of whichever role we are playing. See
        :ref:`state-machine` for details.
        )rVrbrQrcr1r1r2�	our_state��zConnection.our_statecCrd)znThe current state of whichever role we are NOT playing. See
        :ref:`state-machine` for details.
        )rVrbrUrcr1r1r2�their_state�rfzConnection.their_statecCs|jtuo|jS�N)rUrr^rcr1r1r2�!they_are_waiting_for_100_continue�sz,Connection.they_are_waiting_for_100_continuecCs4t|jj�}|j��d|_|jrJ�|�|�dS)a�Attempt to reset our connection state for a new request/response
        cycle.

        If both client and server are in :data:`DONE` state, then resets them
        both to :data:`IDLE` state in preparation for a new request/response
        cycle on this same connection. Otherwise, raises a
        :exc:`LocalProtocolError`.

        See :ref:`keepalive-and-pipelining`.

        N)rarVrb�start_next_cycler]r^�_respond_to_state_changes)r_�
old_statesr1r1r2rj�s


zConnection.start_next_cycle�rolecCs&t|jj�}|j�|�|�|�dSrh)rarVrb�
process_errorrk)r_rmrlr1r1r2�_process_error�szConnection._process_errorr5cCsTt|�tur
|jdkr
tSt|�tur(t|jjvr(d|jkr%dkr(tSdSdS)N�erCrD)rKrrLrrrrV�pending_switch_proposals�r_r5r1r1r2�_server_switch_events�zConnection._server_switch_eventcCsRt|jj�}|tur't|�tur'|jdkr|j�t�t	|j
d�r'|j�t�d}|tur2|�
|�}|j�|t|�|�t|�turF|j|_||jurbt|�tttfvrbtttttf|�}|j|_t|�ttfvrztttttf|��sz|j��t|�tur�t|�r�d|_t|�ttfvr�d|_|tur�t|�ttfvr�d|_|�||�dS)NrBsupgradeTF)rarVrbrrKr�method�process_client_switch_proposalrrr;rr"rs�
process_eventr]rUrrrrr9r\r>�process_keep_alive_disabledrr^rrrk)r_rmr5rl�server_switch_eventr1r1r2�_process_events<

��
zConnection._process_event�io_dict.cCsV|jj|}|tur$ttt|j�tttt	f|��\}}|t||�S|�
||f�Srh)rVrbr!rPr�bytesr]rrr�get)r_rmr5rz�state�framing_type�argsr1r1r2rW@s�zConnection._get_io_objectrlcCsL|j||jkr|�|j|t�|_|j||jkr$|�|j|t�|_dSdSrh)	rerQrWr'rXrgrUrrY)r_rlr5r1r1r2rkVs
�z$Connection._respond_to_state_changescCst|j�|jfS)abData that has been received, but not yet processed, represented as
        a tuple with two elements, where the first is a byte-string containing
        the unprocessed data itself, and the second is a bool that is True if
        the receive connection was closed.

        See :ref:`switching-protocols` for discussion of why you'd want this.
        )r{rZr[rcr1r1r2�
trailing_dataas	zConnection.trailing_data�datacCs.|r|jr	td��|j|7_dSd|_dS)a�Add data to our internal receive buffer.

        This does not actually do any processing on the data, just stores
        it. To trigger processing, you have to call :meth:`next_event`.

        Args:
            data (:term:`bytes-like object`):
                The new data that was just received.

                Special case: If *data* is an empty byte-string like ``b""``,
                then this indicates that the remote side has closed the
                connection (end of file). Normally this is convenient, because
                standard Python APIs like :meth:`file.read` or
                :meth:`socket.recv` use ``b""`` to indicate end-of-file, while
                other failures to read are indicated using other mechanisms
                like raising :exc:`TimeoutError`. When using such an API you
                can just blindly pass through whatever you get from ``read``
                to :meth:`receive_data`, and everything will work.

                But, if you have an API where reading an empty string is a
                valid non-EOF condition, then you need to be aware of this and
                make sure to check for such strings and avoid passing them to
                :meth:`receive_data`.

        Returns:
            Nothing, but after calling this you should call :meth:`next_event`
            to parse the newly received data.

        Raises:
            RuntimeError:
                Raised if you pass an empty *data*, indicating EOF, and then
                pass a non-empty *data*, indicating more data that somehow
                arrived after the EOF.

                (Calling ``receive_data(b"")`` multiple times is fine,
                and equivalent to calling it once.)

        z(received close, then received more data?TN)r[�RuntimeErrorrZ)r_r�r1r1r2�receive_datals
'
zConnection.receive_datacCs�|j}|tur|jrtS|tus|turtS|jdusJ�|�|j�}|dur<|js<|jr<t|jd�r9|j�	�}nt
�}|durBt}|S)N�read_eof)rgrrZr+r r#rYr[�hasattrr�r
r*)r_r}r5r1r1r2�_extract_next_receive_event�sz&Connection._extract_next_receive_eventc
Cs�|jtur	td��z0|��}|ttfvr|�|jtt	|��|tur7t
|j�|jkr0tddd��|j
r7td��|WSty]}z|�|j�t|t�rQ|��n�WYd}~dSd}~ww)aFParse the next event out of our receive buffer, update our internal
        state, and return it.

        This is a mutating operation -- think of it like calling :func:`next`
        on an iterator.

        Returns:
            : One of three things:

            1) An event object -- see :ref:`events`.

            2) The special constant :data:`NEED_DATA`, which indicates that
               you need to read more data from your socket and pass it to
               :meth:`receive_data` before this method will be able to return
               any more events.

            3) The special constant :data:`PAUSED`, which indicates that we
               are not in a state where we can process incoming data (usually
               because the peer has finished their part of the current
               request/response cycle, and you have not yet called
               :meth:`start_next_cycle`). See :ref:`flow-control` for details.

        Raises:
            RemoteProtocolError:
                The peer has misbehaved. You should close the connection
                (possibly after sending some kind of 4xx response).

        Once this method returns :class:`ConnectionClosed` once, then all
        subsequent calls will also return :class:`ConnectionClosed`.

        If this method raises any exception besides :exc:`RemoteProtocolError`
        then that's a bug -- if it happens please file a bug report!

        If this method raises any exception then it also sets
        :attr:`Connection.their_state` to :data:`ERROR` -- see
        :ref:`error-handling` for discussion.

        z+Can't receive data when peer state is ERRORzReceive buffer too longi�)�error_status_hintz#peer unexpectedly closed connectionN)rgrr%r�r*r+ryrUrr�lenrZrSr[�
BaseExceptionro�
isinstancer$�!_reraise_as_remote_protocol_error)r_r5�excr1r1r2�
next_event�s,
(�

���zConnection.next_eventcC�dSrhr1rrr1r1r2�send��zConnection.sendcCr�rhr1rrr1r1r2r��scCr�rhr1rrr1r1r2r�r�cCs |�|�}|durdSd�|�S)a�Convert a high-level event into bytes that can be sent to the peer,
        while updating our internal state machine.

        Args:
            event: The :ref:`event <events>` to send.

        Returns:
            If ``type(event) is ConnectionClosed``, then returns
            ``None``. Otherwise, returns a :term:`bytes-like object`.

        Raises:
            LocalProtocolError:
                Sending this event at this time would violate our
                understanding of the HTTP/1.1 protocol.

        If this method raises any exception then it also sets
        :attr:`Connection.our_state` to :data:`ERROR` -- see
        :ref:`error-handling` for discussion.

        N�)�send_with_data_passthrough�join)r_r5�	data_listr1r1r2r�s

cCs�|jtur	td��z/t|�tur|�|�}|j}|�|j|�t|�t	ur(WdS|dus.J�g}|||j
�|WS|�|j��)ahIdentical to :meth:`send`, except that in situations where
        :meth:`send` returns a single :term:`bytes-like object`, this instead
        returns a list of them -- and when sending a :class:`Data` event, this
        list is guaranteed to contain the exact object you passed in as
        :attr:`Data.data`. See :ref:`sendfile` for discussion.

        z'Can't send data when our state is ERRORN)rerr$rKr�&_clean_up_response_headers_for_sendingrXryrQr
�appendro)r_r5�writerr�r1r1r2r� s 

z%Connection.send_with_data_passthroughcCs|�|j�dS)z�Notify the state machine that we failed to send the data it gave
        us.

        This causes :attr:`Connection.our_state` to immediately become
        :data:`ERROR` -- see :ref:`error-handling` for discussion.

        N)rorQrcr1r1r2�send_failedAszConnection.send_failed�responsecCs�t|�tusJ�|j}d}tt|j�}|dkrd}t||�\}}|dvrIt|dg�}|jdus4|jdkrBt|dg�}|jdkrAd}nt|dd	g�}|j	j
rO|rhtt|d
��}|�
d�|�d�t|d
t|��}t||j|j|jd
�S)NFrAsGET)rHrJrIr:rFTrGr7s
keep-aliver8)r;rLr9�reason)rKrr;rr{r]rPrr\rV�
keep_alive�setr�discard�add�sortedrLr9r�)r_r�r;�
need_close�method_for_choosing_headersr~�_r=r1r1r2r�Zs4	
�

�z1Connection._clean_up_response_headers_for_sending)r6Nrh)1r.r/r0�__doc__�!DEFAULT_MAX_INCOMPLETE_EVENT_SIZEr
r&rMr`�propertyrrbrerg�boolrirjrorrrsryrrr(rrrWrkr	r{r�r�r*r+r�r�rr
r�rrrrrrr�r�r�r1r1r1r2r)�sx���
�' 

0��
�
����
�
.
� A��
!r)N)9�typingrrrrrrrr	r
r�_eventsr
rrrrrr�_headersrrr�_readersrr�_receivebufferr�_staterrrrrrr r!r"r#�_utilr$r%r&�_writersr'r(�__all__r*r+r�r�r>r{�strrMrPr)r1r1r1r2�<module>s*0$
	0	�
�
�: