Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_connection.cpython-313.pyc233 linesDownload Raw Back to __pycache__
1�

2�j�h���SSKJrJrJrJrJrJrJrJrJ	r	J3r4 SSKJrJ
r
JrJrJrJrJr SSKJrJrJr SSKJrJr SSKJr SSKJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r& SSK'J(r(J)r)J*r* SS	K+J,r,J-r- /S5Qr."SS\*\*S
9r/"SS\*\*S
9r0Sr1S\6\\4S\24Sjr3S\4S\7\\4S\\5\8\S\\6444Sjr7"SS5r8g)�)9�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)10�_SWITCH_CONNECT�_SWITCH_UPGRADE�CLIENT�ConnectionState�DONE�ERROR�MIGHT_SWITCH_PROTOCOL�	SEND_BODY�SERVER�SWITCHED_PROTOCOL)�LocalProtocolError�RemoteProtocolError�Sentinel)�WRITERS�WritersType)�11Connection�	NEED_DATA�PAUSEDc��\rSrSrSrg)r+�3�N��__name__�12__module__�__qualname__�__firstlineno__�__static_attributes__r/��UD:\code\apps\devtools\python\user_packages\Python313\site-packages\h11/_connection.pyr+r+3���r6r+)�	metaclassc��\rSrSrSrg)r,�7r/Nr0r/r6r7r,r,7r8r6r,i@�event�returnc�b�[URS5nSU;ag[USS5S:agg)N�13connection�closeF�http_version�1.1T)r�headers�getattr)r<�14connections  r7�_keep_aliverFTs4��!�%�-�-��?�J��:����u�n�f�-��6��r6�request_methodr/c���[U5[[4;de[U5[LaJURS;d'US:Xd!US:XaSURs=::aS:ag OgURS:�de[	UR15S5nU(a16US/:Xdeg	[	UR17S185nU(aS[
US544$[U5[Lagg
)N)��i0�HEAD�CONNECT���,)�content-length)r�transfer-encoding�chunked)�chunkedr/�content-lengthrNr)�http/1.0r/)�typerr�status_coderrC�int)rGr<�transfer_encodings�content_lengthss    r7�
_body_framingrY]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��'�r6c���\rSrSrSr\4S\\S\SS4Sjjr	\19S\\\\\44Sj5r\20S\\4S	j5r
\21S\\4S22j5r\23S\4Sj5rS%SjrS
\\SS4SjrS\S\\\4SjrS
\\S\SS4SjrS
\\S\\S\\\4S\\S\44SjrS&S\\\\\4S\\SS4Sjjr\24S\\\44Sj5r S\SS4Sjr!S\\\\"\\#44Sjr$S\\\\"\\#44Sjr%\&S\'SS4Sj5r(\&S\\)\*\+\,\-4S\4Sj5r(\&S\S\\4Sj5r(S\S\\4Sjr(S\S\\.\4S jr/S%S!jr0S"\+S\+4S#jr1S$r2g)'r*�aAn object encapsulating the state of an HTTP connection.25 26Args:27    our_role: If you're implementing a client, pass :data:`h11.CLIENT`. If28        you're implementing a server, pass :data:`h11.SERVER`.29 30    max_incomplete_event_size (int):31        The maximum number of bytes we're willing to buffer of an32        incomplete event. In practice this mostly sets a limit on the33        maximum size of the request/response line + headers. If this is34        exceeded, then :meth:`next_event` will raise35        :exc:`RemoteProtocolError`.36 37�our_role�max_incomplete_event_sizer=Nc��X lU[[4;a[SU<35eXlU U[La[UlO[Ul[
5UlURURS[5Ul38URUR39S[5Ul[5UlSUlSUlSUlSUlg)Nzexpected CLIENT or SERVER, not F)�_max_incomplete_event_sizerr#�40ValueErrorr\�41their_roler�_cstate�_get_io_objectr(�_writerr�_readerr�_receive_buffer�_receive_buffer_closed�their_http_version�_request_method�"client_is_waiting_for_100_continue)�selfr\r]s   r7�__init__�Connection.__init__�s���42+D�'��F�F�+�+��>�x�l�K�L�L� �
���v��$�D�O�$�D�O�&�(����*�*�4�=�=�$��H����*�*�4�?�?�D�'�J��� -����',��#�48���04���38��/r6c�@�[URR5$)zqA dictionary like::43 44   {CLIENT: <client state>, SERVER: <server state>}45 46See :ref:`state-machine` for details.47 48)�dictrb�states�rks r7rp�Connection.states�s���D�L�L�'�'�(�(r6c�H�URRUR$)zZThe current state of whichever role we are playing. See49:ref:`state-machine` for details.50)rbrpr\rqs r7�	our_state�Connection.our_state�s��51�|�|�"�"�4�=�=�1�1r6c�H�URRUR$)z^The current state of whichever role we are NOT playing. See52:ref:`state-machine` for details.53)rbrprarqs r7�their_state�Connection.their_state�s��54�|�|�"�"�4�?�?�3�3r6c�L�UR[L=(a UR$�N)rarrjrqs r7�!they_are_waiting_for_100_continue�,Connection.they_are_waiting_for_100_continue�s�����&�(�T�T�-T�-T�Tr6c���[URR5nURR5 SUlUR55(aeUR
U5 g)aIAttempt to reset our connection state for a new request/response56cycle.57 58If both client and server are in :data:`DONE` state, then resets them59both to :data:`IDLE` state in preparation for a new request/response60cycle on this same connection. Otherwise, raises a61:exc:`LocalProtocolError`.62 63See :ref:`keepalive-and-pipelining`.64 65N)rorbrp�start_next_cyclerirj�_respond_to_state_changes)rk�66old_statess  r7r~�Connection.start_next_cycle�sO���$�,�,�-�-�.�67����%�%�'�#����:�:�:�:��&�&�z�2r6�rolec��[URR5nURRU5 UR	U5 grz)rorbrp�
process_errorr)rkr�r�s   r7�_process_error�Connection._process_error�s6���$�,�,�-�-�.�68����"�"�4�(��&�&�z�2r6r<c���[U5[LaURS:Xa[$[U5[La>[69URR;a SURs=::aS:a	[70$ gg)N�erLrM)rTrrUrrrrb�pending_switch_proposals�rkr<s  r7�_server_switch_event�Connection._server_switch_eventsc����;�/�/�E�4E�4E��4L�"�"���;�(�"��4�<�<�#H�#H�H��5�,�,�2�s�2�&�&�3�r6c��[URR5nU[La{[	U5[71LaiURS:XaURR[5 [URS5(aURR[5 SnU[LaURU5nURRU[	U5U5 [	U5[72LaURUlXR LaQ[	U5[73["[$4;a3['[([74["[$4U5nUR*Ul[	U5[75["4;aE[/['[([76["4U55(dURR15 [	U5[77La[3U5(aSUl[	U5[$["4;aSUlU[La [	U5[6[84;aSUlUR;X25 g)NrKsupgradeTF)rorbrprrTr�method�process_client_switch_proposalrrrCrr#r��
process_eventrirarrrrrArhrF�process_keep_alive_disabledrrjrrr)rkr�r<r��server_switch_events     r7�_process_event�Connection._process_events����$�,�,�-�-�.�78��6�>�d�5�k�W�4��|�|�z�)����;�;�O�L���
�
�z�:�:����;�;�O�L�"���6�>�"&�";�";�E�"B�����"�"�4��e��6I�J���;�'�!�#(�<�<�D� ��?�?�"�t�E�{���!�779�(80�81��w��2G�G�H�%�P�E�&+�&8�&8�D�#���;�7�H�-�-�k���w��(�)�5�1�782�783�
�L�L�4�4�6���;�'�!�&=�e�&D�&D�6:�D�3���;�0�(�;�;�6;�D�3��6�>�d�5�k�d�L�-A�A�6;�D�3��&�&�z�9r6�io_dict.c�84�URRUnU[LaP[[	[85UR5[	[[[4U55upVU[U"U6$URX45$rz)rbrpr"rYr�bytesrirrr�get)rkr�r<r��state�framing_type�argss       r7rc�Connection._get_io_object@s}�����#�#�D�)���I��"/��U�D�0�0�1�4��g�x�>O�8P�RW�3X�"��L��9�%�l�3�T�:�:��;�;��}�-�-r6r�c��URXR:wa&URURU[5UlUR86XR:wa'URURU[5Ulggrz)	rtr\rcr(rdrwrarre)rkr�r<s   r7r�$Connection._respond_to_state_changesVse���>�>�Z�
�
�6�6��.�.�t�}�}�e�W�M�D�L����z�/�/�:�:��.�.�t����w�O�D�L�;r6c�D�[UR5UR4$)a:Data that has been received, but not yet processed, represented as87a tuple with two elements, where the first is a byte-string containing88the unprocessed data itself, and the second is a bool that is True if89the receive connection was closed.90 91See :ref:`switching-protocols` for discussion of why you'd want this.92)r�rfrgrqs r7�
trailing_data�Connection.trailing_dataas ���d�*�*�+�T�-H�-H�I�Ir6�datac��U(a2UR(a[S5eU=RU-
slgSUlg)a�Add data to our internal receive buffer.93 94This does not actually do any processing on the data, just stores95it. To trigger processing, you have to call :meth:`next_event`.96 97Args:98    data (:term:`bytes-like object`):99        The new data that was just received.100 101        Special case: If *data* is an empty byte-string like ``b""``,102        then this indicates that the remote side has closed the103        connection (end of file). Normally this is convenient, because104        standard Python APIs like :meth:`file.read` or105        :meth:`socket.recv` use ``b""`` to indicate end-of-file, while106        other failures to read are indicated using other mechanisms107        like raising :exc:`TimeoutError`. When using such an API you108        can just blindly pass through whatever you get from ``read``109        to :meth:`receive_data`, and everything will work.110 111        But, if you have an API where reading an empty string is a112        valid non-EOF condition, then you need to be aware of this and113        make sure to check for such strings and avoid passing them to114        :meth:`receive_data`.115 116Returns:117    Nothing, but after calling this you should call :meth:`next_event`118    to parse the newly received data.119 120Raises:121    RuntimeError:122        Raised if you pass an empty *data*, indicating EOF, and then123        pass a non-empty *data*, indicating more data that somehow124        arrived after the EOF.125 126        (Calling ``receive_data(b"")`` multiple times is fine,127        and equivalent to calling it once.)128 129z(received close, then received more data?TN)rg�RuntimeErrorrf)rkr�s  r7�receive_data�Connection.receive_datals6��N��*�*�"�#M�N�N�� � �D�(� �*.�D�'r6c��URnU[LaUR(a[$U[Ld	U[130La[$URceUR
UR5nUcbUR(dQUR(a@[URS5(aURR5nO131[5nUc[nU$)N�read_eof)rwrrfr,r!r$rerg�hasattrr�rr+)rkr�r<s   r7�_extract_next_receive_event�&Connection._extract_next_receive_event�s���� � ��132�D�=�T�1�1��M��)�)�U�6G�-G��M��|�|�'�'�'����T�1�1�2���=��'�'�D�,G�,G�133�4�<�<��4�4� �L�L�1�1�3�E�,�.�E��=��E��r6c�,�UR[La[S5eUR5nU[[1344;a*UR
UR[[U55 U[LaI[UR5UR:�a135[SSS9eUR(a[S5eU$![aKnURUR5 [!U["5(aUR%5 SnAgeSnAff=f)anParse the next event out of our receive buffer, update our internal136state, and return it.137 138This is a mutating operation -- think of it like calling :func:`next`139on an iterator.140 141Returns:142    : One of three things:143 144    1) An event object -- see :ref:`events`.145 146    2) The special constant :data:`NEED_DATA`, which indicates that147       you need to read more data from your socket and pass it to148       :meth:`receive_data` before this method will be able to return149       any more events.150 151    3) The special constant :data:`PAUSED`, which indicates that we152       are not in a state where we can process incoming data (usually153       because the peer has finished their part of the current154       request/response cycle, and you have not yet called155       :meth:`start_next_cycle`). See :ref:`flow-control` for details.156 157Raises:158    RemoteProtocolError:159        The peer has misbehaved. You should close the connection160        (possibly after sending some kind of 4xx response).161 162Once this method returns :class:`ConnectionClosed` once, then all163subsequent calls will also return :class:`ConnectionClosed`.164 165If this method raises any exception besides :exc:`RemoteProtocolError`166then that's a bug -- if it happens please file a bug report!167 168If this method raises any exception then it also sets169:attr:`Connection.their_state` to :data:`ERROR` -- see170:ref:`error-handling` for discussion.171 172z+Can't receive data when peer state is ERRORzReceive buffer too longi�)�error_status_hintz#peer unexpectedly closed connectionN)rwr r&r�r+r,r�rarr�lenrfr_rg�
BaseExceptionr��173isinstancer%�!_reraise_as_remote_protocol_error)rkr<�excs   r7�174next_event�Connection.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�2��5�5�7�7���	�s�BB>�>175D�AD�
D�Dc��grzr/r�s  r7�send�Connection.send����r6c��grzr/r�s  r7r�r��s��	r6c��grzr/r�s  r7r�r�r�r6c�N�URU5nUcgSRU5$)aCConvert a high-level event into bytes that can be sent to the peer,176while updating our internal state machine.177 178Args:179    event: The :ref:`event <events>` to send.180 181Returns:182    If ``type(event) is ConnectionClosed``, then returns183    ``None``. Otherwise, returns a :term:`bytes-like object`.184 185Raises:186    LocalProtocolError:187        Sending this event at this time would violate our188        understanding of the HTTP/1.1 protocol.189 190If this method raises any exception then it also sets191:attr:`Connection.our_state` to :data:`ERROR` -- see192:ref:`error-handling` for discussion.193 194Nr6)�send_with_data_passthrough�join)rkr<�	data_lists   r7r�r�s,��*�3�3�E�:�	�����8�8�I�&�&r6c�t�UR[La[S5e[U5[LaURU5nURnURURU5 [U5[LagUce/nU"XR5 U$! URUR5 e=f)a@Identical to :meth:`send`, except that in situations where195:meth:`send` returns a single :term:`bytes-like object`, this instead196returns a list of them -- and when sending a :class:`Data` event, this197list is guaranteed to contain the exact object you passed in as198:attr:`Data.data`. See :ref:`sendfile` for discussion.199 200z'Can't send data when our state is ERRORN)rtr r%rTr�&_clean_up_response_headers_for_sendingrdr�r\r�appendr�)rkr<�writerr�s    r7r��%Connection.send_with_data_passthrough s����>�>�U�"�$�%N�O�O�	��E�{�h�&��C�C�E�J���\�\�F�����
�
�u�5��E�{�.�.���)�)�)�)+�	��u�.�.�/� � ��	�����
�
�.��s�AB�>B�B7c�:�URUR5 g)z�Notify the state machine that we failed to send the data it gave201us.202 203This causes :attr:`Connection.our_state` to immediately become204:data:`ERROR` -- see :ref:`error-handling` for discussion.205 206N)r�r\rqs r7�send_failed�Connection.send_failedAs��	
���D�M�M�*r6�responsec��[U5[LdeURnSn[[UR2075nUS:XaSn[
XA5upVUS;aX[US/5nURbURS:a [US/5nUR208S:waSnO[USS	/5nURR(aU(aM[[US20955nURS5 URS5 [US210[U55n[UUR UR"UR$S
9$)NFrJsGET)rQrSrRrBrOTrPr?s211keep-aliver@)rCrUrA�reason)rTrrCrr�rirYrrhrb�212keep_alive�setr�discard�add�sortedrUrAr�)rkr�rC�213need_close�method_for_choosing_headersr��_rEs        r7r��1Connection._clean_up_response_headers_for_sendingZs6���H�~��)�)�)��"�"���214�'+�5�$�2F�2F�&G�#�&�'�1�*0�'�'�(C�N����2�2�'�w�0A�2�F�G��&�&�.�$�2I�2I�F�2R�215+�7�4H�"�M��216�'�'�7�2�!%�J��*�7�4H�:�,�W���|�|�&�&�*��-�g�}�E�F�J����}�-��N�N�8�$�&�w�
�v�j�?Q�R�G��� �,�,�!�.�.��?�?�	217�	218r6)rbr_rerfrgrirdrjr\rhra)r=Nrz)3r1r2r3r4�__doc__�!DEFAULT_MAX_INCOMPLETE_EVENT_SIZErr'rVrl�propertyrrprtrw�boolr{r~r�rrr�r�rrr)rrrcrr219r�r�r�r+r,r�r�r	rr�rrrrrrr�r�r�r5r/r6r7r*r*�s���
�$*K�%8��x�.�%8�$'�%8�220�	%8�N�)��T�(�^�T�(�^�;�<�)��)��2�4��>�2��2��4�T�(�^�4��4��U�4�U��U�3�(3�4��>�3�d�3�221	�%�	�H�T�(�^�4L�	�.:�4��>�.:�%�.:�D�.:�`.��8�n�.����.��{�K�/�0�	.�222223�(�3��8�$�	%�.�2"&�	P���h���h��7�8�	P����	P�224�		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��	����225��%��H�U�O����'�%�'�H�U�O�'�6���(�4��;�:O��B+�29226�x�9227�H�9228r6r*N)9�typingrrrrrrr	r229rr�_eventsrrrrrrr�_headersrrr�_readersrr�_receivebufferr�_staterrrrrr r!r"r#r$�_utilr%r&r'�_writersr(r)�__all__r+r,r�r�rFr��strrVrYr*r/r6r7�<module>r�s���������R�Q�*�)������230+�0��	��H�	�	�X��	�%.�!��u�W�h�.�/��D��0 ��0 �"'���(9�":�0 �231�3��e�B�i��s��+�,�,�-�0 �t|232�|233r6
codekingpro/portable-devtools · Team Ai