Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
payload.cpython-313.pyc537 linesDownload Raw Back to __pycache__
1�

2��j3��	�b�%SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	J4r5 SSKJr SSK
Jr SSKJrJrJrJrJrJrJrJrJrJrJrJr SSKJr SSKJr SS	KJ r  SS6K!J"r"J#r#J$r$J%r%J&r& SSK'J(r( SSK)J*r*J+r+ S
r,Sr-\\.\/S'Sr0\\.\/S'\1"5r2\\RfS\/S'"SS\45r5"SS\6\Rn5r8S\S\S\SS4Sjr9\8RtS.S\SS\S \8SS4S!jjr;"S"S#5r<\Sr=\\=\4r>"S$S%5r?"S&S\	5r@"S'S(\@5rA"S)S*\A5rB"S+S,\B5rC"S-S.\@5rD"S/S0\D5rE"S1S2\D5rF"S3S4\D5rG"S5S6\A5rH\(aSS7KJIrIJJrJ \J\KrL\I\KrMOSS7KJIrIJJrJ \JrL\IrM"S8S9\@5rN"S:S;\N5rO\?"5rP\PR�\A\K\R\S45 \PR�\B\65 \PR�\C\R�5 \PR�\E\R�5 \PR�\F\R�5 \PR�\G\R�\R�45 \PR�\D\R�5 \PR�\O\(5 \PR�\N\I\8R�S9 g)<�N)�ABC�abstractmethod)�Iterable)�chain)�IO�
TYPE_CHECKING�Any�Dict�Final�List�Optional�Set�TextIO�Tuple�Type�Union)�CIMultiDict�)�hdrs)�AbstractStreamWriter)�	_SENTINEL�content_disposition_header�guess_filename�parse_mimetype�sentinel)�StreamReader)�JSONEncoder�_CIMultiDict)
�PAYLOAD_REGISTRY�get_payload�payload_type�Payload�BytesPayload�
StringPayload�
IOBasePayload�BytesIOPayload�BufferedReaderPayload�
TextIOPayload�StringIOPayload�JsonPayload�AsyncIterablePayloadi�TOO_LARGE_BYTES_BODYi�	READ_SIZE�_CLOSE_FUTURESc��\rSrSrSrSrg)�LookupError�>z@Raised when no payload factory is found for the given data type.�N)�__name__�7__module__�__qualname__�__firstlineno__�__doc__�__static_attributes__r2��UD:\code\apps\devtools\python\user_packages\Python313\site-packages\aiohttp/payload.pyr0r0>s��Jr9r0c� �\rSrSrSrSrSrSrg)�Order�B�normal�	try_first�try_lastr2N)r3r4r5r6r>r?r@r8r2r9r:r<r<Bs��
�F��I��Hr9r<�data�args�kwargs�returnr"c�6�[R"U/UQ70UD6$�N)r�get)rArBrCs   r:r r Hs������6�t�6�v�6�6r9��order�factory�typerIc�,�[RXUS9 g�NrH)r�register)rJrKrIs   r:�register_payloadrOLs�����g�5��9r9c�d�\rSrSr\R8S.S\S\SS4SjjrS\S	S\S	4S9jr	Sr10g)r!�RrHrKrIrDNc��XlX lgrF)rKrI)�selfrKrIs   r:�__init__�payload_type.__init__Ss���	��11r9rJr"c�B�[XRURS9 U$rM)rOrKrI)rSrJs  r:�__call__�payload_type.__call__Ws����)�)�4�:�:�>��r9)rIrK)r3r4r5r6r<r>r	rTrrWr8r2r9r:r!r!Rs>��49�L�L��S��E��T����Y���D��O�r9r!c��\rSrSrSrSrSSjr\S.S\S	\S12SS\SS
413Sjjr	\14RS.S\S\S\15SS4Sjjr
Srg)�PayloadRegistry�`zRPayload registry.16 17note: we need zope.interface for more efficient adapter search18��_first�_normal�_last�_normal_lookuprDNc�<�/Ul/Ul/Ul0UlgrFr\�rSs r:rT�PayloadRegistry.__init__hs��24���35���13��19�68��r9)�_CHAINrArBrdz!Type[chain[_PayloadRegistryItem]]rCr"c���UR(a3URH#upV[X5(dMU"U/UQ70UD6s $ URR[	U55=n(aU"U/UQ70UD6$[U[205(aU$U"URUR5H#upV[X5(dMU"U/UQ70UD6s $ [5erF)	r]�21isinstancer`rGrKr"r^r_r0)rSrArdrBrCrJ�type_�lookup_factorys        r:rG�PayloadRegistry.getns����;�;�"&�+�+����d�*�*�"�4�9�$�9�&�9�9�#.�"�0�0�4�4�T�$�Z�@�@�>�@�!�$�8��8��8�8��d�G�$�$��K�$�T�\�\�4�:�:�>�N�G��$�&�&��t�5�d�5�f�5�5�?��m�r9rHrJrKrIc��U[RLaURRX45 gU[RLaXUR22RX45 [
U[5(aUHnXRU'M gXRU'gU[RLaURRX45 g[SU<35e)NzUnsupported order )r<r?r]�appendr>r^rfrr`r@r_�23ValueError)rSrJrKrI�ts     r:rN�PayloadRegistry.register�s����E�O�O�#��K�K�����/�
�e�l�l�
"��L�L�����0��$��)�)��A�-4�'�'��*��-4�#�#�D�)�
�e�n�n�
$��J�J���w�o�.��1�%��;�<�<r9)r]r_r^r`�rDN)r3r4r5r6r7�	__slots__rTrr	rGr<r>�PayloadTyperNr8r2r9r:rZrZ`s����24A�I�9�7<�	�����4�	�25��26�
�0BG���=�"�=�*-�=�9>�=�	
�=�=r9rZc�L�\rSrSr%Sr\\S'Sr\\	\S'Sr27\\S'Sr\\S'S\
SS4S	\S28\\\\\\4\\\\44S\\S\4S\\S
\\S\SS4Sjjr\S\\	4Sj5r\S\\4Sj5r\S\4Sj5r\S\4Sj5r\S\\4Sj5r\S\4Sj5r\S\4Sj5r\S\4Sj5rS(S\S\S\S\SS429Sjjr \!S)S
\S\S\4Sjj5r"\!S \#SS4S!j5r$S \#S"\\	SS4S#jr%S)S
\S\S\4S$jjr&S*S%jr'S*S&jr(S'r)g)+r"��application/octet-stream�_default_content_typeN�_sizeF�	_consumed�30_autoclose�value�headers�content_type�filename�encodingrCrDc�2�XPlX@l[5UlXlU[31La UbX0R[R'O�URbv[RS:�a[RnO[RnU"UR5SnUcURnX0R[R'O'URUR[R'U(aURRU5 gg)N)��
r)�	_encoding�	_filenamer�_headers�_valuerr�CONTENT_TYPE�sys�version_info�	mimetypes�guess_file_type�32guess_typeru�update)rSryrzr{r|r}rC�guessers        r:rT�Payload.__init__�s���"��!��&1�m��
����x�'�L�,D�/;�M�M�$�+�+�,�
�^�^�
'����7�*�#�3�3��#�.�.��"�4�>�>�2�1�5�L��#�#�9�9��/;�M�M�$�+�+�,�/3�/I�/I�D�M�M�$�+�+�,���M�M� � ��)�r9c��UR$)z�Size of the payload in bytes.33 34Returns the number of bytes that will be transmitted when the payload35is written. For string payloads, this is the size after encoding to bytes,36not the length of the string.37�rvrbs r:�size�Payload.size�s���z�z�r9c��UR$)zFilename of the payload.)r�rbs r:r|�Payload.filename�����~�~�r9c��UR$)zCustom item headers)r�rbs r:rz�Payload.headers�s���}�}�r9c���SRURR5VVs/sHupUS-U-S-PM snn5RS5S-$s snnf)N�z: z
38�utf-8s
39)�joinrz�items�encode)rS�k�vs   r:�_binary_headers�Payload._binary_headers�s]��
�G�G�t�|�|�7I�7I�7K�L�7K�t�q�Q��X��\�F�*�7K�L�M�T�T��
��
�	40��Ls�A41c��UR$)zPayload encoding)r�rbs r:r}�Payload.encoding�r�r9c�<�UR[R$)zContent type)r�rr�rbs r:r{�Payload.content_type�s���}�}�T�.�.�/�/r9c��UR$)z;Whether the payload has been consumed and cannot be reused.)rwrbs r:�consumed�Payload.consumed�r�r9c��UR$)z�42Whether the payload can close itself automatically.43 44Returns True if the payload has no file handles or resources that need45explicit closing. If False, callers must await close() to release resources.46)rxrbs r:�	autoclose�Payload.autoclose�s�����r9�disptype�quote_fields�_charset�paramsc�V�[U4X#S.UD6UR[R'g)z$Sets ``Content-Disposition`` header.)r�r�N)rr�r�CONTENT_DISPOSITION)rSr�r�r�r�s     r:�set_content_disposition�Payload.set_content_disposition�s1��3M��347�#/�348�FL�349��
�
�d�.�.�/r9�errorsc��g)zo50Return string representation of the value.51 52This is named decode() to allow compatibility with bytes objects.53Nr2�rSr}r�s   r:�decode�Payload.decode���r9�writerc��# �g7f)aX54Write payload to the writer stream.55 56Args:57    writer: An AbstractStreamWriter instance that handles the actual writing58 59This is a legacy method that writes the entire payload without length constraints.60 61Important:62    For new implementations, use write_with_length() instead of this method.63    This method is maintained for backwards compatibility and will eventually64    delegate to write_with_length(writer, None) in all implementations.65 66All payload subclasses must override this method for backwards compatibility,67but new code should use write_with_length for more flexibility and control.68 69Nr2�rSr�s  r:�write�
Payload.write�������content_lengthc��B# �URU5IShv�N gN7f)a`70Write payload with a specific content length constraint.71 72Args:73    writer: An AbstractStreamWriter instance that handles the actual writing74    content_length: Maximum number of bytes to write (None for unlimited)75 76This method allows writing payload content with a specific length constraint,77which is particularly useful for HTTP responses with Content-Length header.78 79Note:80    This is the base implementation that provides backwards compatibility81    for subclasses that don't override this method. Specific payload types82    should override this method to implement proper length-constrained writing.83 84N)r��rSr�r�s   r:�write_with_length�Payload.write_with_lengths���*�j�j�� � � �s���c��t# �UR=(d UnURX25RU5$7f)z�85Return bytes representation of the value.86 87This is a convenience method that calls decode() and encodes the result88to bytes using the specified encoding.89)r�r�r�)rSr}r��actual_encodings    r:�as_bytes�Payload.as_bytes4s/����.�.�4�H���{�{�?�3�:�:�?�K�K�s�68c��g)a=90Async safe synchronous close operations for backwards compatibility.91 92This method exists only for backwards compatibility with code that93needs to clean up payloads synchronously. In the future, we will94drop this method and only support the async close() method.95 96WARNING: This method must be safe to call from within the event loop97without blocking. Subclasses should not perform any blocking I/O here.98 99WARNING: This method must be called from within an event loop for100certain payload types (e.g., IOBasePayload). Calling it outside an101event loop may raise RuntimeError.102Nr2rbs r:�_close�Payload._close?r�r9c��,# �UR5 g7f)a,103Close the payload if it holds any resources.104 105IMPORTANT: This method must not await anything that might not finish106immediately, as it may be called during cleanup/cancellation. Schedule107any long-running operations without awaiting them.108 109In the future, this will be the only close method supported.110N�r�rbs r:�close�
Payload.closeQs���	
���
���)r�r�r�r�)Tr��r��strictro)*r3r4r5r6ru�str�__annotations__rvr
�intrw�boolrxrr	rrr111rrrrT�propertyr�r|rz�bytesr�r}r{r�r�r�rr�rr�r�r�r�r�r8r2r9r:r"r"�sz��!;��3�;��E�8�C�=���I�t���J���
�4<�"&�"&�*��*���,��S�#�X����s�C�x��0I�I�J�112�*��C��y�0�1�
*��3�-�*��3�-�*��*�113�*�>��h�s�m������(�3�-�����������114��115��116���(�3�-�����0�c�0��0���$������4����"��	117118��119120��121122��	123124�125�126127�128�
129130���s��c��������"6��4����*!�*�!�<D�S�M�!�	
�!�.	L�s�	L�c�	L�QV�	L��$131r9c�^�\rSrSr%\\S'SrS\\\\	4S\132S\133SS4U4S	jjrSS134\S\S\4Sjjr
SS135\S\S\4S
jjrS\SS4SjrS\S\\SS4SjrSrU=r$)r#i^r�TryrBrCrDNc�>�SU;aSUS'[TU]"U/UQ70UD6 [U[5(aURUlOD[U[[45(a[U5UlO[S[U5<35eUR136[:�a!SU0n[R"S[40UD6 gg)Nr{rtz%value argument must be byte-ish, not �sourcez}Sending a large body directly with raw bytes might lock the event loop. You should probably pass an io.BytesIO object instead)�superrTrf�137memoryview�nbytesrvr��	bytearray�len�	TypeErrorrKr,�warnings�warn�ResourceWarning�rSryrBrC�	__class__s    �r:rT�BytesPayload.__init__cs������'�%?�F�>�"�
����0��0��0��e�Z�(�(����D�J�
���y�1�
2�
2��U��D�J��C�D��K�?�S�T�T��:�:�,�,���%�F��M�M�,� �	
�138�
�-r9r}r�c�8�URRX5$rF)r�r�r�s   r:r��BytesPayload.decode|s���{�{�!�!�(�3�3r9c��"# �UR$7f)z�139Return bytes representation of the value.140 141This method returns the raw bytes content of the payload.142It is equivalent to accessing the _value attribute directly.143)r�r�s   r:r��BytesPayload.as_bytess����{�{��s�
r�c��V# �URUR5IShv�N gN7f)a�144Write the entire bytes payload to the writer stream.145 146Args:147    writer: An AbstractStreamWriter instance that handles the actual writing148 149This method writes the entire bytes content without any length constraint.150 151Note:152    For new implementations that need length control, use write_with_length().153    This method is maintained for backwards compatibility and is equivalent154    to write_with_length(writer, None).155 156N�r�r�r�s  r:r��BytesPayload.write�s����l�l�4�;�;�'�'�'�s�)�'�)r�c��# �Ub'URURSU5IShv�N gURUR5IShv�N gN)N7f)a�157Write bytes payload with a specific content length constraint.158 159Args:160    writer: An AbstractStreamWriter instance that handles the actual writing161    content_length: Maximum number of bytes to write (None for unlimited)162 163This method writes either the entire byte sequence or a slice of it164up to the specified content_length. For BytesPayload, this operation165is performed efficiently using array slicing.166 167Nr�r�s   r:r��BytesPayload.write_with_length�sH����%��,�,�t�{�{�?�N�;�<�<�<��,�,�t�{�{�+�+�+�
=�+�s!�%A�A�#A�A�A�Ar�r�)r3r4r5r6r�r�rxrr�r�r	rTr�r�r�rr�r
r�r�r8�
__classcell__�r�s@r:r#r#^s�����M��J���5�)�Z�7�8��AD��PS��	
��24�s�4�c�4��4��s��c��QV��(�"6�(�4�(�",�*�,�<D�S�M�,�	
�,�,r9r#c
�Z^�\rSrSrSSS.S\S\S\\S\\S\S	S4U4S168jjjrSrU=r	$)r$i�N�r}r{ryrBr}r{rCrDc��>�Uc0UcSnSnO2[U5nURRSS5nO169UcSU-nUn[TU]"URU5/UQ7UUS.UD6 g)Nr��text/plain; charset=utf-8�charset�text/plain; charset=%sr�)r�170parametersrGr�rTr�)	rSryr}r{rBrC�
real_encoding�mimetyper�s	        �r:rT�StringPayload.__init__�s�������#� '�
�:��)�,�7�� (� 3� 3� 7� 7�	�7� K�
��#�7�(�B��$�M�
����L�L��'�	171��		172�"�%�	173�174�	175r9r2)176r3r4r5r6r�r	r
rTr8r�r�s@r:r$r$�sW���177#'�&*�178��179��180��3�-�	181�182�s�m�183��
184�185�186�187r9r$c�B^�\rSrSrS\\S\S\SS4U4SjjrSrU=r	$)	r)i�ryrBrCrDNc�J>�[TU]"UR5/UQ70UD6 grF)r�rT�readr�s    �r:rT�StringIOPayload.__init__�s ���
�������7��7��7r9r2)188r3r4r5r6rr�r	rTr8r�r�s@r:r)r)�s-���8�b��g�8�c�8�S�8�T�8�8r9r)c�^�\rSrSr%\R189\S'Sr\\	\S'SS\190\S\S\S\S	S4191U4S192jjjr
S SjrS\\	S	\\\	\44S
jrS\\	S	\4Sjr\S	\\	4Sj5rS\S	S4SjrS\S\\	S	S4SjrS\\	S\	S\\	S	\4SjrS SjrS SjrS!S\S\S	\4SjjrS	\4SjrS!S\S\S	\4SjjrSrU=r $)"r%i�r�N�_start_positionry�dispositionrBrCrDc��>�SU;a[U5US'[TU]"U/UQ70UD6 URb=Ub9[R193UR;aURX RS9 gggg)Nr|)r|)rr�rTr�rr�rzr�)rSryrrBrCr�s     �r:rT�IOBasePayload.__init__�sw����V�#�!/��!6�F�:��
����0��0��0��>�>�%�+�*A��'�'�t�|�|�;��,�,�[�>�>�,�R�<�+B�%r9c� �URc!URR5UlgURR
UR5 g![[4a194 SUlgf=f![[4a195 SUlgf=f)z:Set or restore the start position of the file-like object.NT)rr��tell�OSError�AttributeErrorrw�seekrbs r:�_set_or_restore_start_position�,IOBasePayload._set_or_restore_start_position�s������'�
&�'+�{�{�'7�'7�'9��$�
�	"��K�K���T�1�1�2��	�^�,�
&�!%����
&��196��(�	"�!�D�N�	"�s"�A�%A3�A0�/A0�3B
�B
�remaining_content_lenc	���UR5 URnX RR[	[197U=(d [198U=(d [199554$)a|200Read the file-like object and return both its total size and the first chunk.201 202Args:203    remaining_content_len: Optional limit on how many bytes to read in this operation.204        If None, READ_SIZE will be used as the default chunk size.205 206Returns:207    A tuple containing:208    - The total size of the remaining unread content (None if size cannot be determined)209    - The first chunk of bytes read from the file object210 211This method is optimized to perform both size calculation and initial read212in a single operation, which is executed in a single executor job to minimize213context switches and file operations when streaming content.214 215)rr�r�r��minr-)rSr
r�s   r:�_read_and_available_len�%IOBasePayload._read_and_available_len�sL��(	
�+�+�-��y�y���[�[�%�%��	�4�,�9�.C�.P�y�Q�216�217�	218r9c�R�URRU=(d [5$)a�219Read a chunk of data from the file-like object.220 221Args:222    remaining_content_len: Optional maximum number of bytes to read.223        If None, READ_SIZE will be used as the default chunk size.224 225Returns:226    A chunk of bytes read from the file object, respecting the227    remaining_content_len limit if specified.228 229This method is used for subsequent reads during streaming after230the initial _read_and_available_len call has been made.231 232)r�r�r-)rSr
s  r:�_read�IOBasePayload._reads�� �{�{��� 5� B��C�Cr9c��URcURR5Ul[R"URR55RUR-233$![[4a gf=f)a4234Size of the payload in bytes.235 236Returns the total size of the payload content from the initial position.237This ensures consistent Content-Length for requests, including 307/308 redirects238where the same payload instance is reused.239 240Returns None if the size cannot be determined (e.g., for unseekable streams).241N)	rr�r�os�fstat�fileno�st_sizer	rrbs r:r��IOBasePayload.sizesp��	��#�#�+�'+�{�{�'7�'7�'9��$��8�8�D�K�K�.�.�0�1�9�9�D�<P�<P�P�P����(�	��	�s�A0A3�3B�Br�c��D# �URUS5IShv�N gN7f)a�242Write the entire file-like payload to the writer stream.243 244Args:245    writer: An AbstractStreamWriter instance that handles the actual writing246 247This method writes the entire file content without any length constraint.248It delegates to write_with_length() with no length limit for implementation249consistency.250 251Note:252    For new implementations that need length control, use write_with_length() directly.253    This method is maintained for backwards compatibility with existing code.254 255N�r�r�s  r:r��IOBasePayload.write:s��� �$�$�V�T�2�2�2��� �� r�c���# �[R"5nSnUnURSURU5IShv�NupgU(a�[	U5nUcURU5IShv�N O URUSU5IShv�N XX-nXH-
nUR
XdU5(agURSURUb[[U5O[5IShv�NnU(aM�ggN�N�NoN7f)a:256Write file-like payload with a specific content length constraint.257 258Args:259    writer: An AbstractStreamWriter instance that handles the actual writing260    content_length: Maximum number of bytes to write (None for unlimited)261 262This method implements optimized streaming of file content with length constraints:263 2641. File reading is performed in a thread pool to avoid blocking the event loop2652. Content is read and written in chunks to maintain memory efficiency2663. Writing stops when either:267   - All available file content has been written (when size is known)268   - The specified content_length has been reached2694. File resources are properly closed even if the operation is cancelled270 271The implementation carefully handles both known-size and unknown-size payloads,272as well as constrained and unconstrained content lengths.273 274rN)275�asyncio�get_running_loop�run_in_executorrr�r��_should_stop_writingrrr-)	rSr�r��loop�total_written_lenr
�
available_len�chunk�	chunk_lens	         r:r��IOBasePayload.write_with_lengthLs���.�'�'�)���� .��&*�%9�%9��$�.�.�0E�&276� 277��
���E�278�I�%�,��l�l�5�)�)�)��l�l�5�)?�*?�#@�A�A�A�%�2�%��*���(�(��2G�����.�.���279�280�-�8��	�#8�9�"�
��E�'�e�	 281�*�A��sL�:C=�C5�/C=�,C7�-C=�	C9�282AC=�%C;�&C=�3C=�7C=�9C=�;C=r&r%c�N�USL=(a X!:�=(d USL=(a US:*$)a�283Determine if we should stop writing data.284 285Args:286    available_len: Known size of the payload if available (None if unknown)287    total_written_len: Number of bytes already written288    remaining_content_len: Remaining bytes to be written for content-length limited responses289 290Returns:291    True if we should stop writing data, based on either:292    - Having written all available data (when size is known)293    - Having written all requested content (when content-length is specified)294 295Nrr2)rSr&r%r
s    r:r#�"IOBasePayload._should_stop_writing�s2��(�T�)�P�.?�.P�296�!��-�L�2G�1�2L�	297r9c��UR(agSUl[R"5nURSURR2985n[RU5 UR[R5 g)a299Async safe synchronous close operations for backwards compatibility.300 301This method exists only for backwards302compatibility. Use the async close() method instead.303 304WARNING: This method MUST be called from within an event loop.305Calling it outside an event loop will raise RuntimeError.306NT)307rwr r!r"r�r�r.�add�add_done_callback�remove)rSr$�close_futures   r:r��IOBasePayload._close�sc���>�>������'�'�)���+�+�D�$�+�+�2C�2C�D��	���<�(��&�&�~�'<�'<�=r9c��,# �UR5 g7f)z�308Close the payload if it holds any resources.309 310IMPORTANT: This method must not await anything that might not finish311immediately, as it may be called during cleanup/cancellation. Schedule312any long-running operations without awaiting them.313Nr�rbs r:r��IOBasePayload.close�s���	
���
�r�r}r�c�@�UR5RX5$�z�314Return string representation of the value.315 316WARNING: This method does blocking I/O and should not be called in the event loop.317)�	_read_allr�r�s   r:r��IOBasePayload.decode�s���~�~��&�&�x�8�8r9c�t�UR5 SRURR55$)zARead the entire file-like object and return its content as bytes.r9)rr�r��	readlinesrbs r:r6�IOBasePayload._read_all�s*���+�+�-��x�x����-�-�/�0�0r9c��# �[R"5nURSUR5IShv�N$N7f)z�318Return bytes representation of the value.319 320This method reads the entire file content and returns it as bytes.321It is equivalent to reading the file-like object directly.322The file reading is performed in an executor to avoid blocking the event loop.323N)r r!r"r6)rSr}r�r$s    r:r��IOBasePayload.as_bytes�s2����'�'�)���)�)�$����?�?�?�?�s�5>�<�>)rwr)�324attachmentror�)!r3r4r5r6�io�IOBaser�rr
r�rr	r�rTrrr�rrr�r�rr�r�r�r#r�r�r�r6r�r8r�r�s@r:r%r%�s�����I�I��%)�O�X�c�]�)�2>�325S���W�326S�+.�327S�FI�328S�UX�329S�	
�330S�331S�"�332�%-�c�]�333�	�x��}�e�#�	$�334�4D�8�C�=�D�U�D�$��h�s�m����63�"6�3�4�3�$;�*�;�<D�S�M�;�	
�;�z335���}�336��337� (��}�	338�339340�341�0>�,�9�s�9�c�9��9�1�5�1�	@�s�	@�c�	@�QV�	@�	@r9r%c
��^�\rSrSr%\R342\S'SSS.S\S\S\	\343S\	\344S	\S345S4U4SjjjrS\	\S346\
\	\\44S
jrS\	\S347\4SjrSS\348S\349S350\3514SjjrSS\352S\353S354\4SjjrSrU=r$)r(i�r�Nr�ryrBr}r{rCrDc�>�Uc0UcSnSnO0[U5nURRSS5nOUcSU-n[TU]"U/UQ7UUS.UD6 g)Nr�r�r�r��r{r})rr�rGr�rT)rSryr}r{rBrCr�r�s       �r:rT�TextIOPayload.__init__�s|������#�"��:��)�,�7��#�.�.�2�2�9�g�F���#�7�(�B��
����	355��		356�%��	357�358�	359r9r
c�>�UR5 URnURR[	[360U=(d [361U=(d [36255nX R(aURUR54$UR54$)aE363Read the text file-like object and return both its total size and the first chunk.364 365Args:366    remaining_content_len: Optional limit on how many bytes to read in this operation.367        If None, READ_SIZE will be used as the default chunk size.368 369Returns:370    A tuple containing:371    - The total size of the remaining unread content (None if size cannot be determined)372    - The first chunk of bytes read from the file object, encoded using the payload's encoding373 374This method is optimized to perform both size calculation and initial read375in a single operation, which is executed in a single executor job to minimize376context switches and file operations when streaming content.377 378Note:379    TextIOPayload handles encoding of the text content before writing it380    to the stream. If no encoding is specified, UTF-8 is used as the default.381 382)rr�r�r�rr-r�r�)rSr
r�r's    r:r�%TextIOPayload._read_and_available_len�sp��0	
�+�+�-��y�y����� � ��	�4�,�9�.C�.P�y�Q�383���^�^�U�\�\�$�.�.�1�W�W�����W�Wr9c���URRU=(d [5nUR(aUR	UR5$UR	5$)ad384Read a chunk of data from the text file-like object.385 386Args:387    remaining_content_len: Optional maximum number of bytes to read.388        If None, READ_SIZE will be used as the default chunk size.389 390Returns:391    A chunk of bytes read from the file object and encoded using the payload's392    encoding. The data is automatically converted from text to bytes.393 394This method is used for subsequent reads during streaming after395the initial _read_and_available_len call has been made. It properly396handles text encoding, converting the text content to bytes using397the specified encoding (or UTF-8 if none was provided).398 399)r�r�r-r�r�)rSr
r's   r:r�TextIOPayload._readsB��$��� � �!6�!C�)�D��/3�~�~�u�|�|�D�N�N�+�Q�5�<�<�>�Qr9r�c�V�UR5 URR5$r5�rr�r�r�s   r:r��TextIOPayload.decode/s#��	
�+�+�-��{�{���!�!r9c��^^^# �[R"5nTR=(d UmS[4UUU4SjjnUR	SU5IShv�N$N7f)z�400Return bytes representation of the value.401 402This method reads the entire text file content and returns it as bytes.403It encodes the text content using the specified encoding.404The file reading is performed in an executor to avoid blocking the event loop.405rDc�x>�TR5 TRR5RTT5$rF)rr�r�r�)r�r�rSs���r:�_read_and_encode�0TextIOPayload.as_bytes.<locals>._read_and_encodeEs/����/�/�1��;�;�#�#�%�,�,�_�f�E�Er9N)r r!r�r�r")rSr}r�r$rMr�s` `  @r:r��TextIOPayload.as_bytes8sV�����'�'�)���.�.�4�H��	F�%�	F�	F�406�)�)�$�0@�A�A�A�A�s�AA�A�Ar2r�)r3r4r5r6r>�407TextIOBaser�rr	r
r�rTr�rr�rrr�r�r8r�r�s@r:r(r(�s�����M�M��#'�&*�408��409��410��3�-�	411�412�s�m�413��
414�415�416�417�8X�%-�c�]�X�	�x��}�e�#�	$�X�>R�8�C�=�R�U�R�*"�s�"�c�"��"�B�s�B�c�B�QV�B�Br9r(c�^�\rSrSr%\R418\S'\\S'SrS\R419S\	S\	SS	4U4S420jjr421\S\4Sj5rSS\
S
\
S\
4SjjrS\SS	4SjrS\S\\SS	4SjrSS\
S
\
S\4SjjrSSjrSrU=r$)r&iMr�rvTryrBrCrDNc�>�[TU]"U/UQ70UD6 [URR	55URR5-422UlgrF)r�rTr�r��	getbufferrrvr�s    �r:rT�BytesIOPayload.__init__RsE���
����0��0��0�����.�.�0�1�D�K�K�4D�4D�4F�F��423r9c��UR$)z�Size of the payload in bytes.424 425Returns the number of bytes in the BytesIO buffer that will be transmitted.426This is calculated once during initialization for efficiency.427r�rbs r:r��BytesIOPayload.sizeWs���z�z�r9r}r�c�t�UR5 URR5RX5$rF�rr�r�r�r�s   r:r��BytesIOPayload.decode`�,���+�+�-��{�{���!�(�(��:�:r9r�c��B# �URUS5IShv�N$N7frFrr�s  r:r��BytesIOPayload.writeds����+�+�F�D�9�9�9�9�s���r�c���# �UR5 SnUnURR[5=n(a�US:�a[R428"S5IShv�N UcUR
U5IShv�N O1UR
USU5IShv�N U[U5-nUS::agUS-
nURR[5=n(aM�ggN�NgNL7f)a�429Write BytesIO payload with a specific content length constraint.430 431Args:432    writer: An AbstractStreamWriter instance that handles the actual writing433    content_length: Maximum number of bytes to write (None for unlimited)434 435This implementation is specifically optimized for BytesIO objects:436 4371. Reads content in chunks to maintain memory efficiency4382. Yields control back to the event loop periodically to prevent blocking439   when dealing with large BytesIO objects4403. Respects content_length constraints when specified4414. Properly cleans up by closing the BytesIO object when done or on error442 443The periodic yielding to the event loop is important for maintaining444responsiveness when processing large in-memory buffers.445 446rNr)rr�r�r-r �sleepr�r�)rSr�r��447loop_count�remaining_bytesr's      r:r�� BytesIOPayload.write_with_lengthgs����,	
�+�+�-��448�(���{�{�'�'�	�2�2�e�2��A�~�449�m�m�A�&�&�&��&��l�l�5�)�)�)��l�l�5�)9�/�#:�;�;�;��3�u�:�-��"�a�'���!�O�J��{�{�'�'�	�2�2�e�2�2�'�)�;�s=�AC$�C�C$�8C �9C$�C"�AC$�C$� C$�"C$c��^# �UR5 URR5$7f)z�450Return bytes representation of the value.451 452This method reads the entire BytesIO content and returns it as bytes.453It is equivalent to accessing the _value attribute directly.454rIr�s   r:r��BytesIOPayload.as_bytes�s&���	
�+�+�-��{�{���!�!�s�+-c��# �g7f)zq455Close the BytesIO payload.456 457This does nothing since BytesIO is in-memory and does not require explicit closing.458Nr2rbs r:r��BytesIOPayload.close�r�r�r�r�ro)r3r4r5r6r>�BytesIOr�r�rxr	rTr�r�r�r�rr�r
r�r�r�r�r8r�r�s@r:r&r&Ms�����J�J���J��J�G�b�j�j�G��G��G��G�459��c����;�s�;�c�;��;�:�"6�:�4�:�'�*�'�<D�S�M�'�	
�'�R"�s�"�c�"�QV�"��r9r&c�N�\rSrSr%\R460\S'S	S\S\S\4SjjrSr	g)461r'i�r�r}r�rDc�t�UR5 URR5RX5$rFrXr�s   r:r��BufferedReaderPayload.decode�rZr9r2Nr�)462r3r4r5r6r>�BufferedIOBaser�r�r�r8r2r9r:r'r'�s-������;�s�;�c�;��;�;r9r'c�f^�\rSrSrSS\R4634S\S\S\S\S\S	\S464S4U4Sjjjr	S
r465U=r$)r*i�r�zapplication/jsonryr}r{�dumpsrBrCrDNc�^>�[TU]"U"U5RU5/UQ7UUS.UD6 g)NrB)r�rTr�)rSryr}r{rlrBrCr�s       �r:rT�JsonPayload.__init__�sC���	����%�L����)�	466��		467�%��	468�469�	470r9r2)r3r4r5r6�jsonrlr	r�rrTr8r�r�s@r:r*r*�s`��� �.�!�Z�Z�471��472��473��	474�475�476��
477��478�479�480�481r9r*)�
AsyncIterable�
AsyncIteratorc��^�\rSrSr%Sr\\\S'\\S'Sr	\\482\\S'SrS\S\
S	\
S483S4U4SjjrS\S484S4S
jrS\S\\S485S4SjrSS\S\S486\4SjjrSS\S\S487\4SjjrSrU=r$)r+i�N�_iterr��_cached_chunksTryrBrCrDc��>�[U[5(d#[SR[	U555eSU;aSUS'[488TU]"U/UQ70UD6 UR5Ulg)NzMvalue argument must support collections.abc.AsyncIterable interface, got {!r}r{rt)	rfrpr��formatrKr�rT�	__aiter__rsr�s    �r:rT�AsyncIterablePayload.__init__�si����%��/�/���!�6�$�u�+�.��
���'�%?�F�>�"�
����0��0��0��_�_�&��489r9r�c��D# �URUS5IShv�N gN7f)a�490Write the entire async iterable payload to the writer stream.491 492Args:493    writer: An AbstractStreamWriter instance that handles the actual writing494 495This method iterates through the async iterable and writes each chunk496to the writer without any length constraint.497 498Note:499    For new implementations that need length control, use write_with_length() directly.500    This method is maintained for backwards compatibility with existing code.501 502Nrr�s  r:r��AsyncIterablePayload.write�s����$�$�V�T�2�2�2�rr�c��# �URbfUnURHSnUcURU5IShv�N M!US:�a,URUSU5IShv�N U[U5-nMS g gURcgUn[R503S:�a[
UR5IShv�NnO"URR5IShv�NnUcURU5IShv�N O0US:�a*URUSU5IShv�N U[U5-nM�N�N�NzNYN?N![a SUlSUl	gf=f7f)a)504Write async iterable payload with a specific content length constraint.505 506Args:507    writer: An AbstractStreamWriter instance that handles the actual writing508    content_length: Maximum number of bytes to write (None for unlimited)509 510This implementation handles streaming of async iterable content with length constraints:511 5121. If cached chunks are available, writes from them5132. Otherwise iterates through the async iterable one chunk at a time5143. Respects content_length constraints when specified5154. Does NOT generate cache - that's done by as_bytes()516 517NrT)r�518)519rtr�r�rsr�r��anext�	__anext__�StopAsyncIterationrw)rSr�r�r`r's     r:r��&AsyncIterablePayload.write_with_length�sQ���&���*�,�O��,�,��"�*� �,�,�u�-�-�-�$�q�(� �,�,�u�-=�o�'>�?�?�?�#�s�5�z�1�O���-�
��:�:���)��	"���#�#�w�.�"'��520�521�"3�3�E�"&�*�*�"6�"6�"8�8�E�"�*� �,�,�u�-�-�-�$�q�(� �,�,�u�-=�o�'>�?�?�?�#�s�5�z�1�O��!.�?� 4�8�-�@��"�	"��D�J�!�D�N�	"�s��6E�D+�#E�D-�)E�-D7�4D/�5"D7�D1�D7�3D3�4"D7�D5�D7�+E�-E�/D7�1D7�3D7�5D7�7E�E�E�Er}r�c��URb*SRUR5RX5$[S5e)zFDecode the payload content as a string if cached chunks are available.r9z=Unable to decode - content not cached. Call as_bytes() first.)rtr�r�r�r�s   r:r��AsyncIterablePayload.decode.s:�����*��8�8�D�/�/�0�7�7��I�I��W�X�Xr9c��# �URbSRUR5$URcg/nURShv�NnURU5 MN522SUlX0lSRU5$7f)z�523Return bytes representation of the value.524 525This method reads the entire async iterable content and returns it as bytes.526It generates and caches the chunks for future reuse.527Nr9)rtr�rsrk)rSr}r��chunksr's     r:r��AsyncIterablePayload.as_bytes4s������*��8�8�D�/�/�0�0��:�:���!���:�:�	!�%��M�M�%� �	!�:���528�$���x�x����s*�AB�A%�A#�A%�B�#A%�%B)rtrwrsr�)r3r4r5r6rsr
�_AsyncIteratorr��_AsyncIterablertrr�rxr	rTrr�r�r�r�r�r�r8r�r�s@r:r+r+�s����&*�E�8�N�#�*���,0�N�H�T�%�[�)�0��J�
'�n�
'�S�
'�C�
'�D�
'�3�"6�3�4�3�"9"�*�9"�<D�S�M�9"�	
�9"�vY�s�Y�c�Y��Y� �s� �c� �QV� � r9r+c�<^�\rSrSrS\S\S\SS4U4SjjrSrU=r$)	�StreamReaderPayloadiPryrBrCrDNc�J>�[TU]"UR5/UQ70UD6 grF)r�rT�iter_anyr�s    �r:rT�StreamReaderPayload.__init__Qs!���
������)�;�D�;�F�;r9r2)	r3r4r5r6rr	rTr8r�r�s@r:r�r�Ps)���<�l�<�3�<�#�<�$�<�<r9r�)[r �enumr>ror�rr�r��abcrr�collections.abcr�	itertoolsr�typingrrr	r529rrr
rrrrr�	multidictrr�rr�helpersrrrrr�streamsr�typedefsrr�__all__r,r�r�r-�setr.�Future�	Exceptionr0r��Enumr<r r>rOr!rq�_PayloadRegistryItemrZr"r#r$r)r%r(r&r'r*rprqr�r�r�r+r�rrNr�r��StringIOrPrf�BufferedReader�BufferedRandomr?r@r2r9r:�<module>r�s�����	���	�530��#�$��
�
�
�
�"��%���"�/��� $)��e�C�j�(��	�5��:��,/�E���G�N�N�4�(�)�1�K�)�K��C�����7�c�7�#�7��7��7�531<A�<�<�:�
�)�_�:�$'�:�38�:�	�:����9�o���[�#�-�.��4=�4=�nD�c�D�NM,�7�M,�`532�L�533�>8�m�8�534F@�G�F@�RoB�M�oB�dR�]�R�j;�M�;�535�,�536�(�3�"�5�)�N�"�5�)�N�<�"�N�"�N�B �7�B �J<�.�<�537#�$�����,��	�:�(F�G����-��-����/�2�;�;�7����-����7����.�"�*�*�5����/�"�2C�2C�R�EV�EV�1W�X����-����3����-�|�<����.�
�U�^�^��Tr9
codekingpro/portable-devtools · Team Ai