Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2��j�g����SrSSKJr SSKrSSKJrJrJr SSKJ	r	J3r4 SSKJrJ
r
 \(aSSKJrJr SS	KJrJr \"S55r\"S5r\"/SQ5r\"/S
Q5r\"SS/5r\"/SQ5r\"S/5r\"S/5rS2SjrS3SjrS4SjrS5Sjr S3Sjr!"SS\5r"S6Sjr#S7Sjr$S7Sjr%S7Sjr&S7Sjr'S8Sjr(S7S jr)S9S!jr*S:S"jr+S7S#jr,S7S$jr-S;S%jr.S<S&jr/S2S'jr0S2S(jr1S2S)jr2S7S*jr3S7S+jr4S2S,jr5S=S>S-jjr6S7S.jr7S7S/jr8"S0S1\Rr\:\45r;g)?zW6h2/utilities7~~~~~~~~~~~~8 9Utility functions that do not belong in a separate module.10�)�annotationsN)�
TYPE_CHECKING�Any�11NamedTuple)�HeaderTuple�NeverIndexedHeaderTuple�)�FlowControlError�
ProtocolError)�	Generator�Iterable)�Header�HeaderWeaklyTyped�:�1)s12connectionsproxy-connections13keep-alivestransfer-encodingsupgrade)�:method�:scheme�14:authority�:path�:status�	:protocols
authorizationsproxy-authorization)rrrrrrrc#��# �UH_n[US[5(deUS[;dUSS;a([US5S:a[	USUS5v� M[Uv� Ma g7f)a^15Certain headers are at risk of being attacked during the header compression16phase, and so need to be kept out of header compression contexts. This17function automatically transforms certain specific headers into HPACK18never-indexed fields to ensure they don't get added to header compression19contexts.20 21This function currently implements two rules:22 23- 'authorization' and 'proxy-authorization' fields are automatically made24  never-indexed.25- Any 'cookie' header field shorter than 20 bytes long is made26  never-indexed.27 28These fields are the most at-risk. These rules are inspired by Firefox29and nghttp2.30r�cookier	�N)�31isinstance�bytes�_SECURE_HEADERS�lenr��headers�hdr_validation_flags�headers   �RD:\code\apps\devtools\python\user_packages\Python313\site-packages\h2/utilities.py�_secure_headersr$Fsj���&���&��)�U�+�+�+�+��!�9��'�F�1�I��,B�s�6�RS�9�~�XZ�GZ�)�&��)�V�A�Y�?�?��L��s�A'A)c��UHTup[U[5(a32US:XaUs $[U[5(dM;US:XdMCURS5s $ g)z433Extracts the request method from the headers list.34rz:method�utf-8N)rr�str�encode)r �k�vs   r#�extract_method_headerr+asO������a����A��O��H��a����!�y�.��8�8�G�$�$�	�35�c�|�UH6upURS5(d gUS:waM%URS5s $ g)a�36Searches headers list for a :status header to confirm that a given37collection of headers are an informational response. Assumes the header38are well formed and encoded as bytes: that is, that the HTTP/2 special39headers are first in the block, and so that it can stop looking when it40finds the first header field whose name does not begin with a colon.41 42:param headers: The HTTP/2 headers.43:returns: A boolean indicating if this is an informational response.44rFrr)�45startswith�r �nr*s   r#�is_informational_responser1ms@������|�|�D�!�!���46�?���|�|�D�!�!��r,c�<�SnX-nX2:�aSU3n[U5eU$)a47Increments a flow control window, guarding against that window becoming too48large.49 50:param current: The current value of the flow control window.51:param increment: The increment to apply to that window.52:returns: The new value of the window.53:raises: ``FlowControlError``54i���z+May not increment flow control window past )r55)�current�	increment�LARGEST_FLOW_CONTROL_WINDOW�new_size�msgs     r#�guard_increment_windowr8�s6��#,���"�H��-�;�<W�;X�Y���s�#�#��Or,c�.�UHupUS:XdM
Us $ g)a�56Given a header set, searches for the authority header and returns the57value.58 59Note that this doesn't use indexing, so should only be called if the60headers are for a client request. Otherwise, will loop over the entire61header set, which is potentially unwise.62 63:param headers: The HTTP header set.64:returns: The value of the authority header, or ``None``.65:rtype: ``bytes`` or ``None``.66rN�r/s   r#�authority_from_headersr;�s"������
���H��r,c�>�\rSrSr%S\S'S\S'S\S'S\S'Srg)	�HeaderValidationFlags��bool�	is_client�67is_trailer�is_response_header�is_push_promiser:N)�__name__�68__module__�__qualname__�__firstlineno__�__annotations__�__static_attributes__r:r,r#r=r=�s���O������r,r=c��[X5n[X5n[X5n[X5n[	X5n[X5n[
X5$)z�69Validates a header sequence against a set of constraints from RFC 7540.70 71:param headers: The HTTP header set.72:param hdr_validation_flags: An instance of HeaderValidationFlags.73)�_reject_illegal_characters�_reject_empty_header_names�74_reject_te�_reject_connection_header�_reject_pseudo_header_fields�_check_host_authority_header�_check_path_header�r r!s  r#�validate_headersrS�si�� )���G�)���G����G�(���G�+���G�+���G��g�<�<r,c#�0# �UGHnUSHTnSUs=::aS::aO OSUS<S3n[U5eUS::dUS:�dM6S[U5S	US<3n[U5e USRS75S5S:waS
US<3n[U5eUS=n(amUH2nUS:XdUS:XdUS:XdMS[U5SU<3n[U5e USS:XdUSS:XdUSS:Xd	USS:XaSU<3n[U5eUv� GM g7f)z�76Raises a ProtocolError if any header names or values contain illegal characters.77See <https://www.rfc-editor.org/rfc/rfc9113.html#section-8.2.1>.78r�A�ZzReceived uppercase header name �.� �zIllegal character 'z' in header name: rr	�����z&Illegal character ':' in header name: �79�
z' in header value: �	z/Received header value surrounded by whitespace N)r�chr�find)r r!r"�cr7�field_values      r#rKrK�sS��������A��q� �D� �7��q�	�}�A�F��#�C�(�(��D�y�A��I�+�C��F�8�3E�f�Q�i�]�S��#�C�(�(�
��!�9�>�>�$��"�b�(�:�6�!�9�-�H�C���$�$�!��)�#�;�#�!����6�Q�$�Y�!�t�)�/��A��x�7J�;�/�Z�C�'��,�,�!��A��$�&��A��$�&��B��4�'��B��4�'�G���W��#�C�(�(���Q�s�>D�A0D�8ADc#�d# �UH&n[US5S:Xa
Sn[U5eUv� M( g7f)z�80Raises a ProtocolError if any header names are empty (length 0).81While hpack decodes such headers without errors, they are semantically82forbidden in HTTP, see RFC 7230, stating that they must be at least one83character long.84rz&Received header name with zero length.N)rr�r r!r"r7s    r#rLrLs6������v�a�y�>�Q��:�C���$�$���	�s�.0c#�# �UH;nUSS:Xa+USR5S:waSUS<3n[U5eUv� M= g7f)zw85Raises a ProtocolError if the TE header is present in a header block and86its value is anything other than "trailers".87rster	strailerszInvalid value for TE header: N)�lowerrrcs    r#rMrMsO���88���!�9���&��)�/�/�"3�{�"B�1�&��)��?�C���$�$����s�AAc#�j# �UH)nUS[;aSUS<S3n[U5eUv� M+ g7f)zO89Raises a ProtocolError if the Connection header is present in a header90block.91rz*Connection-specific header field present: rWN)�CONNECTION_HEADERSrrcs    r#rNrN(s@���92���!�9�*�*�>�v�a�y�m�1�M�C���$�$����s�13c�2�X;aSU<S3n[U5eg)z�93Given a set of header names, checks whether the string or byte version of94the header name is present. Raises a Protocol error with the appropriate95error if it's missing.96zHeader block missing mandatory z headerN�r)�bytes_header�97header_setr7s   r#�_assert_header_in_setrl5s)���%�/��/?�w�G���C� � �&r,c#�v# �[5nSnSnUH�nUSS[:Xa|USU;aSUS<3n[U5eURUS5 U(aSUS<3n[U5eUS[;aSUS<3n[U5eUSS;aUSnOS	nUv� M� [X$U5 g7f)98z�99Raises a ProtocolError if duplicate pseudo-header fields are found in a100header block or if a pseudo-header field appears in a block after an101ordinary header field.102 103Raises a ProtocolError if pseudo-header fields are found in trailers.104FNrz'Received duplicate pseudo-header field z.Received pseudo-header field out of sequence: z$Received custom pseudo-header field rr	T)�set�SIGILr�add�_ALLOWED_PSEUDO_HEADER_FIELDS�(_check_pseudo_header_field_acceptability)r r!�seen_pseudo_header_fields�seen_regular_header�methodr"r7s       r#rOrOAs����!$�����
�F����!�9�Q�<�5� ��a�y�5�5�?��q�	�}�M��#�C�(�(�%�)�)�&��)�4�"�F�v�a�y�m�T��#�C�(�(��a�y� =�=�<�V�A�Y�M�J��#�C�(�(��a�y�J�&������#'����-�2-�!�+?��s�B7B9c���UR(aU(aSU3n[U5eUR(a-[SU5 U[-nU(aSU3n[U5eg105UR(dUR(dm[SU5 [SU5 [SU5 U[106-nU(aSU3n[U5eUS:wa"U[-nU(aS	U<3n[U5eg107g108g109g110)zy111Given the set of pseudo-headers present in a header block and the112validation flags, confirms that RFC 7540 allows them.113z"Received pseudo-header in trailer rz!Encountered request-only headers rrrz"Encountered response-only headers sCONNECTz)Encountered connect-request-only headers N)rArrBrl�_REQUEST_ONLY_HEADERS�_RESPONSE_ONLY_HEADERS�_CONNECT_REQUEST_ONLY_HEADERS)�pseudo_headersrur!r7�invalid_response_headers�invalid_request_headers�invalid_headerss       r#rrrrls���&�&�>�2�>�2B�C���C� � ��.�.��j�.�9�#1�4I�#I� �#�5�6N�5O�P�C���$�$�$�#�5�5�"�-�-�	�h��7��j�.�9��j�.�9�"0�3I�"I��"�6�7N�6O�P�C���$�$��Z��,�/L�L�O��A�/�AT�U��#�C�(�(�� �.�6r,c#�# �SnSnUH$nUSS:XaUSnOUSS:XaUSnUv� M& USLnUSLnU(dU(d
Sn[U5eU(a#U(aX:waSU<SU<3n[U5eggg7f)	z�114Given the :authority and Host headers from a request block that isn't115a trailer, check that:116 1. At least one of these headers is set.117 2. If both headers are set, they match.118 119:param headers: The HTTP header set.120:raises: ``ProtocolError``121Nrrr	shostz@Request header block does not have an :authority or Host header.zARequest header block has mismatched :authority and Host headers: z / ri)r �authority_header_val�host_header_valr"�authority_present�host_presentr7s       r#�_validate_host_authority_headerr��s����" ���O����!�9�
�%�#)�!�9� �
�A�Y�'�
!�$�Q�i�O���
�.�T�9��#�4�/�L��\�P���C� � ��\�.B�.U�
�1�4�C��7J�
L�	��C� � �/V�\��s�A=A?c�v�UR=(d URnU(a	SU5$[U5$)z�122Raises a ProtocolError if a header block arrives that does not contain an123:authority or a Host header, or if a header block contains both fields,124but their values do not match.125c3�$# �UHov� M g7f�Nr:��.0�hs  r#�	<genexpr>�/_check_host_authority_header.<locals>.<genexpr>�����#�7�a��7����rBrAr��r r!�skip_validations   r#rPrP��;��	�/�/�	(��'�'���#�7�#�#�*�7�3�3r,c�^�SU4SjjnUR=(d URnU(a	ST5$U"5$)za126Raise a ProtocolError if a header block arrives or is sent that contains an127empty :path header.128c3�h># �TH'nUSS:XaUS(d
Sn[U5eUv� M) g7f)Nrrr	z"An empty :path header is forbiddenri)r"r7r s  �r#�inner�!_check_path_header.<locals>.inner�s7�����F��a�y�H�$�V�A�Y�:��#�C�(�(��L��s�/2c3�$# �UHov� M g7fr�r:r�s  r#r��%_check_path_header.<locals>.<genexpr>�r�r�)�return�Generator[Header, None, None])rBrA)r r!r�r�s`   r#rQrQ�s=����	�/�/�	(��'�'���#�7�#�#��7�Nr,c�R�[U[5(aU$URS5$)z�129Given an assumed `str` (or anything that supports `.encode()`),130encodes it using utf-8 into bytes. Returns the unmodified object131if it is already a `bytes` object.132r&)rrr()r*s r#�	_to_bytesr��s$���1�e�$�$�1�;�!�(�(�7�*;�;r,c���/nUHnn[US5[US54n[U[5(a)URUR	USUS55 M]URU5 Mp U$)z�133Given an iterable of header two-tuples, rebuilds that as a list with the134header names and values encoded as utf-8 bytes. This function produces135tuples that preserve the original type of the header tuple for tuple and136any ``HeaderTuple``.137rr	)r�rr�append�	__class__)r �encoded_headersr"r�s    r#�utf8_encode_headersr��su��%'�O���
�v�a�y�
!�9�V�A�Y�#7�8���f�k�*�*��"�"�6�#3�#3�A�a�D�!�A�$�#?�@��"�"�1�%���r,c#��# �UH\n[U[5(a*URUSR5US5v� MBUSR5US4v� M^ g7f)z�138Given an iterable of header two-tuples, rebuilds that iterable with the139header names lowercased. This generator produces tuples that preserve the140original type of the header tuple for tuple and any ``HeaderTuple``.141rr	N)rrr�rers   r#�_lowercase_header_namesr�sZ������f�k�*�*��"�"�6�!�9�?�?�#4�f�Q�i�@�@��!�9�?�?�$�f�Q�i�0�0�	�s�A$A&c#�# �UHxn[U[5(a8URUSR5USR55v� MPUSR5USR54v� Mz g7f)z�142Given an iterable of header two-tuples, strip both leading and trailing143whitespace from both header names and header values. This generator144produces tuples that preserve the original type of the header tuple for145tuple and any ``HeaderTuple``.146rr	N)rrr��striprs   r#�_strip_surrounding_whitespacer�sh������f�k�*�*��"�"�6�!�9�?�?�#4�f�Q�i�o�o�6G�H�H��!�9�?�?�$�f�Q�i�o�o�&7�8�8�	�s�BBc#�D# �UHnUS[;dMUv� M g7f)u9147Strip any connection headers as per RFC7540 § 8.1.2.2.148rN)rgrs   r#�_strip_connection_headersr�+s#���149���!�9�.�.��L��s� �	 c�v�UR=(d URnU(a	SU5$[U5$)z�150Raises an InvalidHeaderBlockError if we try to send a header block151that does not contain an :authority or a Host header, or if152the header block contains both fields, but their values do not match.153c3�$# �UHov� M g7fr�r:r�s  r#r��4_check_sent_host_authority_header.<locals>.<genexpr>Dr�r�r�r�s   r#�!_check_sent_host_authority_headerr�5r�r,c#�# �/nUH&nUSS:XaURUS5 M"Uv� M( U(a SRU5n[SU5v� gg7f)u[154RFC 7540 § 8.1.2.5 allows HTTP/2 clients to split the Cookie header field,155which must normally appear only once, into multiple fields for better156compression. However, they MUST be joined back up again when received.157This normalization step applies that transform. The side-effect is that158all cookie fields now appear *last* in the header block.159rrr	�; N)r��joinr)r r!�cookiesr"�160cookie_vals     r#�_combine_cookie_fieldsr�Is\����G����!�9�	�!��N�N�6�!�9�%��L�	�161��Z�Z��(�162�%�i��<�<��s�AAc#�H# �UH�n[US[5(de[US[5(deUSS:XaTUSRS5H:n[U[5(aUR	USU5v� M1USU4v� M< M�Uv� M� g7f)u�163RFC 7540 § 8.1.2.5 allows for better compression efficiency,164to split the Cookie header field into separate header fields165 166We want to do it for outbound requests, as we are doing for167inbound.168rr	rr�N)rr�splitrr�)r r!r"r�s    r#�_split_outbound_cookie_fieldsr�`s�������&��)�U�+�+�+�+��&��)�U�+�+�+�+��!�9�	�!�$�Q�i�o�o�e�4�169��f�k�2�2� �*�*�6�!�9�j�A�A� ��)�Z�/�/�	5��L��s�B B"c�~�[X5nU(a[X5n[X5n[X5n[	X5$)z�170Normalizes a header sequence that we are about to send.171 172:param headers: The HTTP header set.173:param hdr_validation_flags: An instance of HeaderValidationFlags.174:param should_split_outbound_cookies: boolean flag175)r�r�r�r�r$)r r!�should_split_outbound_cookiess   r#�normalize_outbound_headersr�vs:��&�g�D�G�$�/��N��+�G�J�G�'��F�G��7�9�9r,c��[X5$)z�176Normalizes a header sequence that we have received.177 178:param headers: The HTTP header set.179:param hdr_validation_flags: An instance of HeaderValidationFlags180)r�rRs  r#�normalize_inbound_headersr��s��"�'�@�@r,c�p�[X5n[X5n[X5n[X5n[	X5$)z�181Validates and normalizes a header sequence that we are about to send.182 183:param headers: The HTTP header set.184:param hdr_validation_flags: An instance of HeaderValidationFlags.185)rMrNrOr�rQrRs  r#�validate_outbound_headersr��sK�����G�(���G�+���G�0���G��g�<�<r,c�F^�\rSrSrSU4SjjrSU4SjjrSSjrSrU=r$)	�
SizeLimitDicti�c�t>�URSS5Ul[TU]"U0UD6 UR	5 g)N�186size_limit)�pop�_size_limit�super�__init__�_check_size_limit)�self�args�kwargsr�s   �r#r��SizeLimitDict.__init__�s4���!�:�:�l�D�9���
���$�)�&�)���� r,c�D>�[TU]X5 UR5 gr�)r��__setitem__r�)r��key�valuer�s   �r#r��SizeLimitDict.__setitem__�s���
���C�'���� r,c��URbE[U5UR:�a+URSS9 [U5UR:�aM*ggg)NF)�last)r�r�popitem)r�s r#r��SizeLimitDict._check_size_limit�sG�����'��d�)�d�.�.�.����%��(��d�)�d�.�.�.�(r,)r�)r�zdict[int, int]r�rr��None)r��intr�z	Any | intr�r�)r�r�)	rDrErFrGr�r�r�rI�
__classcell__)r�s@r#r�r��s���!�!�187)�)r,r�)r �Iterable[Header]r!�HeaderValidationFlags | Noner�r�)r r�r��bytes | None)r r�r�r?)r3r�r4r�r�r�)r r�r!r=r�r�)r r�r!r=r�r�)rjrrk�(set[bytes | str] | set[bytes] | set[str]r�r�)rzr�rur�r!r=r�r�)r r�r�r�)r*zbytes | strr�r)r zIterable[HeaderWeaklyTyped]r�zlist[Header])F)r r�r!r�r�r?r�r�)<�__doc__�188__future__r�collections�typingrrr�hpack.structrr�189exceptionsr190r�collections.abcrr
rr�ordro�INFORMATIONAL_START�	frozensetrgrqrrwrxryr$r+r1r8r;r=rSrKrLrMrNrlrOrrr�rPrQr�r�r�r�r�r�r�r�r�r�r��OrderedDictr�r�r:r,r#�<module>r�sr���#��1�1�=�7��3�6��D�	���$�i��191� ���!*�+�!��������"�#���#�J�<�0��192!*�<�.� 9���*F��Kh��6	��,�,�,�J��"=�J.�5J�.�Ol�.�b�5J��Ol��193�194�	!�&N�	!�SW�	!�(�7L�(�Qn�(�V')�5A�')�CX�')�]a�')�T-!�`4�7L�4�Qn�4�(�-B��Gd��4<��"1�2N�1�Sp�1�9�8T�9�Yv�9��4P��Ur��4�<Q�4�Vs�4�(=�.�8T��Yv��0DI�:�5Q�:�>B�:�Mj�:�&A�4I�A�Nk�A�=�4I�=�Nk�=�0)�K�+�+�C��H�5�)r,