Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2p�j�@��L�SSKJr SSKrSSKrSSKrSSKrSSKJr SSKJ	r	J3r4Jr SSKJ
r
Jr SSKJrJrJrJrJrJr /SQr\5"S	5rS6S.S-SjjrS.S
jr\R2"S5rS/Sjr\R2"S5rS0Sjr\R2"S5r\R2"S5rS0Sjr \R2"S5r!\R2"S5r"S1Sjr#S2Sjr$S3Sjr%S4Sjr&\R2"S5r'S5Sjr(S6Sjr)S7Sjr*S8Sjr+S9S jr,\,r-S:S!jr.S;S"jr/\/r0S<S#jr1S=S$jr2\2r3S>S%jr4\4r5S?S&jr6S@S'jr7\R2"S(5r8S0S)jr9SAS*jr:SBS+jr;SCS,jr<g)D�)�annotationsN)�Sequence)�Callable�TypeVar�cast�)�InvalidHeaderFormat�InvalidHeaderValue)�ConnectionOption�ExtensionHeader�
ExtensionName�ExtensionParameter�Subprotocol�UpgradeProtocol)�7build_host�parse_connection�
parse_upgrade�parse_extension�build_extension�parse_subprotocol�build_subprotocol�validate_subprotocols�build_www_authenticate_basic�parse_authorization_basic�build_authorization_basic�TF)�always_include_portc��[R"U5nURS:XaSUS3nU(dX(aSOS:waUSU3nU$![a N*f=f)z8Build a ``Host`` header.9 10��[�]i��P�:)�	ipaddress�11ip_address�version�12ValueError)�host�port�securer�addresss     �XD:\code\apps\devtools\python\user_packages\Python313\site-packages\websockets/headers.pyrr'si����&�&�t�,���?�?�a���t�f�A�;�D��d�f�s�"�=���q������K���
��
�s�A�13A�Ac�,�U[U5:XaS$X$)z�14Return the next character from ``header`` at the given position.15 16Return :obj:`None` at the end of ``header``.17 18We never need to peek more than one character ahead.19 20N)�len)�header�poss  r,�21peek_aheadr1Is���#�f�+�%�4�6�6�;�6�z[\t ]*c�V�[RX5nUceUR5$)z�22Parse optional whitespace from ``header`` at the given position.23 24Return the new position.25 26The whitespace itself isn't returned because it isn't significant.27 28)�_OWS_re�match�end)r/r0r5s   r,�	parse_OWSr7Xs*��
�M�M�&�&�E������9�9�;�r2z[-!#$%&\'*+.^_`|~0-9a-zA-Z]+c��[RX5nUc
[USX5eUR5UR	54$)z�29Parse a token from ``header`` at the given position.30 31Return the token value and the new position.32 33Raises:34    InvalidHeaderFormat: On invalid inputs.35 36zexpected token)�	_token_rer5r	�groupr6�r/r0�header_namer5s    r,�parse_tokenr=js>��
�O�O�F�(�E��}�!�+�/?��M�M��;�;�=�%�)�)�+�%�%r2zC"(?:[\x09\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x09\x20-\x7e\x80-\xff])*"z\\([\x09\x20-\x7e\x80-\xff])c��[RX5nUc
[USX5e[R	SUR5SS5UR
54$)z�37Parse a quoted string from ``header`` at the given position.38 39Return the unquoted value and the new position.40 41Raises:42    InvalidHeaderFormat: On invalid inputs.43 44zexpected quoted stringz\1r�����)�_quoted_string_rer5r	�_unquote_re�subr:r6r;s    r,�parse_quoted_stringrC�sR��
�#�#�F�0�E��}�!�+�/G��U�U��?�?�5�%�+�+�-��"�"5�6��	�	��C�Cr2z[\x09\x20-\x7e\x80-\xff]*z([\x22\x5c])c��[RU5nUc[S5eS[R	SU5-S-$)z\45Format ``value`` as a quoted string.46 47This is the reverse of :func:`parse_quoted_string`.48 49z-invalid characters for quoted-string encoding�"z\\\1)�_quotable_re�	fullmatchr'�	_quote_rerB)�valuer5s  r,�build_quoted_stringrJ�s@��
�"�"�5�)�E��}��H�I�I�����w��.�.��4�4r2c���[X5S:Xa[XS-5n[X5S:XaM/nU"XU5upRURU5 [X5nU[U5:XaOk[X5S:Xa[XS-5nO
[	USX5e[X5S:Xa[XS-5n[X5S:XaMU[U5:XaOM�U[U5:XdeU$)a�50Parse a comma-separated list from ``header`` at the given position.51 52This is appropriate for parsing values with the following grammar:53 54    1#item55 56``parse_item`` parses one item.57 58``header`` is assumed not to start or end with whitespace.59 60(This function is designed for parsing an entire header value and61:func:`~websockets.http.read_headers` strips whitespace from values.)62 63Return a list of items.64 65Raises:66    InvalidHeaderFormat: On invalid inputs.67 68�,rzexpected comma)r1r7�appendr.r	)�69parse_itemr/r0r<�items�items      r,�70parse_listrQ�s���>�V�71!�S�72(���a��(���V�73!�S�74(�
�E�75��v�K�8�	��
���T����$���#�f�+����f�"�c�)��F�!�G�,�C�%�k�3C�V�Q�Q���%��,��F�!�G�,�C���%��,��#�f�+���-�4�#�f�+�����Lr2c�B�[XU5up1[[U5U4$)z�76Parse a Connection option from ``header`` at the given position.77 78Return the protocol value and the new position.79 80Raises:81    InvalidHeaderFormat: On invalid inputs.82 83)r=rr�r/r0r<rPs    r,�parse_connection_optionrT�s%���F��5�I�D�� �$�'��,�,r2c�&�[[USS5$)z�84Parse a ``Connection`` header.85 86Return a list of HTTP connection options.87 88Args89    header: value of the ``Connection`` header.90 91Raises:92    InvalidHeaderFormat: On invalid inputs.93 94r�95Connection)rQrT�r/s r,rr�s���-�v�q�,�G�Gr2z>[-!#$%&\'*+.^_`|~0-9a-zA-Z]+(?:/[-!#$%&\'*+.^_`|~0-9a-zA-Z]+)?c��[RX5nUc
[USX5e[[UR55UR
54$)z�96Parse an Upgrade protocol from ``header`` at the given position.97 98Return the protocol value and the new position.99 100Raises:101    InvalidHeaderFormat: On invalid inputs.102 103zexpected protocol)�_protocol_rer5r	rrr:r6r;s    r,�parse_upgrade_protocolrZsG��
���v�+�E��}�!�+�/B�F�P�P�������/�����<�<r2c�&�[[USS5$)z�104Parse an ``Upgrade`` header.105 106Return a list of HTTP protocols.107 108Args:109    header: Value of the ``Upgrade`` header.110 111Raises:112    InvalidHeaderFormat: On invalid inputs.113 114r�Upgrade)rQrZrWs r,rrs���,�f�a��C�Cr2c�4�[XU5up1[X5nSn[X5S:Xaj[XS-5n[X5S:Xa4Un[XU5upA[RU5c
[
USX5eO[XU5upA[X5nX44U4$)z�115Parse a single extension parameter from ``header`` at the given position.116 117Return a ``(name, value)`` pair and the new position.118 119Raises:120    InvalidHeaderFormat: On invalid inputs.121 122N�=rrEzinvalid quoted header content)r=r7r1rCr9rGr	)r/r0r<�namerI�123pos_befores      r,�parse_extension_item_paramra.s����F��5�I�D�124�F�125 �C��E��&��#�%���a��(���f�"�c�)��J�,�V�+�F�J�E��"�"�5�)�1�)��!@�&���2�126%�V�+�>�J�E���$���=�#��r2c���[XU5up1[X5n/n[X5S:Xa>[XS-5n[XU5upQUR	U5 [X5S:XaM>[[U5U4U4$)z�127Parse an extension definition from ``header`` at the given position.128 129Return an ``(extension name, parameters)`` pair, where ``parameters`` is a130list of ``(name, value)`` pairs, and the new position.131 132Raises:133    InvalidHeaderFormat: On invalid inputs.134 135�;r)r=r7r1rarMrr
)r/r0r<r_�136parameters�	parameters      r,�parse_extension_itemrfRs����F��5�I�D�137�F�138 �C��J�139�V�140!�S�141(���a��(��3�F��M��	����)�$��V�142!�S�143(�
���%�z�2�C�7�7r2c�&�[[USS5$)a�144Parse a ``Sec-WebSocket-Extensions`` header.145 146Return a list of WebSocket extensions and their parameters in this format::147 148    [149        (150            'extension name',151            [152                ('parameter name', 'parameter value'),153                ....154            ]155        ),156        ...157    ]158 159Parameter values are :obj:`None` when no value is provided.160 161Raises:162    InvalidHeaderFormat: On invalid inputs.163 164rzSec-WebSocket-Extensions)rQrfrWs r,rrks��.�*�F�A�7Q�R�Rr2c165��SR[[U5/UVVs/sHupUcUOUSU3PM snn-5$s snnf)zW166Build an extension definition.167 168This is the reverse of :func:`parse_extension_item`.169 170z; r^)�joinr�str)r_rdrIs   r,�build_extension_itemrk�s`���9�9�	
�c�4��� *�171� *����M�D�$��q���'8�8�)�172�	173����174s�Ac�2�SRSU55$)z`175Build a ``Sec-WebSocket-Extensions`` header.176 177This is the reverse of :func:`parse_extension`.178 179�, c3�<# �UHup[X5v� M g7f)N)rk)�.0r_rds   r,�	<genexpr>�"build_extension.<locals>.<genexpr>�s����GQ�3C�4��T�.�.�z�s��ri)�180extensionss r,rr�s"���9�9��GQ���r2c�B�[XU5up1[[U5U4$)z�181Parse a subprotocol from ``header`` at the given position.182 183Return the subprotocol value and the new position.184 185Raises:186    InvalidHeaderFormat: On invalid inputs.187 188)r=rrrSs    r,�parse_subprotocol_itemru�s$���F��5�I�D���T�"�C�'�'r2c�&�[[USS5$)z�189Parse a ``Sec-WebSocket-Protocol`` header.190 191Return a list of WebSocket subprotocols.192 193Raises:194    InvalidHeaderFormat: On invalid inputs.195 196rzSec-WebSocket-Protocol)rQrurWs r,rr�s���,�f�a�9Q�R�Rr2c�$�SRU5$)z`197Build a ``Sec-WebSocket-Protocol`` header.198 199This is the reverse of :func:`parse_subprotocol`.200 201rmrr)�subprotocolss r,rr�s���9�9�\�"�"r2c���[U[5(d[S5e[U[5(a[S5eUH+n[RU5(aM[
SU35e g)zL202Validate that ``subprotocols`` is suitable for :func:`build_subprotocol`.203 204zsubprotocols must be a listz&subprotocols must be a list, not a strzinvalid subprotocol: N)�205isinstancer�	TypeErrorrjr9rGr')rx�subprotocols  r,rr�sd��206�l�H�-�-��5�6�6��,��$�$��@�A�A�#���"�"�;�/�/��4�[�M�B�C�C�$r2c�>�[U5n[S5nSUSU3$)zq207Build a ``WWW-Authenticate`` header for HTTP Basic Auth.208 209Args:210    realm: Identifier of the protection space.211 212zUTF-8zBasic realm=z213, charset=)rJ)�realm�charsets  r,rr�s+��
 ��&�E�!�'�*�G�
�%��214�7�)�4�4r2z[A-Za-z0-9-._~+/]+=*c��[RX5nUc
[USX5eUR5UR	54$)z�215Parse a token68 from ``header`` at the given position.216 217Return the token value and the new position.218 219Raises:220    InvalidHeaderFormat: On invalid inputs.221 222zexpected token68)�_token68_rer5r	r:r6r;s    r,�
parse_token68r��s@��
���f�*�E��}�!�+�/A�6�O�O��;�;�=�%�)�)�+�%�%r2c�<�U[U5:a
[USX5eg)z0223Check that parsing reached the end of header.224 225z
trailing dataN)r.r	)r/r0r<s   r,�	parse_endr�s$��226�S��[��!�+���L�L�r2c���[USS5upUR5S:wa[SSU35e[X5S:wa
[	SSX5eUS-
n[XS5up2[
XS5 [R"UR55R5nURS227S5upVXV4$![Ra [SS5S	ef=f![a [SS5S	ef=f)a228Parse an ``Authorization`` header for HTTP Basic Auth.229 230Return a ``(username, password)`` tuple.231 232Args:233    header: Value of the ``Authorization`` header.234 235Raises:236    InvalidHeaderFormat: On invalid inputs.237    InvalidHeaderValue: On unsupported inputs.238 239r�
Authorization�basiczunsupported scheme: � zexpected space after schemerz#expected base64-encoded credentialsNr#z&expected username:password credentials)r=�lowerr240r1r	r�r��base64�	b64decode�encode�decode�binascii�Error�splitr')r/�schemer0�basic_credentials�	user_pass�username�passwords       r,rrs%�� �f�a��9�K�F�
�|�|�~�� � ��"�6�(�+�241�	242��&��#�%�!��:�F�243�	244��1�H�C�*�6��H���
�f�?�+���$�$�%6�%=�%=�%?�@�G�G�I�	��&�_�_�S�!�4��������>�>�� ��1�245��	����� ��4�246��	��s�/2B9�"C�9"C�C6c��SU;deUSU3n[R"UR55R5nSU-$)zt247Build an ``Authorization`` header for HTTP Basic Auth.248 249This is the reverse of :func:`parse_authorization_basic`.250 251r#zBasic )r��	b64encoder�r�)r�r�r�r�s    r,rr?sQ���h�����*�A�h�Z�(�I��(�(��)9�)9�);�<�C�C�E���'�'�'r2)252r(rjr)�intr*�boolrr��returnrj)r/rjr0r�r�z253str | None)r/rjr0r�r�r�)r/rjr0r�r<rjr�ztuple[str, int])rIrjr�rj)254rNz(Callable[[str, int, str], tuple[T, int]]r/rjr0r�r<rjr�zlist[T])r/rjr0r�r<rjr�ztuple[ConnectionOption, int])r/rjr�zlist[ConnectionOption])r/rjr0r�r<rjr�ztuple[UpgradeProtocol, int])r/rjr�zlist[UpgradeProtocol])r/rjr0r�r<rjr�ztuple[ExtensionParameter, int])r/rjr0r�r<rjr�ztuple[ExtensionHeader, int])r/rjr�zlist[ExtensionHeader])r_r
rdzSequence[ExtensionParameter]r�rj)rszSequence[ExtensionHeader]r�rj)r/rjr0r�r<rjr�ztuple[Subprotocol, int])r/rjr�zlist[Subprotocol])rx�Sequence[Subprotocol]r�rj)rxr�r��None)r~rjr�rj)r/rjr0r�r<rjr�r�)r/rjr�ztuple[str, str])r�rjr�rjr�rj)=�255__future__rr�r�r$�re�collections.abcr�typingrrr�256exceptionsr	r257rrr
rrr�__all__rrr1�compiler4r7r9r=r@rArCrFrHrJrQrTrrYrZrrarfr�parse_extension_listrkr�build_extension_listrur�parse_subprotocol_listr�build_subprotocol_listrrr�r�r�rr�r2r,�<module>r�s���"�
���	�$�*�*�?������C�L��!&��258
��259
��
��260��	�
�D	7�
�*�*�Y�261���
�J�J�6�7�	�
&� �J�J�J���262�j�j�8�9��
D� �z�z�6�7��
�J�J��'�	�2635�?�8�?��?�264
�?��	?�265
�?�D
-��
-��
-�(+�
-�!�
-� 
H� �z�z�E���266=��=��=�(+�=� �=�$
D� !��!��!�(+�!�#�!�H8��8��8�(+�8� �8�2S�4'���267��%A����&	�'��
(��
(��
(�(+�
(��
(� 268S�+��#�+��D�5��j�j�0�1��
&� M�-�`(r2
codekingpro/portable-devtools · Team Ai