HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/aiohttp/__pycache__/client_reqrep.cpython-310.pyc
o

;j���
@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZmZmZddlmZmZddlmZmZddlmZmZmZmZmZmZddlZddlm Z m!Z!m"Z"m#Z#ddl$m%Z%d	d
l&m'Z'm(Z(m)Z)m*Z*m+Z+d	dl,m-Z-m.Z.m/Z/d	dl0m1Z1d	d
l2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8d	dl9m:Z:m;Z;d	dl<m=Z=d	dl(m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHd	dl)mIZImJZJmKZKmLZLmMZMd	dlNmOZOd	dlPmQZQmRZRmSZSmTZTmUZUmVZVer�ddlWZWddlWmXZXnzddlWZWddlWmXZXWneY�ydZWeZZXYnwdZ[e�r'd	dl\m]Z]d	dl^m_Z_d	dl`maZae3d�Zbe�cd�Zde�cd�Zee�cdejf�Zgdehfdd�Ziejjd d d d!�Gd"d#�d#��ZkGd$d%�d%e�ZlGd&d'�d'el�ZmGd(d)�d)�ZneWdu�rxeWjXeoenepd�fZqneoepd�fZqd*ed+eoenfd,eodBd-ed+d.erdBded+eoenff
d/d0�Zsetd1�ZuGd2d3�d3e�Zvd4ehd5ehdeofd6d7�ZwdAd9e+jxd:eyddfd;d<�ZzGd=d>�d>eA�Z{Gd?d@�d@�Z|dS)B�N)�Callable�Iterable�Mapping)�md5�sha1�sha256)�Morsel�SimpleCookie)�MappingProxyType�
TracebackType)�
TYPE_CHECKING�Any�Literal�
NamedTuple�Optional�Union)�CIMultiDict�CIMultiDictProxy�	MultiDict�MultiDictProxy)�URL�)�hdrs�helpers�http�	multipart�payload)�parse_cookie_header�parse_set_cookie_headers� preserve_morsel_with_coded_value)�AbstractStreamWriter)�ClientConnectionError�
ClientOSError�ClientResponseError�ContentTypeError�
InvalidURL�ServerFingerprintMismatch)�
HAS_BROTLI�HAS_ZSTD)�FormData)�	_SENTINEL�BaseTimerContext�	BasicAuth�HeadersMixin�	TimerNoop�_basic_auth_no_warn�noop�reify�sentinel�
set_exception�
set_result)�SERVER_SOFTWARE�HttpVersion�
HttpVersion10�
HttpVersion11�StreamWriter)�StreamReader)�DEFAULT_JSON_DECODER�JSONDecoder�LooseCookies�LooseHeaders�Query�
RawHeaders)�
SSLContext)�
ClientRequest�ClientResponse�RequestInfo�Fingerprint)�
ClientSession)�
Connection)�Trace�Connection closedz[^-!#$%&'*+.^_`|~0-9a-zA-Z]z!^application/(?:[\w.+-]+?\+)?jsonz\d+�returncCs.ddg}tr|�d�tr|�d�d�|�S)N�gzip�deflate�brZzstd�, )r'�appendr(�join)�	encodings�rR�I/opt/saltstack/salt/lib/python3.10/site-packages/aiohttp/client_reqrep.py�_gen_default_accept_encoding^s�


rTT)Zauto_attribs�frozen�slotsc@s.eZdZUedBed<ded<edBed<dS)�ContentDispositionN�typezMappingProxyType[str, str]�
parameters�filename)�__name__�
__module__�__qualname__�str�__annotations__rRrRrRrSrWjs
rWc@s.eZdZUeed<eed<ded<eed<dS)�_RequestInfo�url�method�CIMultiDictProxy[str]�headers�real_urlN)r[r\r]rr_r^rRrRrRrSr`qs

r`c@s2eZdZefdededddeeBddf
dd�Zd	S)
rDrarbrdrcrerJcCs$t�|||||tur|f�S|f�S)zuCreate a new RequestInfo instance.

        For backwards compatibility, the real_url parameter is optional.
        )�tuple�__new__r2)�clsrarbrdrerRrRrSrgzs
��zRequestInfo.__new__N)r[r\r]r2rr^r*rgrRrRrRrSrDxs������rDc@sPeZdZeeed�Zdeddfdd�Ze	defdd��Z
d	ejddfd
d�Z
dS)rE)��� �fingerprintrJNcCsHt|�}|j�|�}|std��|tus|turtd��||_||_dS)Nzfingerprint has invalid lengthz8md5 and sha1 are insecure and not supported. Use sha256.)�len�HASHFUNC_BY_DIGESTLEN�get�
ValueErrorrr�	_hashfunc�_fingerprint)�selfrlZ	digestlenZhashfuncrRrRrS�__init__�s
zFingerprint.__init__cC�|jS�N)rr�rsrRrRrSrl��zFingerprint.fingerprint�	transportcCs`|�d�sdS|�d�}|jdd�}|�|���}||jkr.|�d�^}}}t|j|||��dS)NZ
sslcontextZ
ssl_objectT)�binary_formZpeername)Zget_extra_info�getpeercertrq�digestrrr&)rsry�sslobj�certZgot�host�port�_rRrRrS�check�s


�zFingerprint.check)r[r\r]rrrrn�bytesrt�propertyrl�asyncioZ	Transportr�rRrRrRrSrE�s�
rE�sslrA�
verify_ssl�ssl_contextrlcCs�|durd}|dur|stjdtdd�|durtd��d}|dur4tjdtdd�|dur2td��|}|durLtjdtdd�|durHtd��t|�}t|t�sYtd	|�d
���|S)NTz/verify_ssl is deprecated, use ssl=False instead���
stacklevelzNverify_ssl, ssl_context, fingerprint and ssl parameters are mutually exclusiveFz2ssl_context is deprecated, use ssl=context insteadzCfingerprint is deprecated, use ssl=Fingerprint(fingerprint) insteadz9ssl should be SSLContext, bool, Fingerprint or None, got z	 instead.)�warnings�warn�DeprecationWarningrprE�
isinstance�SSL_ALLOWED_TYPES�	TypeError)r�r�r�rlrRrRrS�_merge_ssl_params�sT������
��r�)�https�wssc@sneZdZUeed<edBed<eed<eeBeBed<e	dBed<e
dBed<edBed<dZedBed	<dS)
�
ConnectionKeyrNr��is_sslr��proxy�
proxy_authZproxy_headers_hash�server_hostname)r[r\r]r^r_�int�boolrArErr,r�rRrRrRrSr��s
r��response_content_type�expected_content_typecCs|dkrt�|�duS||vS)N�application/json)�json_re�match)r�r�rRrRrS�_is_expected_content_type�sr��rr�cCs(|js|jstjdt|d�dSdSdS)z�Warn if the payload is not closed.

    Callers must check that the body is a Payload before calling this method.

    Args:
        payload: The payload to check
        stacklevel: Stack level for the warning (default 2 for direct callers)
    z�The previous request body contains unclosed resources. Use await request.update_body() instead of setting request.body directly to properly close resources and avoid leaks.r�N)Z	autoclose�consumedr�r��ResourceWarning)rr�rRrRrS�_warn_if_unclosed_payloads	
��r�c@s8eZdZUdZedBed<dZeed<dZe	dBed<dZ
eed<dZe
dBed<dZee	ed<dZed	ed
<dZeed<dZeded
<dZedBed<dZee	dfdBed<dZeded<dZejdBed<dZeded<dZdZdZ dd�Z!e"de
ge	fed<dZ#eded<dZ$ee%ed<dZ&eed<dZ'ee(j)ded <d!e	d"e*d#d$d%edd&e+d'e,d(e-d)d*e(j.d+dd,e%d-dfd.d/�Z/d�d0e0d-dfd1d2�Z1e2d-edfd3d4��Z3e3j4d#edd-dfd5d4��Z3e2d-efd6d7��Z5e2d�d9d:��Z6e2d-efd;d<��Z7e7j4d=ed-dfd>d<��Z7e8d-e*fd?d@��Z9e8d-e*fdAdB��Z:e8d-e*fdCdD��Z;e8d-e	fdEdF��Z<e8d�dHdI��Z=e8d-efdJdK��Z>e8d-e,fdLdM��Z?e8d-e@dBfdNdO��ZAeBfdPeCd-dfdQdR�ZDd-e	fdSdT�ZEe2d-edfdUdV��ZFe8d-ed	fdWdX��ZGe8d�dZd[��ZHd�d]d^�ZId�d_d`�ZJe2d-eKfdadb��ZLd�dcdd�ZMd-eCfdedf�ZNe2d-eKfdgdh��ZOd�didj�ZPd�dkdl�ZQd�dmdn�ZRd�dodp�ZSd�dqdr�ZTd�dsdt�ZUd-e
fdudv�ZVd-e	fdwdx�ZWd�dze	dBd{e	d-e	fd|d}�ZXdeYd~d�dze	dBd�eZd�e	dBd-eCfd�d��Z[d�d�d��Z\d�e]e^dBd�e^dBd�e_dBd-dfd�d��Z`dS)�rCN�version�status�reason�content�_body�_headersrR)rC.�_history�_raw_headersrG�_connection�_cookies.�_raw_cookie_headerszasyncio.Future[bool]�	_continue�_source_tracebackrF�_sessionTFcGsdS)N�utf-8rR)r�rRrRrS�<lambda>1szClientResponse.<lambda>�_resolve_charset�asyncio.Task[None]�_ClientResponse__writer�_stream_writerr�_output_size�_upload_completerbra�writerzasyncio.Task[None] | None�continue100�timer�request_info�tracesrH�loop�session�
stream_writerrJcCs�t|�tusJ�||_||_|jr|�d�n||_|dur"|
j|_n|
|_	||_
|dur/||_||_|dur8|nt
�|_i|_||_||_|	durP|	|_|	j|_|��r_t�t�d��|_dSdS)Nr)rXrrb�	_real_url�raw_fragment�
with_fragment�_url�output_sizer�r��_writerr��
_request_infor.�_timer�_cache�_traces�_loopr�r��	get_debug�	traceback�
extract_stack�sys�	_getframer�)rsrbrar�r�r�r�r�r�r�r�rRrRrSrt8s*
�zClientResponse.__init__r�cCsLd|_|jdur|jj|_d|_|jdur"|j��s$|j�d�dSdSdSrv)r�r�r�r�r��doner4�rsr�rRrRrS�__reset_writercs

�zClientResponse.__reset_writercCru)z�The writer task for streaming data.

        _writer is only provided for backwards compatibility
        for subclasses that may need to access it.
        )r�rwrRrRrSr�kszClientResponse._writercCsN|jdur|j�|j�||_|durdS|��r|��dS|�|j�dS)z'Set the writer task for streaming data.N)r��remove_done_callback�_ClientResponse__reset_writerr��add_done_callback�rsr�rRrRrSr�ts
cCs|jdur	|jjS|jS)z&Number of bytes sent for this request.N)r�r�r�rwrRrRrSr��s
zClientResponse.output_size�asyncio.Future[None]cCs2|jdur|j��|_|jdur|j�d�|jS)z�Future set when the request body has been fully sent.

        Already done when the request had no body or was written eagerly.
        N)r�r��
create_futurer�r4rwrRrRrS�upload_complete�s


zClientResponse.upload_completecCsD|jdur|jdurt�}|�t|j��||_|jSt�|_|jSrv)r�r�r	�updater�rs�cookiesrRrRrSr��s

�zClientResponse.cookiesr�cCs0||_|rtdd�|��D��|_dSd|_dS)Ncss�|]}|��VqdSrv)ZOutputString)�.0ZmorselrRrRrS�	<genexpr>���
�z)ClientResponse.cookies.<locals>.<genexpr>)r�rf�valuesr�r�rRrRrSr��s�
cCrurv)r�rwrRrRrSra�rxzClientResponse.urlcCstjdtdd�|jS)NzDeprecated, use .url #1654r�r�)r�r�r�r�rwrRrRrS�url_obj�szClientResponse.url_objcCrurv)r�rwrRrRrSre�rxzClientResponse.real_urlcCs|jjdusJ�|jjSrv)r�rrwrRrRrSr�szClientResponse.hostrccCrurv)r�rwrRrRrSrd�rxzClientResponse.headerscCrurv)r�rwrRrRrS�raw_headers�rxzClientResponse.raw_headerscCrurv)r�rwrRrRrSr��rxzClientResponse.request_infocCsF|j�tj�}|dur
dSt�|�\}}t|�}t�|�}t|||�Srv)	r�rorZCONTENT_DISPOSITIONrZparse_content_dispositionr
Zcontent_disposition_filenamerW)rs�rawZdisposition_typeZ
params_dct�paramsrZrRrRrS�content_disposition�s
z"ClientResponse.content_disposition�	_warningscCs�|jrdS|jdur>|j��|��|j��r@d|i}|jd|��tfi|��|dd�}|jr6|j|d<|j�	|�dSdSdS)N�sourcezUnclosed response zUnclosed response)Zclient_response�messageZsource_traceback)
�_closedr��release�_cleanup_writerr�r�r�r�r�Zcall_exception_handler)rsr��kwargs�contextrRrRrS�__del__�s




�zClientResponse.__del__cCsjt��}t|j�}|jr|j�dd��d�}nd}td|�d|j�d|�d�|d�t|j	|d�|�
�S)	N�ascii�backslashreplace�Nonez<ClientResponse(z) [� z]>)�file)�io�StringIOr^rar��encode�decode�printr�rd�getvalue)rs�outZascii_encodable_urlZascii_encodable_reasonrRrRrS�__repr__�s
���zClientResponse.__repr__cCrurv)r�rwrRrRrS�
connection�rxzClientResponse.connectioncCru)z2A sequence of of responses, if redirects occurred.)r�rwrRrRrS�history�szClientResponse.history�)MultiDictProxy[MultiDictProxy[str | URL]]c
Cs�d�|j�dg��}|stt��St�}t�d|�D][}t�d|�}|dur'q|��\}}|�d�dd�}t�}|D]}	t�d|	tj	�}|durJq;|��\}
}}}|�
|
|�q;|�d|�}
|�
d	|j�t
|���|�
t|
�t|��qt|�S)
NrN�linkz	,(?=\s*<)z
\s*<(.*)>(.*)�;rz%^\s*(\S*)\s*=\s*(['\"]?)(.*?)(\2)\s*$�relra)rPrd�getallrr�re�splitr��groups�M�addrorarr^)
rsZ	links_str�links�valr�raZ
params_strr�r�param�keyr��valuerRrRrSr�s*
zClientResponse.linksrc�s.�d|_|j|_||_|j�S	z|j}|��IdH\}}Wntjy:}zt|j	|j
|j|j|j
d�|�d}~ww|jdksJ|jdksJ|jdkrKn|jdurYt|jd�d|_qWd�n1sdwY|�|j�|j|_|j|_|j|_|j
|_|j|_||_|j
�tjd�}r�t|�|_|S)	zStart response processing.FTN�r�r�rd�d���erR)r��protocolZ	_protocolr�r��readrZHttpProcessingErrorr#r�r�coder�rdr�r4Zon_eof�
_response_eofr�r�r�r�r�r�r�rrZ
SET_COOKIErfr�)rsrrr�r�excZcookie_hdrsrRrRrS�start#sN�����	
��
zClientResponse.startcCsD|jrdS|jo|jj}|dur|jrdSd|_|��|��dS�NT)r�r�r�upgradedr��_release_connection)rsrrRrRrSrTszClientResponse._response_eofcCrurv)r�rwrRrRrS�closedarxzClientResponse.closedcCsV|js|��d|_|jdus|j��rdS|��|jdur)|j��d|_dSdSr)�	_released�_notify_contentr�r��	is_closedr�r��closerwrRrRrSr"es


�zClientResponse.closecCs*|js|��d|_|��|��t�Sr)rr r�r�rr0rwrRrRrSr�rszClientResponse.releasecCs
d|jkS)z�Returns ``True`` if ``status`` is less than ``400``, ``False`` if not.

        This is **not** a check for ``200 OK`` but a check that the response
        status is under 400.
        i�)r�rwrRrRrS�ok|s
zClientResponse.okcCsB|js|jdus
J�|js|��t|j|j|j|j|jd��dS)Nr)	r#r��_in_contextr�r#r�rr�rdrwrRrRrS�raise_for_status�s��zClientResponse.raise_for_statuscsD�jdur �jdur�j��d�_dS�j��fdd��dSdS)Ncs���Srv)r)�frwrRrSr��sz4ClientResponse._release_connection.<locals>.<lambda>)r�r�r�r�rwrRrwrSr�s



�z"ClientResponse._release_connectionc��^�|jdur)z|jIdHWntjy(tjdkr&t��}r&|��r&�Ynw|��dS�N)r��)r�r��CancelledErrorr��version_info�current_task�
cancellingr�rs�taskrRrRrS�_wait_released���


����zClientResponse._wait_releasedcCs8|jdur
|j��|jdur|jj|_d|_d|_dSrv)r��cancelr�r�r�r�rwrRrRrSr��s




zClientResponse._cleanup_writercCs*|j}|r|��durt|t�d|_dSr)r��	exceptionr3�_CONNECTION_CLOSED_EXCEPTIONr)rsr�rRrRrSr �s

zClientResponse._notify_contentc�r'r()r�r�r*r�r+r,r-r�r.rRrRrS�wait_for_close�r1zClientResponse.wait_for_closec�s��|jdur1z|j��IdH|_|jD]}|�|j|j|j�IdHqWnty0|���w|j	r8t
d��|jo>|jj}|dusF|j
sM|��IdH|jS)zRead response payload.NrI)r�r�rr�Zsend_response_chunk_receivedrbra�
BaseExceptionr"rr!r�rrr0)rs�tracerrRrRrSr�s&�

���zClientResponse.readcCs�|j�tjd���}t�|�}|j�d�}|r3t�	t
t��t�
|�jWd�S1s.wY|jdkrD|jdksB|jdkrDdS|jdurMtd��|�||j�S)N��charsetZapplication�jsonZrdapr�z7Cannot compute fallback encoding of a not yet read body)rdror�CONTENT_TYPE�lowerrZparse_mimetyperY�
contextlib�suppress�LookupErrorrp�codecs�lookup�namerX�subtyper��RuntimeErrorr�)rs�ctypeZmimetype�encodingrRrRrS�get_encoding�s

 �

�zClientResponse.get_encoding�strictrF�errorsc�s:�|jdur
|��IdH|dur|��}|jj||d�S)z!Read response payload and decode.N)rI)r�rrGr�)rsrFrIrRrRrS�text�s�
zClientResponse.textr�)rF�loads�content_typerKrLc�s��|jdur
|��IdH|r-|j�tjd���}t||�s-t|j	|j
|jd||jd��|j��}|s6dS|dur>|�
�}||�|��S)zRead and decodes JSON response.Nr8z3Attempt to decode JSON with unexpected mimetype: %sr)r�rrdrorr;r<r�r$r�rr��striprGr�)rsrFrKrLrE�strippedrRrRrSr:�s&�

�

zClientResponse.jsonc�s�d|_|Sr)r$rwrRrRrS�
__aenter__s�zClientResponse.__aenter__�exc_type�exc_val�exc_tbc�s"�d|_|��|��IdHdS)NF)r$r�r5)rsrPrQrRrRrRrS�	__aexit__!s�zClientResponse.__aexit__rv)rJr�)rJrc)rJr)rrGrJrC�rJN)NrH)rJrC)ar[r\r]r�r6r_r�r�r�r^r�r:r�r�r�rr�rfr�r@r�rr�r	r�r�r�r��StackSummaryr�r�rr$r�rr�r�r r�r�r�ZFuturerr+rD�list�AbstractEventLooprt�objectr�r�r��setterr�r�r�r1rar�rerrdr�r�rWr�r�r
r�r�rrrrrr�rr"r�r#r%rr0r�r r5rrGrJr;r<r:rOrXr6rrSrRrRrRrSrCs�
������	�
���
�+


	
#
1











����
�
!
����rCc0@s:eZdZUejejejejhZej	ej
ejhZe�
e��
ejh�Zejdeje�iZdZdejBed<dZdZdZeded<e�ZdZdZdZ eded<dddddde!j"ddd	ddddddd
ddd	dd�de#d
ede$de%dBde&e#dBde'de(dBde)dBde!j*de#e+BdBde+dBde+de,j-dBde.ddBdedBde)dBde/dBdedd e0e+Be1Bd!e%dBd"e2d#dBd$e+d%e#dBf.d&d'�Z3dwd(e4d)dfd*d+�Z5d)e6dBfd,d-�Z7e8d)e9dfd.d/��Z:e8d)edfd0d1��Z;e;j<dxd3d1��Z;d)e+fd4d5�Z=e8d)e>d6e+e1ffd7d8��Z?e8d)e@fd9d:��ZAe8d)e#fd;d<��ZBe8d)e6dBfd=d>��ZCe8d)ejeDd?Bfd@dA��ZEeEj<dBe'd)dfdCdA��ZEe8d)eFfdDdE��ZGe8dydFdG��ZHd
ed)dfdHdI�ZIde!j*e#Bd)dfdJdK�ZJde%dBd)dfdLdM�ZKde&e#dBd)dfdNdO�ZLde(dBd)dfdPdQ�ZMde'd)dfdRdS�ZNdzdTdU�ZOd{de)dBd$e+d)dfdVdW�ZPd|dYe'dZe6d)dfd[d\�ZQdYe'd)dfd]d^�ZRdYe'd)dfd_d`�ZSd{dae+d)dfdbdc�ZTdedBde)dBd!e%dBd)dfddde�ZU	dwd2eVdfdgdhe6dBd)dfdidj�ZWd}dkdl�ZXdzdmdn�ZYdzdodp�ZZde#d
edqe[d)dfdrds�Z\de#d
eddtd)dfdudv�Z]dS)~rBz*/*Nr�r��_ClientRequest__writerZGETzCIMultiDict[None]�_skip_auto_headersFT)r�rd�skip_auto_headers�datar��authr��compress�chunked�	expect100r��response_classr�r�r�r�r��
proxy_headersr��	trust_envr�rbrar�rdr\r]r�r^r�r_r`rar�rbrCr�r�r�r�rFr�rcr�rHrdr�cCs�|
durt��}
t�|�}rtd|�d|���d���t|�tus&J|��|dur4t|�tus4J|��tr<|dus<J�||_	|rF|�
|�}||_|jrQ|�
d�n||_|��|_||_|
|_|
|_d|_|durlt}n|}||_|durw|nt�|_|dur�|nd|_||_|
��r�t�t�d��|_ |�!|	�|�"|�|�#|�|�$|�|�%|�|�&|�|�'||�|�(|||�|�)|�|dus�|j|j*vr�|�+�|�,|�|dur�g|_-dS||_-dS)Nz+Method cannot contain non-token characters z (found at least �)Tr).r�Zget_event_loop�_CONTAINS_CONTROL_CHAR_RE�searchrp�grouprXrrr�Zextend_query�original_urlr�r�ra�upperrbr`r_r��lengthrCrbr.r��_sslr�r�r�r�r�r�r��update_version�update_host�update_headers�update_auto_headers�update_cookies�update_content_encoding�update_auth�update_proxy�update_body_from_data�GET_METHODS�update_transfer_encoding�update_expect_continuer�)rsrbrar�rdr\r]r�r^r�r_r`rar�rbr�r�r�r�r�rcr�rdr�r�Zreal_response_classrRrRrSrtSsZ��









zClientRequest.__init__r�rJcCs
d|_dSrv�rZr�rRrRrSr��s
zClientRequest.__reset_writercCs<tj|jvrdS|jtj}t�|�std|����t|�S)z�Extract and validate Content-Length header value.

        Returns parsed Content-Length value or None if not set.
        Raises ValueError if header exists but cannot be parsed as an integer.
        NzInvalid Content-Length header: )r�CONTENT_LENGTHrd�
_DIGITS_RE�	fullmatchrpr�)rsZcontent_length_hdrrRrRrS�_get_content_length�s
z!ClientRequest._get_content_lengthcCs|jpt�Srv)r[rrwrRrRrSr\�szClientRequest.skip_auto_headerscCrurvryrwrRrRrSr��rxzClientRequest._writerr�cCs.|jdur|j�|j�||_|�|j�dSrv)rZr��_ClientRequest__reset_writerr�r�rRrRrSr��s
cCs|jjtvSrv)ra�scheme�_SSL_SCHEMESrwrRrRrSr��szClientRequest.is_sslrAcCrurv)rlrwrRrRrSr��rxzClientRequest.sslcCsX|j}rtt|����}nd}|j}t�t|jpd|j|j	t
v|j|j|j
||jf�S)Nr8)rc�hashrf�itemsrargr��raw_hostr�rr�rlr�r�r�)rsrc�hrarRrRrS�connection_key�s 
��zClientRequest.connection_keycCs|jj}|dus
J�|Srv)rar�)rs�retrRrRrSr�szClientRequest.hostcCs|jjSrv)rar�rwrRrRrSr��szClientRequest.port�cCs
|jpdS)z
Request body.r�)r�rwrRrRrS�body�s
zClientRequest.bodyrcCs0|jdurt|jdd�|j��|�|�dS)a�Set request body with warning for non-autoclose payloads.

        WARNING: This setter must be called from within an event loop and is not
        thread-safe. Setting body outside of an event loop may raise RuntimeError
        when closing file-based payloads.

        DEPRECATED: Direct assignment to body is deprecated and will be removed
        in a future version. Use await update_body() instead for proper resource
        management.
        Nr�r�)r�r�Z_close�_update_body)rsrrRrRrSr��s


cCs$t|j�}t�t|j|j||jf�Srv)rrdrfrgrDrarbri)rsrdrRrRrSr�s
�zClientRequest.request_infocCru)z�Return the ClientSession instance.

        This property provides access to the ClientSession that initiated
        this request, allowing middleware to make additional requests
        using the same session.
        )r�rwrRrRrSr�szClientRequest.sessioncCs:|jst|��|js
|jrt|jpd|jpd�|_dSdS)z8Update destination host, port and connection type (ssl).r8N)r�r%Zraw_userZraw_passwordr/�user�passwordr^)rsrarRrRrSrns
�zClientRequest.update_hostcCsjt|t�r0dd�|�dd�D�}zt�t|d�t|d��}Wnty/td|���d�w||_dS)zdConvert request version to two elements tuple.

        parser HTTP version '1.1' => (1, 1)
        cSsg|]}|���qSrR)rM)r��partrRrRrS�
<listcomp>+sz0ClientRequest.update_version.<locals>.<listcomp>�.rrz#Can not parse http version number: N)r�r^rrr6r�rpr�)rsr��vrRrRrSrm%s
 ���
zClientRequest.update_versioncCs~t�|_|jj}|dusJ�||jtj<|sdSt|ttt	f�r$|�
�}|D]\}}|tjvr5||j|<q&|j�||�q&dS)zUpdate request headers.N)
rrdraZhost_port_subcomponentrZHOSTr��dictrrr�ZHOST_ALLr)rsrdrrrrRrRrSro4s
�zClientRequest.update_headerscCs�|durtdd�t|�D��|_|j��}|�|j�n|j}|j��D]
\}}||vr1||j|<q$tj	|vr?t
|jtj	<dSdS)Ncss�|]}|dfVqdSrvrR)r��hdrrRrRrSr�Or�z4ClientRequest.update_auto_headers.<locals>.<genexpr>)r�sortedr[rd�copy�extend�DEFAULT_HEADERSr�rZ
USER_AGENTr5)rsr\Zused_headersr�r
rRrRrSrpMs
�

�
�z!ClientRequest.update_auto_headerscCs�|sdSt�}tj|jvr|�t|j�tjd���|jtj=t|t�r)|�	�}n|}|D]\}}t|t
�r=t|�||<q-|||<q-|jddd��
�|jtj<dS)zUpdate request cookies header.Nr8r)�header�sep)r	rZCOOKIErdr�rror�rr�rr�outputrM)rsr��cZiter_cookiesrBrrRrRrSrq`s




zClientRequest.update_cookiescCsb|sd|_dS|j�tj�r|jrtd��dS|jr/t|jt�s#d|_|j|jtj<d|_dSdS)zSet request content encoding.Nz9compress can not be set if Content-Encoding header is setrLT)	r_rdrorZCONTENT_ENCODINGrpr�r^r`)rsr]rRrRrSrrxs��
�z%ClientRequest.update_content_encodingcCs\|j�tjd���}d|vr|jrtd��dS|jr,tj|jvr$td��d|jtj<dSdS)z!Analyze transfer-encoding header.r8r`zDchunked can not be set if "Transfer-Encoding: chunked" header is setz6chunked can not be set if Content-Length header is setN)rdror�TRANSFER_ENCODINGr<r`rprz)rs�terRrRrSrw�s����z&ClientRequest.update_transfer_encodingcCsB|dur|j}|dur
dSt|tj�std��|��|jtj<dS)zSet basic auth.Nz%BasicAuth() tuple is required instead)	r^r�rr,r�r�rdrZ
AUTHORIZATION)rsr^rdrRrRrSrs�szClientRequest.update_authr�r��_stacklevelc
Cs*|jdurt|j|d�|dur*d|_|j|jvr(|js(tj|jvr(d|jtj<dSt|t	�r2|�n|}z
t
jj|dd�}Wnt
j
yMt	|��}Ynw||_|jsmtj|jvrm|j}durjt|�|jtj<nd|_|jsrJ�|j}|j}|j��D]\}}	||vs�|dur�||vr�q}|	||<q}dS)zUpdate request body from data.Nr��0)ZdispositionT)r�r�rbrvr`rrzrdr�r)rZPAYLOAD_REGISTRYror?�sizer^r[r�)
rsr�r�Z
maybe_payloadZbody_payloadr�rdZskip_headersrrrRrRrSru�s:
��

�z#ClientRequest.update_body_from_datacCsdtj|jvr|jtj=|jrtj|jvr|jtj=|j|dd�|dus*|j|jvr0|��dSdS)z/Update request body after its already been set.�)r�N)	rrzrdr`r�rurbrvrw�rsr�rRrRrSr��s

�zClientRequest._update_bodyc�s*�|jdur|j��IdH|�|�dS)ac	
        Update request body and close previous payload if needed.

        This method safely updates the request body by first closing any existing
        payload to prevent resource leaks, then setting the new body.

        IMPORTANT: Always use this method instead of setting request.body directly.
        Direct assignment to request.body will leak resources if the previous body
        contains file handles, streams, or other resources that need cleanup.

        Args:
            body: The new body content. Can be:
                - bytes/bytearray: Raw binary data
                - str: Text data (will be encoded using charset from Content-Type)
                - FormData: Form data that will be encoded as multipart/form-data
                - Payload: A pre-configured payload object
                - AsyncIterable: An async iterable of bytes chunks
                - File-like object: Will be read and sent as binary data
                - None: Clears the body

        Usage:
            # CORRECT: Use update_body
            await request.update_body(b"new request data")

            # WRONG: Don't set body directly
            # request.body = b"new request data"  # This will leak resources!

            # Update with form data
            form_data = FormData()
            form_data.add_field('field', 'value')
            await request.update_body(form_data)

            # Clear body
            await request.update_body(None)

        Note:
            This method is async because it may need to close file handles or
            other resources associated with the previous payload. Always await
            this method to ensure proper cleanup.

        Warning:
            Setting request.body directly is highly discouraged and can lead to:
            - Resource leaks (unclosed file handles, streams)
            - Memory leaks (unreleased buffers)
            - Unexpected behavior with streaming payloads

            It is not recommended to change the payload type in middleware. If the
            body was already set (e.g., as bytes), it's best to keep the same type
            rather than converting it (e.g., to str) as this may result in unexpected
            behavior.

        See Also:
            - update_body_from_data: Synchronous body update without cleanup
            - body property: Direct body access (STRONGLY DISCOURAGED)

        N)r�r"r�r�rRrRrS�update_body�s�
:zClientRequest.update_body�expectcCsN|r	d|jtj<ntj|jvr|jtj��dkrd}|r%|j��|_dSdS)Nz100-continueT)rdrZEXPECTr<r�r�r�)rsr�rRrRrSrx"s�z$ClientRequest.update_expect_continuecCsd||_|durd|_d|_dS|rt|tj�std��||_|dur-t|ttf�s-t	|�}||_dS)Nz,proxy_auth must be None or BasicAuth() tuple)
r�r�rcr�rr,rprrr)rsr�r�rcrRrRrSrt.s
�
zClientRequest.update_proxy�connrG�content_lengthc
�s<�|jdur|��|��IdH|jIdH|j}|dus J�z|jdur0|j�||�IdHWn_tyd}z'|}|jdupFt|t	j
�}|rSt|jd|j���}t
|||�WYd}~dSd}~wt	jyp|���ty�}zt
|td|�d|���|�WYd}~dSd}~ww|��IdH|��dS)a:
        Write the request body to the connection stream.

        This method handles writing different types of request bodies:
        1. Payload objects (using their specialized write_with_length method)
        2. Bytes/bytearray objects
        3. Iterable body content

        Args:
            writer: The stream writer to write the body to
            conn: The connection being used for this request
            content_length: Optional maximum number of bytes to write from the body
                            (None means write the entire body)

        The method properly handles:
        - Waiting for 100-Continue responses if required
        - Content length constraints for chunked encoding
        - Error handling for network issues, cancellation, and other exceptions
        - Signaling EOF and timeout management

        Raises:
            ClientOSError: When there's an OS-level error writing the body
            ClientConnectionError: When there's a general connection error
            asyncio.CancelledError: When the operation is cancelled

        NzCan not write request body for z4Failed to send bytes into the underlying connection z: )r�Zsend_headersZdrainrr�Zwrite_with_length�OSError�errnor�r��TimeoutErrorr"rar3r*r"�	Exceptionr!�	write_eof�
start_timeout)rsr�r�r�rZunderlying_excZreraised_excZexc_is_not_timeoutrRrRrS�write_bytesDsT�
!
��
��������zClientRequest.write_bytesc�sJ�|jtjkr|jj}|dusJ�|�d|jj��}n|jr(|��s(t|j�}n|jj	}|j
}|dus5J�t||j|j
rFt�|j|j|j�nd|j
rTt�|j|j|j�ndd�}|jra|�|j�|jdurj|��|j|jvr�|jdus{tj|jvr�tj|jvr�d|jtj<|j}tj|jvr�|jjr�|tkr�d|jtj<n
|tkr�d|jtj<|j�d|�d|j �d|j!��}|�"||j�IdH|j#s�|j$dus�|j%r�|�&|||�'��}t(j)d	kr�t*j+||jd
d�}	n|j�,|�}	|	�-�r�d}	n|	|_.n
|�/�|�0�d}	|j1}
|
du�sJ�|
|j|j2|	|j$|j3|j4|j
|j|j5|d�
|_6|j6S)
N�:)Z
on_chunk_sentZon_headers_sentzapplication/octet-streamr"z
keep-aliver�z HTTP/r�)r��T)r�Zeager_start)r�r�r�r�r�r�r�r�)7rbrZMETH_CONNECTraZhost_subcomponentr�r�r�r^Zraw_path_qsrr9r�r��	functools�partial�_on_chunk_request_sent�_on_headers_request_sentr_Zenable_compressionr`Zenable_chunking�POST_METHODSr[r;rdr�Z
CONNECTIONZ
_connectorZforce_closer8r7�major�minorZ
write_headersr�r�Zwriting_pausedr�r}r�r+r�ZTaskZcreate_taskr�r�r�Zset_eofrbrir�r�r��response)rsr�Zconnect_host�pathrr�r�Zstatus_line�coror/rbrRrRrS�send�s�����

� 
�zClientRequest.sendc�sf�|jdur1z	|jIdHWdStjy0tjdkr't��}r*|��r-�YdSYdSYdSwdSr()rZr�r*r�r+r,r-r.rRrRrSr"�s�


�����zClientRequest.closecCs:|jdur|j��s|j��|j�|j�d|_dSdSrv)rZr�r!r2r�r~rwrRrRrS�	terminates



�zClientRequest.terminate�chunkc��&�|jD]}|�|||�IdHqdSrv)r�Zsend_request_chunk_sent)rsrbrar�r7rRrRrSr�
s�
�z$ClientRequest._on_chunk_request_sentzCIMultiDict[str]c�r�rv)r�Zsend_request_headers)rsrbrardr7rRrRrSr�s�
�z&ClientRequest._on_headers_request_sentrv)r�r�rJN)rJrFrT)F)r�)r�rGrJrC)^r[r\r]rZMETH_GETZ	METH_HEADZMETH_OPTIONSZ
METH_TRACErvZ
METH_PATCHZ	METH_POSTZMETH_PUTr��unionZMETH_DELETEZALL_METHODSZACCEPTZACCEPT_ENCODINGrTr�r�r�Payloadr_r^r�rZrrrarbr�r[rr8r^r?r>rr
r=r,r6r�r�rWrXr+rArErVrtrXr~r�r}r�rr\r�rYr�rr�r�r�rr�rr�rDr�r�rnrmrorprqrrrwrsrur�r�rxrtr r�r�r"r�r�r�r�rRrRrRrSrB/s8
�������
��	�
��
�
���
�����
��
��
�O
	

)>���
�����
�
R
d
����rB)r�)}r�r@r=r�r�rr�r�r��collections.abcrrr�hashlibrrrZhttp.cookiesrr	�typesr
r�typingrr
rrrr�attrZ	multidictrrrrZyarlrr8rrrrrZ_cookie_helpersrrr�abcr Zclient_exceptionsr!r"r#r$r%r&Zcompression_utilsr'r(Zformdatar)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9Zstreamsr:Ztypedefsr;r<r=r>r?r@r�rA�ImportErrorrX�__all__�clientrFZ	connectorrG�tracingrHr4�compilerfr��ASCIIr{r^rT�srWr`rDrEr�rXr�r�r��	frozensetr�r�r�r�r�r�rCrBrRrRrRrS�<module>s�  4
 	�


 ����
�7
��
�