Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2��j�H��3�SrSSKJr SSKJr SSKJrJr SSKrSSK	J4r5JrJr SSK
JrJrJrJrJr SS	KJr SS6KJrJrJrJrJrJr \(aSSKJrJrJr SSKJ r  S
r!Sr""SS5r#SSjr$SSjr%g)zR7wsproto/handshake8~~~~~~~~~~~~~~~~~~9 10An implementation of WebSocket handshakes.11�)�annotations)�deque)�
TYPE_CHECKING�castN�)�12Connection�ConnectionState�ConnectionType)�AcceptConnection�Event�RejectConnection�13RejectData�Request)�	Extension)�LocalProtocolError�RemoteProtocolError�generate_accept_token�generate_nonce�normed_header_dict�split_comma_header)�	Generator�Iterable�Sequence)�Headerss13s	websocketc���\rSrSrSrSSjr\SSj5r\SSj5rSSjr	SSjr14SSjrSS	jrSS15jr
SSjrSSjrSS
jrSSjrSSjrS SjrSrg)!�H11Handshake�)z4A Handshake implementation for HTTP/1.1 connections.c�l�U[RLUl[RUlUR(a*[R"[R5UlO)[R"[R5UlSUl16[5UlSUl
SUlg�N)r17�CLIENT�clientr	�18CONNECTING�_state�h11r�_h11_connection�SERVER�_connectionr�_events�_initiating_request�_nonce)�self�connection_types  �WD:\code\apps\devtools\python\user_packages\Python313\site-packages\wsproto/handshake.py�__init__�H11Handshake.__init__,sr��%��)>�)>�>���%�0�0����;�;�#&�>�>�#�*�*�#=�D� �#&�>�>�#�*�*�#=�D� �.2���%*�W���37�� �$(���c��UR$r)r#�r+s r-�state�H11Handshake.state:s���{�{�r0c��UR$)z�19Return the established connection.20 21This will either return the connection or raise a22LocalProtocolError if the connection has not yet been23established.24 25:rtype: h11.Connection26)r'r2s r-�27connection�H11Handshake.connection>s�����r0c���UR(a
Sn[U5e[R"SX!S9n[R"[R285nUR
URU55 g)z�29Initiate an upgrade connection.30 31This should be used if the request has already be received and32parsed.33 34:param list headers: HTTP headers represented as a list of 2-tuples.35:param str path: A URL path.36z?Cannot initiate an upgrade connection when acting as the client�GET��method�target�headersN)r!rr$rrr �receive_data�send)r+r=�path�msg�upgrade_request�37h11_clients      r-�initiate_upgrade_connection�(H11Handshake.initiate_upgrade_connectionKs[���;�;�S�C�$���
��+�+�V�D�R���^�^�C�J�J�/�38����*�/�/�/�:�;r0c�x�Sn[U[5(aX RU5-
nU$[U[5(aX R	U5-
nU$[U[395(aX R
U5-
nU$[U[5(aX RU5-
nU$SUS3n[U5e)z�40Send an event to the remote.41 42This will return the bytes to send based on the event or raise43a LocalProtocolError if the event is not valid given the44state.45 46:returns: Data to send to the WebSocket peer.47:rtype: bytes48r0zEvent z$ cannot be sent during the handshake)49�50isinstancer�_initiate_connectionr�_acceptr
�_rejectr�_send_reject_datar)r+�event�datarAs    r-r?�H11Handshake.send`s������e�W�%�%��-�-�e�4�4�D�����/�
0�
0��L�L��'�'�D�����/�
0�
0��L�L��'�'�D�����z�
*�
*��*�*�5�1�1�D���	�5�'�!E�F�C�$���
r0c��URRU=(d S5 URR5n[
U[R5(d&U[RLdU[RLag	UR(Ga�[
U[R5(a�URS:Xa,URRURU55 GO�URR[[!UR"5URSS95 [$R&UlGOd[
U[R*5(aW[$R,UlURR[[!UR"5URSS95 O�[
U[R.5(a.URR[1UR2SS95 O�[
U[R45(a8URR[1SSS95 [$R&UlOI[
U[R65(a*URRUR9U55 GM�![Ra Sn[	U[5S9ef=f)51z�52Receive data from the remote.53 54A list of events that the remote peer triggered by sending55this data can be retrieved with :meth:`events`.56 57:param bytes data: Data received from the WebSocket peer.58r0TzBad HTTP message��59event_hint�eF)r=�status_code�has_body)rM�
body_finishedN)r%r>�60next_eventr$rr
rG�ConnectionClosed�	NEED_DATA�PAUSEDr!�InformationalResponserSr(�append�_establish_client_connection�listr=r	�CLOSEDr#�Response�	REJECTING�DatarrM�EndOfMessager�_process_connection_request)r+rMrLrAs    r-r>�H11Handshake.receive_data{s��	
���)�)�$�+�#�6��
��,�,�7�7�9���5�#�"6�"6�7�7��C�M�M�)��C�J�J�&���{�{�{��e�S�%>�%>�?�?��(�(�C�/����+�+�D�,M�,M�e�,T�U����+�+�,�(,�U�]�]�(;�,1�,=�,=�).���'6�&<�&<�����s�|�|�4�4�"1�";�";�D�K��L�L�'�'�(�$(����$7�(-�(9�(9�%)��� ��s�x�x�0�0��L�L�'�'�"��61�62�%�H�� ��s�'7�'7�8�8��L�L�'�'�63��4�(P�Q�"1�"8�"8�D�K���E�3�;�;�/�/����#�#�D�$D�$D�U�$K�L�[���*�*�
�(��)��$4�$6���
�s�J3�3)Kc#�# �UR(a0URR5v� UR(aM/gg7f)z�64Return a generator that provides any events that have been generated65by protocol activity.66 67:returns: a generator that yields H11 events.68N)r(�popleftr2s r-�events�H11Handshake.events�s,����l�l��,�,�&�&�(�(��l�l�l�s�?A�Ac	���URS:waSn[U[5S9eSn/nSnSn/nSnSn	/n69URH�up�UR	5nUS:Xa[U5nOwUS:XaUR
S5nM@US:XaUR[U55 MbUS	:XaUnO3US70:XaUR[U55 M�US:XaUn	OUS:XaUnU71RX�45 M� Ub[S
U55(dSn[U[5S9eU	[:wa$Sn[U[S[4/U	(aSOSS9S9eUcSn[U[5S9eUR	5[:wa*S[R
5S3n[U[5S9eUcSn[U[5S9e[UU72UUURR
S5S9UlUR$)Nr9zRequest method must be GETrPr0�73connectionshost�idna�sec-websocket-extensions�sec-websocket-key�sec-websocket-protocolssec-websocket-version�upgradec3�F# �UHoR5S:Hv� M g7f��upgradeN��lower��.0�tokens  r-�	<genexpr>�;H11Handshake._process_connection_request.<locals>.<genexpr>�����074�4E�5�K�K�M�Y�&�4E���!�%Missing header, 'Connection: Upgrade'z'Missing header, 'Sec-WebSocket-Version'�Sec-WebSocket-Versioni�i�)r=rSz#Missing header, 'Sec-WebSocket-Key'�Missing header, 'Upgrade: �'zMissing header, 'Host'�ascii)�75extensions�
extra_headers�host�subprotocolsr<)r;rr
r=rtr�decode�extendr[�any�WEBSOCKET_VERSION�WEBSOCKET_UPGRADErr<r))
r+rLrA�connection_tokensr�r��keyr�rr�versionr=�name�values
             r-rc�(H11Handshake._process_connection_request�sK���<�<�6�!�.�C�%�� 0� 2��
�!�� "�76�����"$�������� �=�=�K�D��:�:�<�D��}�$�$6�u�$=�!�����|�|�F�+����4�4��!�!�"4�U�";�<���-�-����2�2��#�#�$6�u�$=�>���1�1�����#����N�N�D�=�)�')�(�$�C�077�4E�078�-79�-80�:�C�%�� 0� 2��
��'�'�;�C�%��+�6�8I�J�K�'.��C���
��;�7�C�%�� 0� 2��
��=�=�?�/�/�.�/@�/G�/G�/I�.J�!�L�C�%��+�-��
��<�*�C�%�� 0� 2��
�$+�!�!��%��<�<�&�&�w�/�$81�� ��'�'�'r0c��URce[URR5nUSn[U5nS[4SSU4/nUR82bjUR83URR;aSUR843n[U5eURSUR85RS545 UR(aN[[SURR5UR5nU(aURS	U45 [R"S86XQR-SS9n[UR (a["R$O["R&UR5Ul[*R,UlUR0R3U5=(d S
$)Nrm�Upgrade�s87Connectionr�sSec-WebSocket-Acceptzunexpected subprotocol �Sec-WebSocket-Protocolr�z
Sequence[str]�Sec-WebSocket-ExtensionsrRsSwitching Protocols)rSr=�reasonr0)r)rr�rr��subprotocolr�rr[�encoder��server_extensions_handshakerr$rZrr!r88r r&r'r	�OPENr#r%r?)	r+rL�request_headers�nonce�accept_tokenr=rA�accepts�responses	         r-rI�H11Handshake._accepts����'�'�3�3�3�,�T�-E�-E�-S�-S�T��� 4�5��,�U�3���*�+�'�
$�l�3�89�����(�� � ��(@�(@�(M�(M�M�/��0A�0A�/B�C��(��-�-��N�N�*�E�,=�,=�,D�,D�W�,M�N�
����1��_�d�&>�&>�&I�&I�J�� � ��G����� ;�W�E�F��,�,���1�1�1�)�90��91&�%)�[�[�N�!�!�n�6K�6K����92���&�*�*����#�#�(�(��2�9�c�9r0c�R�UR[R:waSUR3n[U5e[	UR935nUR(dURS5 [R"URUS9nURRU5=(d Sn[RUlUR(dNXPRR[R"55=(d S-
n[R UlU$)Nz'Connection cannot be rejected in state )scontent-length�0)rSr=r0)r3r	r"rr]r=rTr[r$r_rSr%r?r`r#rbr^)r+rLrAr=r�rMs      r-rJ�H11Handshake._reject8s����:�:��3�3�3�;�D�J�J�<�H�C�$���
��u�}�}�%���~�~��N�N�4�5��<�<�E�,=�,=�w�O���#�#�(�(��2�9�c��%�/�/����~�~��(�(�-�-�c�.>�.>�.@�A�H�S�H�D�)�0�0�D�K��r0c��UR[R:waSUR3n[U5eURR[R"URS95=(d SnUR(aNX0RR[R"55=(d S-
n[RUlU$)Nz$Cannot send rejection data in state )rMr0)
r3r	r`rr%r?r$rarMrUrbr^r#)r+rLrArMs    r-rK�H11Handshake._send_reject_dataJs����:�:��2�2�2�8�����E�C�$���
��#�#�(�(����u�z�z�)B�C�J�s������(�(�-�-�c�.>�.>�.@�A�H�S�H�D�)�0�0�D�K��r0c���Xl[5UlSURR	S54S[944SSUR4S[4/nUR(a;URSSRUR5R	S	545 UR(a�0nURH6n[U[5(deUR5X4R'M8 /nUR5HkupgUR	S	5n[U[ 5(aU(aURU5 MEMGURS95X�R	S	54-5 Mm U(a"URSSRU545 ["R$"S
UR&R	S	5X!R(-S9n	UR*R-U	5=(d S$)NsHostrkr�r�sSec-WebSocket-Keyr}r�z, r��%s; %sr��, r9r:r0)r)rr*r�r�r�r�r�r[�joinr�rGr�offerr��items�boolr$rr<r�r%r?)96r+�requestr=�offers�er�r��params�bnamerrs97          r-rH�!H11Handshake._initiate_connectionYs���#*� �$�&����g�l�l�)�)�&�1�2�
�*�+�'�
!�4�;�;�/�
%�'8�9�98������N�N�-��Y�Y�w�3�3�4�<�<�W�E��
����,.�F��'�'��!�!�Y�/�/�/�/�!"�����v�v��(��J� &���������G�,���f�d�+�+��"�)�)�%�0���%�%�i�5�-�-��:P�2Q�&Q�R�
!/����� ;�U�Z�Z�99�=S�T�U��+�+���>�>�(�(��1��3�3�3�100��101�#�#�(�(��1�8�S�8r0c�N�URceURceSnSn/nSnSn/nURHzup�UR5nUS:Xa
[	U	5nM(US:Xa
[	U	5nM;US:XaU	nMEUS:XaU	RS5nM^US:XaU	nMhUR
X�45 M| Ub[SU55(dS	n102[U103[5S1049eUR5[:wa*S[R5S3n105[U106[5S1079e[UR5nX+:waS
n108[U109[5S1109eUb0XPRR;aSU3n111[U112[5S1139e[U[SURR55n[!UR"(a[$R&O[$R(UUR*R,S5Ul[0R2Ul[7X�US9$)Nr0rjrlssec-websocket-acceptrnr�roc3�F# �UHoR5S:Hv� M g7frqrsrus  r-rx�<H11Handshake._establish_client_connection.<locals>.<genexpr>�rzr{r|rPr~rzBad accept tokenzunrecognized subprotocol �Sequence[Extension]r)r�r�r�)r)r*r=rtrr�r[r�rr
r�rr��client_extensions_handshakerr�rr!r114r r&r%�
trailing_datar'r	r�r#r)
r+rL�acceptr�r�r�rrr=r�r�rAr�r�s
             r-r\�)H11Handshake._establish_client_connection�s;���'�'�3�3�3��{�{�&�&�&��� ���������� �=�=�K�D��:�:�<�D��}�$�$6�u�$=�!���2�2�,�U�3����.�.�����0�0�#�l�l�7�3����z�!�����N�N�D�=�)�#)�&�$�C�0115�4E�0116�-117�-118�:�C�%�� 0� 2��
��=�=�?�/�/�.�/@�/G�/G�/I�.J�!�L�C�%��+�-��
�-�T�[�[�9���!�$�C�%�c�6F�6H�I�I��"�{�:R�:R�:_�:_�'_�-�k�]�;�C�%��+�-��
�1��T�/��1I�1I�1T�1T�U�119�120�&�%)�[�[�N�!�!�n�6K�6K��� � �.�.�q�1�121���122&�*�*����!�k�123�	124r0c�h�URRSURSURS3$)Nz(client=z, state=�))�	__class__�__name__r!r3r2s r-�__repr__�H11Handshake.__repr__�s/���.�.�)�)�*�(�4�;�;�-�x��125�126�|�ST�U�Ur0)r'r(r%r)r*r#r!N)r,r127�return�None)r�r	)r�zConnection | None)r=rr@zbytes | strr�r�)rLrr��bytes)rM�bytes | Noner�r�)r�zGenerator[Event, None, None])rLzh11.Requestr�r)rLrr�r�)rLr
r�r�)rLrr�r�)r�rr�r�)rLzh11.InformationalResponser�r)r��str)r��128__module__�__qualname__�__firstlineno__�__doc__r.�propertyr3r6rDr?r>rgrcrIrJrKrHr\r��__static_attributes__�r0r-rr)s���>�)������129 ��130 �<��<�&1�<�	
�<�*�67M�r)�L(� �L(�	�L(�\(:�T�$�)9�VC131�.�C132�	�C133�JVr0rc��0nUH�nURSS5SR5nUHvnURU:XdMURU5n[	U[1345(aU(aSX%R'MRMTUcMYUR
S5X%R'Mx M� U(a�/nUR5HxupHUR
S5n	[	U[1355(aU(deURU	5 MGUS:XaURSU	-5 McURS	X�4-5 Mz S136RU5$g)z|137Agree on the extensions to use returning an appropriate header value.138 139This returns None if there are no agreed extensions140�;rrTNr�r0s%sr�r�)141�split�stripr�r�rGr�r�r�r[r�)142�	requested�	supportedr�r�r��	extensionr�r�r��143name_bytess144          r-r�r��s#��(*�G����{�{�3��"�1�%�+�+�-��"�I��~�~��%�"�)�)�%�0���f�d�+�+��26����/���'�.4�m�m�G�.D�G�N�N�+�#���"$�145�#�M�M�O�L�D����W�-�J��&�$�'�'��
�v��!�!�*�-��3���!�!�%�:�"6�7��!�!�)�z�.B�"B�C�,��z�z�*�%�%�r0c��/nUHynURSS5SR5nUH8nURU:XdMURU5 UR	U5  Mb SU3n[U[
5S9e U$)Nr�rrzunrecognized extension rP)r�r�r��finalizer[rr
)�acceptedr�r�r�r�r�rAs       r-r�r��s���146�J����|�|�C��#�A�&�,�,�.��"�I��~�~��%��"�"�6�*��!�!�)�,��	#�,�D�6�2�C�%�� 0� 2��
���r0)r��
Iterable[str]r��list[Extension]r�r�)r�r�r�r�r�r�)&r��147__future__r�collectionsr�typingrrr$r6rr	r148rgrrr
rrr�r�	utilitiesrrrrrr�collections.abcrrrrr�r�rr�r�r�r0r-�<module>r�s����#���149�C�C�R�R�!����=�=����!��aV�aV�H
!��!�)8�!��!�H���(;���r0
codekingpro/portable-devtools · Team Ai