HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/aiohttp/__pycache__/multipart.cpython-310.pyc
o

;j���@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
ddlmZddlmZmZmZmZmZddlmZmZmZddlmZmZdd	lmZdd
lm Z m!Z!ddl"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-dd
l.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=ej>dkr�ddlm?Z?neddd�Z?ej>dkr�ddl	m@Z@neeAeBddfZ@ede@d�ZCdZDer�ddlEmFZFGdd�deG�ZHGd d!�d!eG�ZId"eJdBd#eKeJdBeLeJeJfffd$d%�ZM	&d7d'eeJeJfd(eJd#eJdBfd)d*�ZNGd+d,�d,�ZOGd-d�d�ZPe;ePe7jQd.�Gd/d0�d0e8��ZRGd1d2�d2�ZSeKe8eJeJfZTGd3d4�d4e8�ZUGd5d6�d6�ZVdS)8�N)�deque)�
AsyncIterator�Iterator�Mapping�Sequence)�
TracebackType)�
TYPE_CHECKING�Any�TypeVar�Union�cast)�	parse_qsl�unquote�	urlencode)�CIMultiDict�CIMultiDictProxy�)�AbstractStreamWriter)�ZLibCompressor�ZLibDecompressor)�CONTENT_DISPOSITION�CONTENT_ENCODING�CONTENT_LENGTH�CONTENT_TRANSFER_ENCODING�CONTENT_TYPE)�CHAR�DEFAULT_CHUNK_SIZE�TOKEN�parse_mimetype�reify)�
HeadersParser)�BadHttpMessage)�internal_logger)�JsonPayload�LookupError�Order�Payload�
StringPayload�get_payload�payload_type)�StreamReader)��)�Selfr-�BodyPartReader)�bound)r+�)�Bufferzmemoryview[int]zmemoryview[bytes]�_Buffer)�MultipartReader�MultipartWriterr.�BadContentDispositionHeader�BadContentDispositionParam�parse_content_disposition�content_disposition_filename)�ClientResponsec@�eZdZdS)r5N��__name__�
__module__�__qualname__�r?r?�E/opt/saltstack/salt/lib/python3.10/site-packages/aiohttp/multipart.pyr5C�r5c@r:)r6Nr;r?r?r?r@r6GrAr6�header�returncs�dtdtfdd��dtdtfdd�}dtdtf�fdd�}dtdtfd	d
�}dtdtfdd�}d
�ttjt��d�dtdtdtfdd�}|sJdifS|�d�^}}�|�s`t�	t
|��difSi}|�r[|�d�}	|	stt�	t
|��qbd|	vr�t�	t
|��difS|	�dd�\}
}|
���
�}
|��}|
|vr�t�	t
|��difS�|
�s�t�	t|	��qb||
�r�||�r�||dd��}n��|�s�t�	t|	��qbn�||
��r||�r�|�dd�\}}
}|p�d}nt�	t|	��qbzt||d�}Wn_t�yt�	t|	��Yqbwd}||��rd}||dd��d��}n+�|��r$d}n#|�rG|�d|d��}||��rG|�d�||dd��d��}d}|�rUt�	t
|��difS|||
<|se|��|fS)N�stringrCcSst|�o	tt|�kS�N)�boolr�set�rDr?r?r@�is_tokenNsz+parse_content_disposition.<locals>.is_tokencSs |d|dko
dkSS)Nr����"r?rHr?r?r@�	is_quotedQs z,parse_content_disposition.<locals>.is_quotedcs�|�o
|�d�dkS)N�'�)�countrH�rIr?r@�
is_rfc5987T�z-parse_content_disposition.<locals>.is_rfc5987cSs
|�d�S)N�*)�endswithrHr?r?r@�is_extended_paramW�
z4parse_content_disposition.<locals>.is_extended_paramcSs@|�d�d}|sdS|�d�r||d�n||d�}|��S)NrSrFrJ)�findrT�isdigit)rD�posZ	substringr?r?r@�is_continuous_paramZs
"z6parse_content_disposition.<locals>.is_continuous_param�)�chars�textr\cSst�d|�d�d|�S)Nz\\([z])z\1)�re�sub)r]r\r?r?r@�unescapearRz+parse_content_disposition.<locals>.unescape�;r�=rrJrMrN�utf-8�strictTFz\/)�strrF�join�mapr^�escaper�split�warnings�warnr5�pop�lower�strip�lstripr6r�UnicodeDecodeError)rBrLrQrUrZr`Zdisptype�parts�params�item�key�value�encoding�_Zfailed�_valuer?rPr@r7Ks�*
�

�



�Br7�filenamerr�namec
s�d|�|sdS�|vr|�S||vr||Sg}t�fdd�|��D��}t|�D]%\}\}}|�dd�\}}|�d�rD|dd�}|t|�krP|�|�q+|sUdSd�|�}d|vrq|�dd	�\}	}}|	pjd
}	t||	d�S|S)Nz%s*c3s&�|]\}}|���r||fVqdSrE)�
startswith)�.0rtru�Zname_sufr?r@�	<genexpr>�s��
�z/content_disposition_filename.<locals>.<genexpr>rSrrJr[rMrNrcrd)	�sorted�items�	enumeraterirTre�appendrfr)
rrrzrqZfnparams�numrtrurw�tailrvr?r}r@r8�s4�

r8c@speZdZdZ						ddd	�Zdd
d�Zdedfd
d�Zdefdd�Z	deddBfdd�Z
ddd�ZdS)�MultipartResponseWrapperzzWrapper around the MultipartReader.

    It takes care about
    underlying connection and close it when it needs in.
    �respr9�streamr3rCNcCs||_||_dSrE)r�r�)�selfr�r�r?r?r@�__init__�s
z!MultipartResponseWrapper.__init__cC�|SrEr?�r�r?r?r@�	__aiter__��z"MultipartResponseWrapper.__aiter__)r3r.c�� �|��IdH}|durt�|SrE��next�StopAsyncIteration�r��partr?r?r@�	__anext__��
�z"MultipartResponseWrapper.__anext__cCs|jj��S)z2Returns True when all response data had been read.)r��content�at_eofr�r?r?r@r���zMultipartResponseWrapper.at_eofc�s.�|j��IdH}|j��r|��IdH|S)z#Emits next multipart reader object.N)r�r�r��release�r�rsr?r?r@r��s
�
zMultipartResponseWrapper.nextc�s�|j��IdHdS)z_Release the connection gracefully.

        All remaining content is read to the void.
        N)r�r�r�r?r?r@r��s�z MultipartResponseWrapper.release)r�r9r�r3rCN)rCr��rCN)r<r=r>�__doc__r�r�rr�rFr�r�r�r?r?r?r@r��s$��
�

�

�	r�c@sHeZdZdZdZddeejed�de	ddd	e
d
ededBded
ede
eddfdd�Zdedefdd�Zde	fdd�Zde	dBfdd�Zdd�dede	fdd�Zefdede	fdd �Zdede	fd!d"�Zdede	fd#d$�Zde	fd%d&�ZdId'd(�Zdd)�d*edBdefd+d,�Zdd)�d*edBdeeefdBfd-d.�Zdd)�d*edBdee eeffd/d0�Z!defd1d2�Z"d3e#de#e	Bfd4d5�Z$defd6d7�Z%d3e#de#e	Bfd8d9�Z&d3e#de'e#e	Bfd:d;�Z(d3e#de#e	Bfd<d=�Z)d3e#de'e#e	Bfd>d?�Z*d3e#de#e	Bfd@dA�Z+dBedefdCdD�Z,e-dedBfdEdF��Z.e-dedBfdGdH��Z/dS)Jr.z&Multipart reader for single body part.i �mixedN)�subtype�default_charset�max_decompress_size�client_max_size�max_size_error_cls�boundary�headers�CIMultiDictProxy[str]r�r�r�r�r�r�rCc
Cs�||_||_t|�d|_||_||_d|_|dk|_|jr dn|j�t	d�}	|	dur/t
|	�nd|_d|_t
�|_d|_d|_i|_||_||_||_dS)NrNF�	form-datar)r��	_boundary�len�
_boundary_len�_content�_default_charset�_at_eof�
_is_form_data�getr�int�_length�_read_bytesr�_unread�_prev_chunk�_content_eof�_cache�_max_decompress_size�_client_max_size�_max_size_error_cls)
r�r�r�r�r�r�r�r�r��lengthr?r?r@r�s"

zBodyPartReader.__init__r�cCr�rEr?r�r?r?r@r�&r�zBodyPartReader.__aiter__c�r�rEr�r�r?r?r@r�)s
�zBodyPartReader.__anext__c�s�|��IdH}|sdS|SrE)�readr�r?r?r@r�/s
�zBodyPartReader.nextF��decoder�c�s��|jrdSt�}|js(|�|�|j�IdH�t|�|jkr%|�|j��|jr|rNt�}|�|�2z3dHW}|�|�t|�|jkrJ|�|j��q26|S|S)z�Reads body part data.

        decode: Decodes data following by encoding
                method from Content-Encoding header. If it missed
                data remains untouched
        �N)	r��	bytearray�extend�
read_chunk�
chunk_sizer�r�r��decode_iter)r�r��data�decoded_data�dr?r?r@r�5s&��
��zBodyPartReader.read�sizec�sb�|jrdS|jr|�|�IdH}n|�|�IdH}|j�t�}|r�|��dkr�d�|�	��}t
|�d}|dkr�|��s�d|}d}|jrW|jd|�}|jt
|�d�|_t
|�|krl||j
�dt
|��IdH7}|sqd|_|d�|�	��7}||7}t
|�d}|dkr�|��r=|jt
|�7_|j|jkr�d|_|jr�|j
��IdHdkr�td��|S)	zWReads body part content chunk of the specified size.

        size: chunk size
        r�N�base64�rT�
z3Reader did not read all the data or it is malformed)r�r��_read_chunk_from_length�_read_chunk_from_streamr�r�rrmrfrir�r�r�r�r�r��readline�
ValueError)r�r��chunkrvZstripped_chunk�	remainderZover_chunk_sizeZ
over_chunkr?r?r@r�Ls<��zBodyPartReader.read_chunkc�sL�|jdus
Jd��t||j|j�}|j�|�IdH}|j��r$d|_|S)Nz(Content-Length required for chunked readT)r��minr�r�r�r�r�)r�r�r�r�r?r?r@r�xs�
z&BodyPartReader._read_chunk_from_lengthc�s��||jks
Jd��|jdu}|rd|j�|�IdH|_d}t|�|jkrQ||j�|�IdH7}|jt|j���7_|jdkrFtd��|jrJnt|�|jks&t|�|krg|j�	||d��|d|�}|jdusnJ�|j|}d|j
}|r�|�|�}n|�|tdt|j�t|���}|dkr�t
���t
jdtd�|j�	||d��Wd�n1s�wY|jd|�|_|t|j�|�}|s�d	|_|j|r�dndd�}||_|S)
Nz<Chunk size must be greater or equal than boundary length + 2r�r�rNzReading after EOFr�ignore)�categoryT)r�r�r�r�r�r�r�r�r�Zunread_datar�rW�maxrj�catch_warnings�filterwarnings�DeprecationWarningr�)r�r�Zfirst_chunkr�Zwindowr_�idx�resultr?r?r@r��sJ��

�

 
�z&BodyPartReader._read_chunk_from_streamc�s��|jrdS|jr|j��}n|j��IdH}|�|j�r?|�d�}|j}|jd}||ks2||kr=d|_|j�|�dS|S|j��IdH}|�|j�rS|dd�}|j�|�|S)z Reads body part by line by line.r�Nr��--T���)	r�r��popleftr�r�r{r��rstripr�)r��line�sliner�Z
last_boundary�	next_liner?r?r@r��s(�

�zBodyPartReader.readlinec�s2�|jrdS|js|�|j�IdH|jr	dSdS)z0Like read(), but reads all the data to the void.N)r�r�r�r�r?r?r@r��s��zBodyPartReader.release)rvrvc�s.�|jdd�IdH}|p|jdd�}|�|�S)z;Like read(), but assumes that body part contains text data.Tr�Nrc��default)r��get_charsetr��r�rvr�r?r?r@r]�s�
zBodyPartReader.textc�sJ�|jdd�IdH}|sdS|p|jdd�}ttttft�|�|���S)z<Like read(), but assumes that body parts contains JSON data.Tr�Nrcr�)	r�r�r�dictrer	�json�loadsr�r�r?r?r@r��s�zBodyPartReader.jsonc�sr�|jdd�IdH}|sgS|dur|}n|jdd�}z	|���|�}Wn
ty1td|��wt|d|d�S)zFLike read(), but assumes that body parts contain form urlencoded data.Tr�Nrcr�z'data cannot be decoded with %s encoding)�keep_blank_valuesrv)r�r�r�r�rpr�r
)r�rvr�Z
real_encodingr�r?r?r@�form�s"���zBodyPartReader.formcC�|jS)z<Returns True if the boundary was reached or False otherwise.�r�r�r?r?r@r���zBodyPartReader.at_eofr�cCst|jvr
|�|�S|S)z>Apply Content-Transfer-Encoding decoding if header is present.)rr��_decode_content_transfer)r�r�r?r?r@� _apply_content_transfer_decoding�s

z/BodyPartReader._apply_content_transfer_decodingcCs|jot|jvS)z5Check if Content-Encoding decoding should be applied.)r�rr�r�r?r?r@�_needs_content_decodingsz&BodyPartReader._needs_content_decodingcCs |�|�}|��r|�|�S|S)aDecodes data synchronously.

        Decodes data according the specified Content-Encoding
        or Content-Transfer-Encoding headers value.

        Note: For large payloads, consider using decode_iter() instead
        to avoid blocking the event loop during decompression.
        )r�r��_decode_content)r�r��decodedr?r?r@r�s
	
zBodyPartReader.decodecCsB�|�|�}|��r|�|�2z	3dHW}|Vq6dS|VdS)a$Async generator that yields decoded data chunks.

        Decodes data according the specified Content-Encoding
        or Content-Transfer-Encoding headers value.

        This method offloads decompression to an executor for large payloads
        to avoid blocking the event loop.
        N)r�r��_decode_content_async)r�r�r�r�r?r?r@r�s�
	�
zBodyPartReader.decode_itercCsL|j�td���}|dkr|S|dvrt|dd�j||jd�Std|����)Nr[�identity>�deflate�gzipT�rv�suppress_deflate_header�Z
max_length�unknown content encoding: )r�r�rrmrZdecompress_syncr��RuntimeError�r�r�rvr?r?r@r�$s��zBodyPartReader._decode_contentcCs��|j�td���}|dkr|VdS|dvr?t|dd�}|j||jd�IdHV|jr=|jd|jd�IdHV|js,dSdStd|����)	Nr[r�>r�r�Tr�r�r�r�)	r�r�rrmr�
decompressr�Zdata_availabler�)r�r�rvr�r?r?r@r�0s�
��z$BodyPartReader._decode_content_asynccCsP|j�td���}|dkrt�|�S|dkrt�|�S|dvr!|Std|����)Nr[r��quoted-printable)�binary�8bit�7bit�#unknown content transfer encoding: )	r�r�rrmr��	b64decode�binascii�a2b_qpr�r�r?r?r@r�As

z'BodyPartReader._decode_content_transferr�cCs*|j�td�}t|�}|j�d|jp|�S)z>Returns charset parameter from Content-Type header or default.r[�charset)r�r�rr�
parametersr�)r�r��ctype�mimetyper?r?r@r�MszBodyPartReader.get_charsetcC�t|j�t��\}}t|d�S)z|Returns name specified in Content-Disposition header.

        If the header is missing or malformed, returns None.
        rz�r7r�r�rr8�r�rwrrr?r?r@rzS�
zBodyPartReader.namecCr)zReturns filename specified in Content-Disposition header.

        Returns None if the header is missing or malformed.
        ryr	r
r?r?r@ry\rzBodyPartReader.filenamer�)0r<r=r>r�r�r�sys�maxsizer��bytesr*rer��type�	Exceptionr�r-r�r�r�rFr�r�r�r�r�r�r]r�r	r��list�tupler�r�r2r�r�r�rr�r�r�r�r�rrzryr?r?r?r@r.sp�������	�
�
�,
-
((�

�)�ordercszeZdZUeed<dedededdf�fdd�Zddededefd
d�Zddedede	fdd�Z
deddfdd�Z�Z
S)�BodyPartReaderPayloadrxru�args�kwargsrCNcsbt�j|g|�Ri|��i}|jdur|j|d<|jdur#|j|d<|r/|jdi|��dSdS)Nrzry�
attachmentT)rT)�superr�rzry�set_content_disposition)r�rurrrr��	__class__r?r@r�ks



�zBodyPartReaderPayload.__init__rcrdrv�errorscCstd��)NzUnable to decode.��	TypeError�r�rvrr?r?r@r�wszBodyPartReaderPayload.decodec�s
�td��)aRRaises TypeError as body parts should be consumed via write().

        This is intentional: BodyPartReader payloads are designed for streaming
        large data (potentially gigabytes) and must be consumed only once via
        the write() method to avoid memory exhaustion. They cannot be buffered
        in memory for reuse.
        z:Unable to read body part as bytes. Use write() to consume.rrr?r?r@�as_byteszs�zBodyPartReaderPayload.as_bytes�writerc�sf�|j}|jtd�IdH}r1|�|�2z3dHW}|�|�IdHq6|jtd�IdH}sdSdS)N)r�)rxr�rr��write)r�r!�fieldr�r�r?r?r@r"�s���zBodyPartReaderPayload.write�rcrd)r<r=r>r.�__annotations__r	r�rer�rr rr"�
__classcell__r?r?rr@rfs

rc@sVeZdZUdZeZdZeddBed<e	Z
ejdde
d�deeefded	ed
ededeed
dfdd�Zded
efdd�Zd
ede	fdBfdd�Zeddd
efdd��Zd
efdd�Zd
ede	fdBfdd�Zd0dd�Zd
ede	ffdd �Zdd!d
ede	ffd"d#�Zd
efd$d%�Z d
e!fd&d'�Z"d0d(d)�Z#d0d*d+�Z$d1d,d-�Z%d0d.d/�Z&dS)2r3zMultipart body reader.N�multipart_reader_clsi���r��max_field_size�max_headersr�r�r�r�r*r+r�rCcCs�t|t�|_|jjdksJd��d|jjvrtd|t��||_d|����|_	||_
||_d|_d|_
||_||_||_d|_d|_g|_dS)N�	multipartz!multipart/* content type expectedr�z$boundary missed for Content-Type: %s�--FT)rr�	_mimetyperrr�r��
_get_boundary�encoder�r�r�r��
_last_part�_max_field_size�_max_headersr�r��_at_bofr�)r�r�r�r�r*r+r�r?r?r@r��s$

�
zMultipartReader.__init__r�cCr�rEr?r�r?r?r@r��r�zMultipartReader.__aiter__c�r�rEr�r�r?r?r@r��r�zMultipartReader.__anext__�responser9cCs|�|||j|j��}|S)z�Constructs reader instance from HTTP response.

        :param response: :class:`~aiohttp.client.ClientResponse` instance
        )�response_wrapper_clsr�r�)�clsr5�objr?r?r@�
from_response�s	�zMultipartReader.from_responsecCr�)z@Returns True if the final boundary was reached, false otherwise.r�r�r?r?r@r��r�zMultipartReader.at_eofc�s��|jrdS|��IdH|jr|��IdHd|_n|��IdH|jr'dS|��IdH}|jduro|jjdkrot	|t
�rot|j�
t��\}}|�
d�dkro|�d�IdH}t|�dkratd��|����|_|��IdH}||_|jS)	z#Emits the next multipart body part.NFr�rzZ	_charset_� �zInvalid default charset)r��_maybe_release_last_partr4�_read_until_first_boundary�_read_boundary�fetch_next_partr1r.r��
isinstancer.r7r�r�rr�r�r�rnr�r�)r�r�rwrrrr?r?r@r��s0�
�zMultipartReader.nextc�s>�|js|��IdH}|durdS|��IdH|jrdSdS)z=Reads all the body parts to the void till the final boundary.N)r�r�r�r�r?r?r@r��s��zMultipartReader.releasec�s�|��IdH}|�|�S)z"Returns the next body part reader.N)�
_read_headers�_get_part_reader)r�r�r?r?r@r?�s�
zMultipartReader.fetch_next_partr�c	Cs�|�td�}t|�}|jdkr5|jdur%t|�||j|j|j|j|j	d�S|j||j|j|j|j|j	d�S|j
|j||j|jj
|j|j|j	d�S)z�Dispatches the response by the `Content-Type` header.

        Returns a suitable reader instance.

        :param dict headers: Response headers
        r[r,Nr))r�r�r�r�)r�rrrr'r�r�r2r3r��part_reader_clsr�r.r�r�)r�r�rrr?r?r@rBs:


��	�z MultipartReader._get_part_readercCs(|jjd}t|�dkrtd|��|S)Nr��Fz&boundary %r is too long (70 chars max))r.rr�r�)r�r�r?r?r@r/-szMultipartReader._get_boundaryc�s"�|jr	|j��S|j��IdHSrE)r�rlr�r�r�r?r?r@�	_readline4s�
zMultipartReader._readlinec�sX�	|��IdH}|dkrtd|j��|��}||jkrdS||jdkr+d|_dSq)NTr�z#Could not find starting boundary %rr�)rEr�r�r�r��r�r�r?r?r@r=9s��
�z*MultipartReader._read_until_first_boundaryc�s��|��IdH��}||jkrdS||jdkrCd|_|��IdH}|��IdH}|dd�dkr9|j�|�dS|j�||g�dStd|�d|j����)Nr�TrNzInvalid boundary z, expected )rEr�r�r�r�r�r�r�)r�r��epiloguer�r?r?r@r>Gs�
zMultipartReader._read_boundaryc�sn�g}	|jj|jd�IdH}|�d�}|�|�|snt|�|jkr'td��qt|jd�}|�	|�\}}|S)NT)�max_line_lengthr�zToo many headers received)r*)
r�r�r2r�r�r�r3r!r �
parse_headers)r��linesr��parserr��raw_headersr?r?r@rA^s�

�zMultipartReader._read_headersc�sD�|jdur |j��s|j��IdH|j�|jj�d|_dSdS)z8Ensures that the last read body part is read completely.N)r1r�r�r�r�r�r?r?r@r<ls�


�z(MultipartReader._maybe_release_last_partr�)rCr�)'r<r=r>r�r�r6r'rr%r.rCrr
r�rrer*r�rr�r-r�rr��classmethodr9rFr�r�r�r?rBr/rrEr=r>rAr<r?r?r?r@r3�sj
�
������	
�
���

�
#

��

�*


r3cs�eZdZUdZded<dZd9dededBddf�fd	d
�
Zd:dd�Zd
e	e
dBde
dBdedBddfdd�Zde
efdd�Zdefdd�Zdefdd�Ze�d�Ze�d�Zedefdd��Zedefdd��Zd;dedeeefdBdefd d!�Zd"edefd#d$�Z	d;dedeeefdBdefd%d&�Z 	d;de!e"eefeeefBdeeefdBdefd'd(�Z#ededBfd)d*��Z$d<d-ed.edefd/d0�Z%d<d-ed.ede&fd1d2�Z'	d=d3e(d4eddfd5d6�Z)d>d7d8�Z*�Z+S)?r4zMultipart body writer.NrxTr�r�r�rCcsv|dur|nt��j}z|�d�|_Wntytd�d�wd|�d|j��}t�j	d|d�g|_
|dk|_dS)N�asciiz(boundary should contain ASCII only charsz
multipart/z; boundary=)�content_typer�)�uuidZuuid4�hexr0r��UnicodeEncodeErrorr��_boundary_valuerr��_partsr�)r�r�r�rrr?r@r�s
�zMultipartWriter.__init__cCr�rEr?r�r?r?r@�	__enter__�r�zMultipartWriter.__enter__�exc_type�exc_val�exc_tbcCsdSrEr?)r�rVrWrXr?r?r@�__exit__�szMultipartWriter.__exit__cC�
t|j�SrE)�iterrTr�r?r?r@�__iter__�rVzMultipartWriter.__iter__cCrZrE)r�rTr�r?r?r@�__len__�rVzMultipartWriter.__len__cCsdS)NTr?r�r?r?r@�__bool__�r�zMultipartWriter.__bool__s\A[!#$%&'*+\-.^_`|~\w]+\Zs[\x00-\x08\x0A-\x1F\x7F]cCs^|j}t�|j|�r|�d�St�|j|�rtd��|�dd�}|�dd�}d|�d�dS)zzWrap boundary parameter value in quotes, if necessary.

        Reads self.boundary and returns a unicode string.
        rNz*boundary value contains invalid characters�\s\\�"s\"rK)	r�r^�match�_valid_tchar_regexr��search�_invalid_qdtext_char_regexr��replace)r�ruZquoted_value_contentr?r?r@rS�s
zMultipartWriter._boundary_valuecCs|j�d�S)NrN)r�r�r�r?r?r@r��r�zMultipartWriter.boundaryr8r�cCsd|durt�}t|t�r|j�|�|�|�Szt||d�}Wn
ty,td|��w|�|�S)N�r�zCannot create payload from %r)	rr@r&r��update�append_payloadr(r$r)r�r8r��payloadr?r?r@r��s

�
zMultipartWriter.appendricCs�d}d}|jr(ttth|j��@rJ�t|jvr'dt|j���}|j	d|d�nH|j�
td���}|r>|dvr>td|����|dkrDd}|j�
td���}|d	vrXtd
|����|dkr^d}|j
}|durp|sp|spt|�|jt<|j�|||f�|S)z)Adds a new body part to multipart writer.Nzsection-r�)rzr[)r�r�r�r�r�)r[r�r�r�rr�)r�rrrr��keysrr�rTrr�rmr�r�rer�)r�rirv�te_encodingrzr�r?r?r@rh�s4��
�zMultipartWriter.append_payloadcCs |durt�}|�t||d��S)zHelper to append JSON part.Nrf)rrhr#)r�r8r�r?r?r@�append_jsonszMultipartWriter.append_jsoncCsVt|ttf�s	J�|durt�}t|t�rt|���}t|dd�}|�t||dd��S)z&Helper to append form urlencoded part.NT)�doseqz!application/x-www-form-urlencoded)r�rO)	r@rrrrr�rrhr')r�r8r�r�r?r?r@�append_form
s
��zMultipartWriter.append_formcCsxd}|jD])\}}}|j}|s|s|durdS|tdt|j�d|t|j�d�7}q|dt|j�d7}|S)zSize of the payload.rNrNr�)rTr�r�r�r��_binary_headers)r��totalr�rvrkZ	part_sizer?r?r@r�s(������	zMultipartWriter.sizercrdrvrcsd����fdd��jD��S)z�Return string representation of the multipart data.

        WARNING: This method may do blocking I/O if parts contain file payloads.
        It should not be called in the event loop. Use as_bytes().decode() instead.
        r[c3s:�|]\}}}d�jd|j����|��VqdS)r-z
N)r�ror�)r|r��_e�_te�rvrr�r?r@r~:s������
�z)MultipartWriter.decode.<locals>.<genexpr>)rfrTrr?rsr@r�4s�zMultipartWriter.decodec�s|�g}|jD](\}}}|�d|jd�|�|j�|�||�IdH}|�|�|�d�q|�d|jd�d�|�S)z�Return bytes representation of the multipart data.

        This method is async-safe and calls as_bytes on underlying payloads.
        r�r�N�--
r�)rTr�r�ror rf)r�rvrrqr�rqrrZ
part_bytesr?r?r@r Cs�

zMultipartWriter.as_bytesr!�close_boundaryc�s��|jD]d\}}}|jrt|jvsJ�d|jtvsJ�|�d|jd�IdH|�|j�IdH|s6|rXt|�}|rA|�|�|rH|�	|�|�|�IdH|�
�IdHn|�|�IdH|�d�IdHq|rz|�d|jd�IdHdSdS)zWrite body.zname=r�r�Nrt)rTr�rr�r"r�ro�MultipartPayloadWriter�enable_compression�enable_encoding�	write_eof)r�r!rur�rvrk�wr?r?r@r"^s(�

�zMultipartWriter.writec�s��|jrdSd|_t|j�D]2\}\}}}|js@|js@z	|��IdHWqty?}ztjd||dd�WYd}~qd}~wwqdS)a
        Close all part payloads that need explicit closing.

        IMPORTANT: This method must not await anything that might not finish
        immediately, as it may be called during cleanup/cancellation. Schedule
        any long-running operations without awaiting them.
        NTz%Failed to close multipart part %d: %s)�exc_info)	Z	_consumedr�rTZ	autoclose�consumed�closerr"�error)r�r�r�rw�excr?r?r@r}{s ������zMultipartWriter.close)r�N)rCr4rEr$)Tr�),r<r=r>r�r%Z
_autocloserer�rUr�
BaseExceptionrrYr�_Partr\r�r]rFr^r^�compilerbrd�propertyrSr�r	rr&r�rhrlrrrnr�r�rr rr"r}r&r?r?rr@r4xsn
 

���
�

$'���
����
����
�r4c@sjeZdZdeddfdd�Zdeddfdd�Z	dded
edBddfdd�Zdd
d�Z	de
ddfdd�ZdS)rvr!rCNcCs||_d|_d|_d|_dSrE)�_writer�	_encoding�	_compress�_encoding_buffer)r�r!r?r?r@r��s
zMultipartPayloadWriter.__init__rvcCs0|dkr
||_t�|_dS|dkrd|_dSdS)Nr�r�)r�r�r�)r�rvr?r?r@rx�s
�z&MultipartPayloadWriter.enable_encodingr��strategycCst|d|d�|_dS)NT)rvr�r�)rr�)r�rvr�r?r?r@rw�s
�z)MultipartPayloadWriter.enable_compressionc�sf�|jdur|j��}|rd|_|�|�IdH|jdkr/|jr1|j�t�|j��IdHdSdSdS)Nr�)r��flushr"r�r�r�r��	b64encoderFr?r?r@ry�s�


�z MultipartPayloadWriter.write_eofr�c�s��|jdur|r|j�|�IdH}|sdS|jdkr[|j}|dus#J�|�|�|rWtt|�d�\}}|d|d�||dd�}|_|rYt�|�}|j	�
|�IdHdSdSdS|jdkrn|j	�
t�|��IdHdS|j	�
|�IdHdS)Nr�r+r�)
r��compressr�r�r��divmodr�r�r�r�r"r�b2a_qp)r�r��bufZdiv�modZ	enc_chunkZb64chunkr?r?r@r"�s*�


$
�
zMultipartPayloadWriter.write)r�Nr�)r<r=r>rr�rerxr�rwryrr"r?r?r?r@rv�s���
�
	rv)ry)Wr�rr�r^rrPrj�collectionsr�collections.abcrrrr�typesr�typingrr	r
rr�urllib.parser
rrZ	multidictrr�abcrZcompression_utilsrrZhdrsrrrrrZhelpersrrrrr�httpr Zhttp_exceptionsr!�logr"rir#r$r%r&r'r(r)Zstreamsr*�version_infor-r1rr�r2�__all__Z
client_reqrepr9�RuntimeWarningr5r6rerr�r7r8r�r.Z	try_firstrr3r�r4rvr?r?r?r@�<module>sx$	

�
�h�
��
�!/f$k