← back to Atmos Game

assets/gen/.venv/lib/python3.12/site-packages/h11/__pycache__/_connection.cpython-312.pyc

226 lines

�

c�bj�h���ddlmZmZmZmZmZmZmZmZm	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.Gd�de*e*�
�Z/Gd�de*e*�
�Z0dZ1de
eefde2fd�Z3de4de
eefdee5e
edee6fffd�Z7Gd�d�Z8y)�)
�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��eZdZy)r+N��__name__�
__module__�__qualname__���f/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/h11/_connection.pyr+r+3���r3r+)�	metaclassc��eZdZy)r,Nr.r2r3r4r,r,7r5r3r,i@�event�returnc�\�t|jd�}d|vryt|dd�dkryy)N�
connection�closeF�http_version�1.1T)r�headers�getattr)r8�
connections  r4�_keep_aliverBTs4��!�%�-�-��?�J��:����u�n�f�-��6��r3�request_methodr2c��t|�ttfvsJ�t|�turB|jdvs"|dk(s|dk(rd|jcxkrdkryny|jdk\sJ�t	|j
d�}|r	|dgk(sJ�y	t	|j
d
�}|rdt
|d�ffSt|�turyy
)N)��i0�HEAD�CONNECT���,)�content-length)r�transfer-encoding�chunked)�chunkedr2�content-lengthrJr)�http/1.0r2)�typerr�status_coderr?�int)rCr8�transfer_encodings�content_lengthss    r4�
_body_framingrU]s�����;�7�H�-�-�-�-��E�{�h������+���(��*�,���8I�8I�1O�C�1O�+�2P�+�� � �C�'�'�'�*�%�-�-�9M�N���!�j�\�1�1�1��'�u�}�}�6G�H�O�� �3��q�'9�#:�"<�=�=��E�{�g��'�r3c��eZdZdZefdeededdfd�Ze	de
eeeeffd��Ze	deefd��Ze	deefd	��Z
e	defd
��Zd#d�Zdeeddfd
�Zdedeeefd�Zdeededdfd�Zdeedeedeeefdeedeffd�Z	d$de
eeeefdeeddfd�Ze	deeeffd��Zdeddfd�Z deeee!ee"ffd�Z#deeee!ee"ffd�Z$e%de&ddfd��Z'e%dee(e)e*e+e,fdefd��Z'e%dedeefd��Z'dedeefd�Z'dedee-efd�Z.d#d �Z/d!e*de*fd"�Z0y)%r*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_sizer9Nc��||_|ttfvrtd|����||_||turt|_nt|_t
�|_|j|jdt�|_
|j|j
dt�|_t�|_d|_d|_d|_d|_y)Nzexpected CLIENT or SERVER, not F)�_max_incomplete_event_sizerr#�
ValueErrorrW�
their_roler�_cstate�_get_io_objectr(�_writerr�_readerr�_receive_buffer�_receive_buffer_closed�their_http_version�_request_method�"client_is_waiting_for_100_continue)�selfrWrXs   r4�__init__zConnection.__init__�s���
+D��'��F�F�+�+��>�x�l�K�L�L� ��
���v��$�D�O�$�D�O�&�(����*�*�4�=�=�$��H����*�*�4�?�?�D�'�J��� -����',��#�48���04���38��/r3c�@�t|jj�S)z�A dictionary like::

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

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

        )�dictr]�states�rfs r4rjzConnection.states�s���D�L�L�'�'�(�(r3c�H�|jj|jS)zjThe current state of whichever role we are playing. See
        :ref:`state-machine` for details.
        )r]rjrWrks r4�	our_statezConnection.our_state�s��
�|�|�"�"�4�=�=�1�1r3c�H�|jj|jS)znThe current state of whichever role we are NOT playing. See
        :ref:`state-machine` for details.
        )r]rjr\rks r4�their_statezConnection.their_state�s��
�|�|�"�"�4�?�?�3�3r3c�B�|jtuxr|jS�N)r\rrerks r4�!they_are_waiting_for_100_continuez,Connection.they_are_waiting_for_100_continue�s�����&�(�T�T�-T�-T�Tr3c���t|jj�}|jj�d|_|j
rJ�|j
|�y)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)rir]rj�start_next_cyclerdre�_respond_to_state_changes)rf�
old_statess  r4rtzConnection.start_next_cycle�sO���$�,�,�-�-�.�
����%�%�'�#����:�:�:�:��&�&�z�2r3�rolec��t|jj�}|jj|�|j	|�yrq)rir]rj�
process_errorru)rfrwrvs   r4�_process_errorzConnection._process_error�s6���$�,�,�-�-�.�
����"�"�4�(��&�&�z�2r3r8c���t|�tur|jdk(rtSt|�tur9t
|jjvrd|jcxkr
dkrt
Syy)N�erHrI)rPrrQrrrr]�pending_switch_proposals�rfr8s  r4�_server_switch_eventzConnection._server_switch_eventsc����;�/�/�E�4E�4E��4L�"�"���;�(�"��4�<�<�#H�#H�H��5�,�,�2�s�2�&�&�3�r3c�Z�t|jj�}|turtt	|�t
urc|jdk(r|jjt�t|jd�r|jjt�d}|tur|j|�}|jj|t	|�|�t	|�t
ur|j|_||j urOt	|�t
t"t$fvr3t't(t
t"t$f|�}|j*|_t	|�t
t"fvr@t/t't(t
t"f|��s|jj1�t	|�t
urt3|�rd|_t	|�t$t"fvrd|_|turt	|�t6t8fvrd|_|j;||�y)NrGsupgradeTF)rir]rjrrPr�method�process_client_switch_proposalrrr?rr#r�
process_eventrdr\rrrrr=rcrB�process_keep_alive_disabledrrerrru)rfrwr8rv�server_switch_events     r4�_process_eventzConnection._process_events����$�,�,�-�-�.�
��6�>�d�5�k�W�4��|�|�z�)����;�;�O�L���
�
�z�:����;�;�O�L�"���6�>�"&�";�";�E�"B�����"�"�4��e��6I�J���;�'�!�#(�<�<�D� ��4�?�?�"�t�E�{���!�7
�(
�
��w��2G�G�H�%�P�E�&+�&8�&8�D�#���;�7�H�-�-�k���w��(�)�5�1�7
�
�L�L�4�4�6���;�'�!�&=�e�&D�6:�D�3���;�0�(�;�;�6;�D�3��6�>�d�5�k�d�L�-A�A�6;�D�3��&�&�z�5�9r3�io_dict.c��|jj|}|turQtt	t
|j�t	tttf|��\}}|t||�S|j||f�Srq)r]rjr"rUr�bytesrdrrr�get)rfrwr8r��state�framing_type�argss       r4r^zConnection._get_io_object@s������#�#�D�)���I��"/��U�D�0�0�1�4��g�x�>O�8P�RW�3X�"��L�$�4�7�9�%�l�3�T�:�:��;�;��e�}�-�-r3rvc��|j||jk7r&|j|j|t�|_|j
||jk7r'|j|j|t�|_yyrq)	rmrWr^r(r_ror\rr`)rfrvr8s   r4ruz$Connection._respond_to_state_changesVsi���>�>�Z��
�
�6�6��.�.�t�}�}�e�W�M�D�L����z�$�/�/�:�:��.�.�t����w�O�D�L�;r3c�D�t|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�rarbrks r4�
trailing_datazConnection.trailing_dataas ���d�*�*�+�T�-H�-H�I�Ir3�datac�p�|r-|jrtd��|xj|z
c_yd|_y)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)rb�RuntimeErrorra)rfr�s  r4�receive_datazConnection.receive_datals6��N��*�*�"�#M�N�N�� � �D�(� �*.�D�'r3c��|j}|tur|jrtS|tus|t
urtS|j�J�|j
|j�}|�S|jsG|jr;t|jd�r|jj�}n
t�}|�t}|S)N�read_eof)rorrar,r!r$r`rb�hasattrr�rr+)rfr�r8s   r4�_extract_next_receive_eventz&Connection._extract_next_receive_event�s���� � ��
�D�=�T�1�1��M��)�)�U�6G�-G��M��|�|�'�'�'����T�1�1�2���=��'�'�D�,G�,G�
�4�<�<��4� �L�L�1�1�3�E�,�.�E��=��E��r3c��|jturtd��	|j�}|tt
fvr*|j
|jtt|��|turFt|j�|jkDr
tdd���|jrtd��|S#t$rG}|j|j�t!|t"�r|j%�n�Yd}~yd}~wwxYw)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)ror r&r�r+r,r�r\rr�lenrarZrb�
BaseExceptionrz�
isinstancer%�!_reraise_as_remote_protocol_error)rfr8�excs   r4�
next_eventzConnection.next_event�s���P���u�$�%�&S�T�T�	��4�4�6�E��Y��/�/��#�#�D�O�O�T�%��5G�H��	�!��t�+�+�,�t�/N�/N�N�.�1�S����.�.�.�.S�T�T��L���	�������0��#�1�2��5�5�7��8��	�s�BB7�7	D�=D�Dc��yrqr2r~s  r4�sendzConnection.send����r3c��yrqr2r~s  r4r�zConnection.send�s��	r3c��yrqr2r~s  r4r�zConnection.sendr�r3c�L�|j|�}|�ydj|�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.

        Nr3)�send_with_data_passthrough�join)rfr8�	data_lists   r4r�zConnection.sends,��*�3�3�E�:�	�����8�8�I�&�&r3c�n�|jturtd��	t|�tur|j|�}|j}|j|j|�t|�tury|�J�g}|||j�|S#|j|j��xYw)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)rmr r%rPr�&_clean_up_response_headers_for_sendingr_r�rWr�appendrz)rfr8�writerr�s    r4r�z%Connection.send_with_data_passthrough s����>�>�U�"�$�%N�O�O�	��E�{�h�&��C�C�E�J���\�\�F�����
�
�u�5��E�{�.�.���)�)�)�)+�	��u�i�.�.�/� � ��	�����
�
�.��s�AB�;B�B4c�:�|j|j�y)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)rzrWrks r4�send_failedzConnection.send_failedAs��	
���D�M�M�*r3�responsec�z�t|�tusJ�|j}d}tt|j
�}|dk(rd}t
||�\}}|dvrUt|dg�}|j�|jdkrt|dg�}|j
dk7rd}nt|dd	g�}|jjr|rMtt|d
��}|jd�|jd�t|d
t|��}t||j |j"|j$�
�S)NFrFsGET)rMrOrNr>rKTrLr;s
keep-aliver<)r?rQr=�reason)rPrr?rr�rdrUrrcr]�
keep_alive�setr�discard�add�sortedrQr=r�)rfr�r?�
need_close�method_for_choosing_headersr��_rAs        r4r�z1Connection._clean_up_response_headers_for_sendingZs9���H�~��)�)�)��"�"���
�'+�5�$�2F�2F�&G�#�&�'�1�*0�'�'�(C�X�N���a��2�2�'�w�0A�2�F�G��&�&�.�$�2I�2I�F�2R�
+�7�4H�"�M��
�'�'�7�2�!%�J�*�7�4H�:�,�W���|�|�&�&�*��-�g�}�E�F�J����}�-��N�N�8�$�&�w�
�v�j�?Q�R�G��� �,�,�!�.�.��?�?�	
�	
r3)r9Nrq)1r/r0r1�__doc__�!DEFAULT_MAX_INCOMPLETE_EVENT_SIZErr'rRrg�propertyrrjrmro�boolrrrtrzrrrr�rrr)rrr^rur
r�r�r�r+r,r�r�r	rr�rrrrrrr�r�r�r2r3r4r*r*�s���
�$*K�%8��x�.�%8�$'�%8�
�	%8�N�)��T�(�^�T�(�^�;�<�)��)��2�4��>�2��2��4�T�(�^�4��4��U�4�U��U�3�(3�4��>�3�d�3�
	�%�	�H�T�(�^�4L�	�.:�4��>�.:�%�.:�D�.:�`.��8�n�.����.��{�K�/�0�	.�

�(�3��8�$�	%�.�2"&�	P���h���h��7�8�	P����	P�
�		P��J�u�U�D�[�1�J��J�,/��,/�4�,/�\�	�u�d�9�o�t�F�|�3�	4��8?�E�%��i��$�v�,�"F�G�?�B��*��t�������7�$9�8�T�<�W�X��	����
��%��H�U�O����'�%�'�H�U�O�'�6���(�4��;�:O��B+�29
�x�9
�H�9
r3r*N)9�typingrrrrrrr	r
rr�_eventsrrrrrrr�_headersrrr�_readersrr�_receivebufferr�_staterrrrrr r!r"r#r$�_utilr%r&r'�_writersr(r)�__all__r+r,r�r�rBr��strrRrUr*r2r3r4�<module>r�s���������R�Q�*�)������
+�0��	��H�	�	�X��	�%.�!��u�W�h�.�/��D��0 ��0 �"'���(9�":�0 �
�3��e�B�i��s��+�,�,�-�0 �t|
�|
r3