Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2p�jd7���SSKJr SSKrSSKrSSKrSSKJrJr SSKJ	r	 SSK3JrJr SSK
JrJrJrJrJrJrJr SSKJrJr SS	KJrJrJrJrJrJrJrJ r  SS4K!J"r"J#r# SSK$J%r% SSK&J'r'J(r(J)r)J*r*J+r+ SS
KJ,r,J-r-J.r.J/r/J0r0J1r1 SSK2J3r3 SSK4J5r5J6r6 S/r7"SS\*5r8"SS\85r9\:"\RvRySS55r=\:"\RvRySS55r>\:"\RvRySS55r?\:"\RvRySS55r@\=\>\?\@4S SjjrA\%"\B"5SSSS.S9 g)!�)�annotationsN)�	Generator�Sequence)�Any�)�Headers�MultipleValuesError)�InvalidHandshake�
InvalidHeader�InvalidHeaderValue�InvalidMessage�
InvalidStatus�InvalidUpgrade�NegotiationError)�ClientExtensionFactory�	Extension)�build_authorization_basic�build_extension�5build_host�build_subprotocol�parse_connection�parse_extension�parse_subprotocol�
parse_upgrade)�Request�Response)�lazy_import)�CLIENT�6CONNECTING�OPEN�Protocol�State)�ConnectionOption�ExtensionHeader�7LoggerLike�Origin�Subprotocol�UpgradeProtocol)�WebSocketURI)�8accept_key�generate_key�ClientProtocolc�^�\rSrSrSrSSS\SSS.SU4SjjjrSSjrSSjrSS	jr	SS9jr10SSjrSU4SjjrS
r
U=r$)r,�0a#11Sans-I/O implementation of a WebSocket client connection.12 13Args:14    uri: URI of the WebSocket server, parsed15        with :func:`~websockets.uri.parse_uri`.16    origin: Value of the ``Origin`` header. This is useful when connecting17        to a server that validates the ``Origin`` header to defend against18        Cross-Site WebSocket Hijacking attacks.19    extensions: List of supported extensions, in order in which they20        should be tried.21    subprotocols: List of supported subprotocols, in order of decreasing22        preference.23    state: Initial state of the WebSocket connection.24    max_size: Maximum size of incoming messages in bytes.25        :obj:`None` disables the limit. You may pass a ``(max_message_size,26        max_fragment_size)`` tuple to set different limits for messages and27        fragments when you expect long messages sent in short fragments.28    logger: Logger for this connection;29        defaults to ``logging.getLogger("websockets.client")``;30        see the :doc:`logging guide <../../topics/logging>` for details.31 32Ni)�origin�33extensions�subprotocols�state�max_size�loggerc�|>�[TU][UUUS9 XlX lX0lX@l[5Ulg)N)�sider2r3r4)	�super�__init__r�urir/�available_extensions�available_subprotocolsr+�key)	�selfr9r/r0r1r2r3r4�	__class__s	        ��WD:\code\apps\devtools\python\user_packages\Python313\site-packages\websockets/client.pyr8�ClientProtocol.__init__IsD���	�������		�	34�����$.�!�&2�#��>���c���[5n[URRURRURR355US'URR(a[URR6US'URbURUS'SUS'SUS'URUS'SUS	'URbC[URVs/sHnURUR54PM! sn5US36'URb[UR5US'[!URR"U5$s snf)a37Create a handshake request to open a connection.38 39You must send the handshake request with :meth:`send_request`.40 41You can modify it before sending it, for example to add HTTP headers.42 43Returns:44    WebSocket handshake request event to send to the server.45 46�Host�
Authorizationr&�	websocket�Upgrade�47ConnectionzSec-WebSocket-Key�13zSec-WebSocket-Version�Sec-WebSocket-Extensions�Sec-WebSocket-Protocol)rrr9�host�port�secure�	user_inforr/r<r:r�name�get_request_paramsr;rr�
resource_name)r=�headers�extension_factorys   r?�connect�ClientProtocol.connect`s;���)��$�T�X�X�]�]�D�H�H�M�M�4�8�8�?�?�S�����8�8���'@�$�(�(�BT�BT�'U�G�O�$��;�;�"� $���G�H��(��	�� )����'+�x�x��#�$�+/��'�(��$�$�0�2A�.2�-F�-F��-F�)�'�+�+�->�-Q�-Q�-S�T�-F��3�G�.�/��&�&�2�0A��+�+�1�G�,�-��t�x�x�-�-�w�7�7��s�+&E c�b�URS:wa[U5eURn[UR	S5Vs/sHn[U5PM sn/5n[
SU55(d([SU(aSRU55eS5e[UR	S5Vs/sHn[U5PM sn/5n[U5S:XaUSR5S	:Xd([SU(aSRU55eS5eUS48nU[UR 5:wa[#S49U5eUR%U5UlUR)U5Ulgs snfs snf![a
 [S505Se[a [S51S5Sef=f)z�52Check a handshake response.53 54Args:55    request: WebSocket handshake response received from the server.56 57Raises:58    InvalidHandshake: If the handshake response is invalid.59 60�erGc3�F# �UHoR5S:Hv� M g7f)�upgradeN)�lower)�.0�values  r?�	<genexpr>�2ClientProtocol.process_response.<locals>.<genexpr>�s���F�:�%�;�;�=�I�-�:�s�!�, NrFrrrEzSec-WebSocket-Acceptzmultiple values)�status_coderrR�sum�get_allr�anyr�joinr�lenrZ�KeyErrorrr	r*r<r�process_extensionsr0�process_subprotocol�subprotocol)r=�responserRr\�61connectionrY�62s_w_accepts       r?�process_response�ClientProtocol.process_response�s������3�&���)�)��"�"��-0�29�/�/�,�2O�P�2O��
�e�
$�2O�P�RT�.63�64��F�:�F�F�F� ��z�d�i�i�65�3��
�GK��
�*-�/6���y�/I�J�/I�e�]�5�
!�/I�J�B�*66��67�G���!�g�a�j�&6�&6�&8�K�&G� ��'�D�I�I�g�,>�T�T�t�T�T�	U� �!7�8�J�68��D�H�H�-�-�$�%;�Z�H�H��1�1�'�:����3�3�G�<����3
Q��
K���	B�� 6�7�T�A�"�	U�� 6�8I�J�PT�T�	U�s�E7�4E<� F�-F.c��/nURS5nU(a�URc[S5e[UVs/sHn[	U5PM sn/5nUH]upgURH9nUR69U:waMUR
Xr5n	URU	5  ML [SUSU35e U$s snf![a Mdf=f)a�70Handle the Sec-WebSocket-Extensions HTTP response header.71 72Check that each extension is supported, as well as its parameters.73 74:rfc:`6455` leaves the rules up to the specification of each75extension.76 77To provide this level of flexibility, for each extension accepted by78the server, we check for a match with each extension available in the79client configuration. If no match is found, an exception is raised.80 81If several variants of the same extension are accepted by the server,82it may be configured several times, which won't make sense in general.83Extensions must implement their own requirements. For this purpose,84the list of previously accepted extensions is provided.85 86Other requirements, for example related to mandatory extensions or the87order of extensions, may be implemented by overriding this method.88 89Args:90    headers: WebSocket handshake response headers.91 92Returns:93    List of accepted extensions.94 95Raises:96    InvalidHandshake: To abort the handshake.97 98rIzno extensions supportedzUnsupported extension: name = z, params = )rbr:rrarrO�process_response_params�append)99r=rR�accepted_extensionsr0�header_value�parsed_extensionsrO�response_paramsrS�	extensions100          r?rg�!ClientProtocol.process_extensions�s��>02���_�_�%?�@�101���(�(�0�&�'@�A�A�7:�CM�N�:�<���.�:�N�PR�8��*;�%��)-�)B�)B�%�(�-�-��5� �!�$5�$M�$M�+�%�	�(�.�.�y�9��#*C�,+�"�"&��{�?�2C�E���/*;�8#�"��?O��,�!� �!�s�B>�C�102C�Cc�^�SnURS5nU(a�URc[S5e[UVs/sHn[	U5PM sn/5n[U5S:�a[
SSSRU535eUSnX R;a[SU35eU$s snf)	z�103Handle the Sec-WebSocket-Protocol HTTP response header.104 105If provided, check that it contains exactly one supported subprotocol.106 107Args:108    headers: WebSocket handshake response headers.109 110Returns:111   Subprotocol, if one was selected.112 113NrJzno subprotocols supportedrzmultiple values: r_rzunsupported subprotocol: )rbr;rrarrerrd)r=rRrir1rs�parsed_subprotocolss      r?rh�"ClientProtocol.process_subprotocol�s���+/�����'?�@����*�*�2�&�'B�C�C�9<�EQ�R�\�\�"�<�0�\�R�TV�:���&�'�!�+�#�,�'��	�	�2E�(F�'G�H���114.�a�0�K��"=�"=�=�&�)B�;�-�'P�Q�Q����Ss�B*c�B�UR(aeURRSUR5 URR	5H!up#URRSX#5 M# UR115R
UR55 g)za116Send a handshake request to the server.117 118Args:119    request: WebSocket handshake request event.120 121z> GET %s HTTP/1.1z> %s: %sN)�debugr4�pathrR�	raw_items�writesrq�	serialize)r=�requestr<r\s    r?�send_request�ClientProtocol.send_requestsn���:�:��K�K���1�7�<�<�@�%�o�o�7�7�9�122�����!�!�*�c�9�:�	
�����7�,�,�.�/rAc#�.># �UR[LGam[R"URR123URRURR5Shv�NnUR (a�WR"UR$pCUR&R!SX45 UR(R+5H!upVUR&R!SXV5 M# UR,(a/UR&R!S[/UR,55 UR1W5 UR[Lde[:UlUR6R9U5 [<TU]
5Shv�N gGN,![ain[S5Ul124X RlUR5 UR5Ul[UR5 Sv� SnAGN�SnAff=f![2aqnUWlUR6R9U5 X l125UR5 UR5Ul[UR5 Sv� SnAGNASnAff=fN�7f)Nz%did not receive a valid HTTP responsez< HTTP/1.1 %d %sz< %s: %sz< [body] (%d bytes))r2rr�parse�reader�	read_line�126read_exact�read_to_eof�	Exceptionr
�
handshake_exc�	__cause__�send_eof�discard�parser�nextr|r`�
reason_phraser4rRr~�bodyrermr127�128_exception�eventsrqr r7)r=rj�exc�code�phraser<r\r>s       �r?r��ClientProtocol.parse,s������:�:��#�
�&.�n�n��K�K�)�)��K�K�*�*��K�K�+�+�'����z�z�'�3�3�X�5K�5K�f����!�!�"4�d�C�"*�"2�"2�"<�"<�">�J�C��K�K�%�%�j�#�=�#?��=�=��K�K�%�%�&;�S����=O�P�	
��%�%�h�/��:�:��+�+�+��D�J��K�K���x�(��7�=�?�"�"�M��129�
�%3�;�&��"�03�"�"�,��
�
��"�l�l�n����T�[�[�!����
��($�
�&)��#����"�"�8�,�%(�"��
�
��"�l�l�n����T�[�[�!����
��	#�s{�J�AF�0F�1F�5CJ�9H�130AJ�J�J�F�131H�)AH
�J�
H�J�132J�A&J�J�J�J)133r:r;r0r�r<r/r�r2rir9)r9r)r/z
Origin | Noner0z'Sequence[ClientExtensionFactory] | Noner1zSequence[Subprotocol] | Noner2r"r3z*int | None | tuple[int | None, int | None]r4zLoggerLike | None�return�None)r�r)rjrr�r�)rRrr�zlist[Extension])rRrr�zSubprotocol | None)r�rr�r�)r�zGenerator[None])�__name__�134__module__�__qualname__�__firstlineno__�__doc__rr8rTrmrgrhr�r��__static_attributes__�
__classcell__�r>s@r?r,r,0s�����8!%�>B�59�!�?D�$(�"�
�"��	"�135<�"�3�
"��"�=�"�"�"�136�"�"�.!8�F+=�ZG#�R"�H
0�)#�)#rAc�,^�\rSrSrSU4SjjrSrU=r$)�ClientConnectioniXc�\>�[R"S[5 [TU]"U0UD6 g)Nz.ClientConnection was renamed to ClientProtocol)�warnings�warn�DeprecationWarningr7r8)r=�args�kwargsr>s   �r?r8�ClientConnection.__init__Ys)����
�
�<��	137�	���$�)�&�)rA�)r�rr�rr�r�)r�r�r�r�r8r�r�r�s@r?r�r�Xs
���*�*rAr�� WEBSOCKETS_BACKOFF_INITIAL_DELAY�5�WEBSOCKETS_BACKOFF_MIN_DELAYz3.1�WEBSOCKETS_BACKOFF_MAX_DELAYz90.0�WEBSOCKETS_BACKOFF_FACTORz1.618c#�x# �[R"5U-v� UnXB:aUv� XC-nXB:aMUv� M7f)z�138Generate a series of backoff delays between reconnection attempts.139 140Yields:141    How many seconds to wait before retrying to connect.142 143)�random)�
initial_delay�	min_delay�	max_delay�factor�delays     r?�backoffr�gsF����-�-�/�M�144)�)��E�145�146���
����147�����s�/:�:z.legacy.client)�WebSocketClientProtocolrT�unix_connect)�deprecated_aliases)148r��floatr�r�r�r�r�r�r�zGenerator[float])C�149__future__r�osr�r��collections.abcrr�typingr�datastructuresrr	�150exceptionsr151rrr
rrrr0rrrRrrrrrrrr�http11rr�importsr�protocolrrr r!r"r#r$r%r&r'r(r9r)�utilsr*r+�__all__r,r�r��environ�get�BACKOFF_INITIAL_DELAY�BACKOFF_MIN_DELAY�BACKOFF_MAX_DELAY�BACKOFF_FACTORr��globalsr�rAr?�<module>r�sP��"�	�
��/��8����:�	�	�	�&� �?�?����+��152��e#�X�e#�P	*�~�*��b�j�j�n�n�-O�QT�U�V���"�*�*�.�.�)G��O�P���"�*�*�.�.�)G��P�Q���r�z�z�~�~�&A�7�K�L��1�(�(�"�	�������
�	�153��0��I�$4�#�(�	�rA
codekingpro/portable-devtools · Team Ai