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__/connector.cpython-310.pyc
o

;j��@sRddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
ddlmZm
Z
mZmZddlmZddlmZddlmZmZmZddlmZddlmZdd	lmZmZmZm Z m!Z!m"Z"ddl#Z#dd
l#m$Z$m%Z%ddl&m'Z'm(Z(dd
l)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8ddl9m:Z:ddl;m<Z<m=Z=m>Z>ddl(m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFddlGmHZHddlImJZJejKdkr�ddlmLZLne!eMeNddfZLer�ddlOZOeOjPZPnz	ddlOZOeOjPZPWneQ�ydZOeRZPYnweSdh�ZTeSddh�ZUeSddh�ZVeUeTBZWeWeVBZXdejKk�o&dkn�p.ejKdkZYd ZZe�rFdd!l[m\Z\dd"l;m]Z]dd#l^m_Z_Gd$d%�d%�Z`d&eaeeRd'dfd(d)�ZbGd*d+�d+�ZcGd,d-�d-ec�ZdGd.d/�d/�ZeGd0d1�d1�ZfGd2d3�d3�Zgd4ehd'ePfd5d6�Zieid7�Zjeid8�ZkGd9d:�d:ef�ZlGd;d<�d<ef�ZmGd=d>�d>ef�ZndS)?�N)�OrderedDict�defaultdict�deque)�	Awaitable�Callable�Iterator�Sequence)�suppress)�
HTTPStatus)�chain�cycle�islice)�	monotonic)�
TracebackType)�
TYPE_CHECKING�Any�Literal�Optional�Union�cast)�AddrInfoType�SocketFactoryType�)�hdrs�helpers)�AbstractResolver�
ResolveResult)�ClientConnectionError�ClientConnectorCertificateError�ClientConnectorDNSError�ClientConnectorError�ClientConnectorSSLError�ClientHttpProxyError�ClientProxyConnectionError�InvalidUrlClientError�ServerFingerprintMismatch�UnixClientConnectorError�cert_errors�
ssl_errors)�ResponseHandler)�
ClientRequest�Fingerprint�_merge_ssl_params)�	_SENTINEL�ceil_timeout�is_canonical_ipv4_address�
is_ip_address�noop�sentinel�
set_exception�
set_result)�
client_logger)�DefaultResolver���)�Bufferzmemoryview[int]zmemoryview[bytes]��http�https�ws�wss)r8�
r)r8r@r)r8r9�)�
BaseConnector�TCPConnector�
UnixConnector�NamedPipeConnectorrr)�
ClientTimeout)�
ConnectionKey)�Tracec@s>eZdZdZdeeddfdd�Zdefdd�Zdd	d
�ZdS)�_DeprecationWaiter��
_awaitable�_awaited�	awaitable�returnNcCs||_d|_dS�NFrJ)�selfrM�rQ�E/opt/saltstack/salt/lib/python3.10/site-packages/aiohttp/connector.py�__init__h�
z_DeprecationWaiter.__init__cCsd|_|j��S)NT)rLrK�	__await__�rPrQrQrRrUlrTz_DeprecationWaiter.__await__cCs|jst�dt�dSdS)NzDConnector.close() is a coroutine, please use await connector.close())rL�warnings�warn�DeprecationWarningrVrQrQrR�__del__ps��z_DeprecationWaiter.__del__�rNN)	�__name__�
__module__�__qualname__�	__slots__rrrSrUrZrQrQrQrRrIes
rI�waitersrNc�s<�tj|ddi�IdH}|D]
}t|t�rt�d|�qdS)z'Wait for all waiters to finish closing.Zreturn_exceptionsTNz!Error while closing connector: %r)�asyncioZgather�
isinstance�	Exceptionr5�debug)r`�results�resrQrQrR�_wait_for_closeys�
��rgc
@s�eZdZdZdddddedejddf
d	d
�Zdefdd�Z	e
fd
eddfdd�Zde
dfdd�Zedejfdd��ZedejdBfdd��ZededBfdd��Zdegdfddfdd�Zd$dd�Zd$dd�Zd$d d!�Zedefd"d#��ZdS)%�
ConnectionN�	connectorrB�keyrG�protocol�looprNcCs@||_||_||_||_g|_|��rt�t�	d��|_
dSdS)Nr)�_key�
_connector�_loop�	_protocol�
_callbacks�	get_debug�	traceback�
extract_stack�sys�	_getframe�_source_traceback)rPrirjrkrlrQrQrRrS�s�zConnection.__init__cCsd|j�d�S)NzConnection<�>)rmrVrQrQrR�__repr__�szConnection.__repr__�	_warningscCs�|jdur?d|i}|jd|��tfi|��|j��rdS|jj|j|jdd�|dd�}|jdur7|j|d<|j�	|�dSdS)N�sourcezUnclosed connection T��should_closezUnclosed connection)Zclient_connection�message�source_traceback)
rprX�ResourceWarningro�	is_closedrn�_releasermrw�call_exception_handler)rPrz�kwargs�contextrQrQrRrZ�s




�zConnection.__del__TcC�dS)z9Force subclasses to not be falsy, to make checks simpler.TrQrVrQrQrR�__bool__�szConnection.__bool__cCstjdtdd�|jS)Nz%connector.loop property is deprecated���
stacklevel)rWrXrYrorVrQrQrRrl�s�zConnection.loopcCs|jdurdS|jjS�N)rp�	transportrVrQrQrRr��s
zConnection.transportcC�|jSr�)rprVrQrQrRrk�szConnection.protocol�callbackcCs|dur|j�|�dSdSr�)rq�append)rPr�rQrQrR�add_callback�s�zConnection.add_callbackc	CsR|jdd�g}|_|D]}tt��|�Wd�n1s!wYq
dSr�)rqr	rc)rPZ	callbacks�cbrQrQrR�_notify_release�s
���zConnection._notify_releasecCs6|��|jdur|jj|j|jdd�d|_dSdS)NTr|�r�rprnr�rmrVrQrQrR�close�s


�zConnection.closecCs2|��|jdur|j�|j|j�d|_dSdSr�r�rVrQrQrR�release�s


�zConnection.releasecCs|jdup
|j��Sr�)rp�is_connectedrVrQrQrR�closed�szConnection.closedr[)r\r]r^rwr)ra�AbstractEventLooprS�strryrWrrZrr��propertyrl�	Transportr�rkrr�r�r�r��boolr�rQrQrQrRrh�s8����
�


rhc@seZdZdZddd�ZdS)�_ConnectTunnelConnectiona�Special connection wrapper for CONNECT tunnels that must never be pooled.

    This connection wraps the proxy connection that will be upgraded with TLS.
    It must never be released to the pool because:
    1. Its 'closed' future will never complete, causing session.close() to hang
    2. It represents an intermediate state, not a reusable connection
    3. The real connection (with TLS) will be created separately
    rNNcCr�)aaDo nothing - don't pool or close the connection.

        These connections are an intermediate state during the CONNECT tunnel
        setup and will be cleaned up naturally after the TLS upgrade. If they
        were to be pooled, they would never be properly closed, causing
        session.close() to wait forever for their 'closed' future.
        NrQrVrQrQrRr���z _ConnectTunnelConnection.releaser[)r\r]r^�__doc__r�rQrQrQrRr��s	r�c@sDeZdZdZdZdejedBddfdd�Zddd	�Z	dd
d�Z
dS)
�_TransportPlaceholderz.placeholder for BaseConnector.connect function�r�r��
closed_futureNrNcCs||_d|_dS)z)Initialize a placeholder for a transport.Nr�)rPr�rQrQrRrS�s
z_TransportPlaceholder.__init__cCr�)zClose the placeholder.NrQrVrQrQrRr��r�z_TransportPlaceholder.closecCr�)z%Abort the placeholder (does nothing).NrQrVrQrQrR�abort�r�z_TransportPlaceholder.abortr[)r\r]r^r�r_raZFuturercrSr�r�rQrQrQrRr��s
r�c@sHeZdZdZdZdZdZeZe	ddddddd	�d
e
dBeBdede
d
e
dedejdBdeddfdd�Zefdeddfdd�ZdRdd�Zdeddfdd�ZdRdd�Z			dSdeedBdedBd edBddfd!d"�Zedefd#d$��Zede
fd%d&��Zede
fd'd(��ZdTd)d*�ZdTd+d,�Z dd-�d.ede!dfd/d0�Z"dd-�d.ede#e!e
fd1d2�Z$edefd3d4��Z%d5d6de
fd7d8�Z&d9e'de'fd:d;�Z(d9e'd<e#d=d>d?de)fd@dA�Z*d5d6d<e#d=ddfdBdC�Z+d5d6d<e#d=de)dBfdDdE�Z,dTdFdG�Z-d5d6dHe.ddfdIdJ�Z/ddK�d5d6dLe.dMeddfdNdO�Z0d9e'd<e#d=d>d?de.fdPdQ�Z1dS)UrBa\Base connector class.

    keepalive_timeout - (optional) Keep-alive timeout.
    force_close - Set to True to force close and do reconnect
        after each request (and between redirects).
    limit - The total number of simultaneous connections.
    limit_per_host - Number of simultaneous connections to one host.
    enable_cleanup_closed - Enables clean-up closed ssl transports.
                            Disabled by default.
    timeout_ceil_threshold - Trigger ceiling of timeout values when
                             it's above timeout_ceil_threshold.
    loop - Optional event loop.
    TNg@F�dr���keepalive_timeout�force_close�limit�limit_per_host�enable_cleanup_closedrl�timeout_ceil_thresholdr�r�r�r�r�rlr�rNcCs|r|dur|turtd��n|turd}|pt��}||_d|_|��r.t�t	�
d��|_tt
�|_||_||_t�|_tt�|_tt|�|_||_tt�|_||_tjt|d�|_d|_d|_ |rst!sst"j#dt	j$��t%dd�d}||_&g|_'|�(�|_)|j)�*d�|�+�dS)	Nz6keepalive_timeout cannot be set if force_close is Trueg.@Fr�rlzoenable_cleanup_closed ignored because https://github.com/python/cpython/pull/118960 is fixed in Python version r�r�),r2�
ValueErrorra�get_running_loop�_timeout_ceil_threshold�_closedrrrsrtrurvrwrr�_conns�_limit�_limit_per_host�set�	_acquired�_acquired_per_hostr�float�_keepalive_timeout�_force_closer�_waitersro�	functools�partialr)�_factory�_cleanup_handle�_cleanup_closed_handle�NEEDS_CLEANUP_CLOSEDrWrX�version_inforY�_cleanup_closed_disabled�_cleanup_closed_transports�
create_future�_placeholder_futurer4�_cleanup_closed)rPr�r�r�r�r�rlr�rQrQrRrSsV��������zBaseConnector.__init__rzcCs�|jrdS|js
dSdd�|j��D�}|��d|i}|jd|��tfi|��||dd�}|jdur9|j|d<|j�|�dS)NcSsg|]}t|��qSrQ)�repr)�.0�crQrQrR�
<listcomp>hsz)BaseConnector.__del__.<locals>.<listcomp>r{zUnclosed connector zUnclosed connector)ri�connectionsr~r)	r�r��values�_closerXr�rwror�)rPrz�connsr�r�rQrQrRrZbs�

zBaseConnector.__del__cCst�dt�|S)NzH"with Connector():" is deprecated, use "async with Connector():" instead)rWrXrYrVrQrQrR�	__enter__ws
�zBaseConnector.__enter__�exccGs|��dSr�)r�)rPr�rQrQrR�__exit__szBaseConnector.__exit__c�s�|Sr�rQrVrQrQrR�
__aenter__�s�zBaseConnector.__aenter__�exc_type�	exc_value�
exc_tracebackc�s�|��IdHdSr�)r�)rPr�r�r�rQrQrR�	__aexit__�s�zBaseConnector.__aexit__cCr�)z1Ultimately close connection on releasing if True.)r�rVrQrQrRr���zBaseConnector.force_closecCr�)z�The total number for simultaneous connections.

        If limit is 0 the connector has no limit.
        The default limit size is 100.
        )r�rVrQrQrRr���zBaseConnector.limitcCr�)z�The limit for simultaneous connections to the same endpoint.

        Endpoints are the same if they are have equal
        (host, port, is_ssl) triple.
        )r�rVrQrQrRr��r�zBaseConnector.limit_per_hostcCs�|jr|j��d|_t�}|j}|jr^tt�}||}|j��D]9\}}t�}|D])\}}	|��r@|	|dkr@|�	||	f�q*|j
}
|��|jsS|j
rS|j�	|
�q*|rZ|||<q!||_|jrptj|d||j|jd�|_dSdS)zCleanup unused transports.Nr�_cleanup�r�)r��cancelrr�r�rr�itemsr�r�r�r�r��is_sslr�r�weakref_handleror�)rP�now�timeoutr�Zdeadlinerjr��alive�protoZuse_timer�rQrQrRr��s@
����zBaseConnector._cleanupcCs\|jr|j��|jD]
}|dur|��qg|_|js,tj|d|j|j|j	d�|_dSdS)z~Double confirmation for transport close.

        Some broken ssl servers may leave socket open without proper close.
        Nr�r�)
r�r�r�r�r�rr��_cleanup_closed_periodror�)rPr�rQrQrRr��s 

���zBaseConnector._cleanup_closed��	abort_sslr�cCsZ|j|d�}s
tt��St|�}tjdkr#tj||jdd�}t|�S|j�	|�}t|�S)aClose all opened transports.

        :param abort_ssl: If True, SSL connections will be aborted immediately
                         without performing the shutdown handshake. This provides
                         faster cleanup at the cost of less graceful disconnection.
        r�r7T�rlZeager_start)
r�rIr1rgrur�ra�Taskro�create_task)rPr�r`�coroZtaskrQrQrRr��s

�zBaseConnector.closec

Csg}|jr|Sd|_z�|j��r>|W|j��|j��|j��D]}|D]}|��q%q!|j��d|_	|j
��d|_S|j	rF|j	��|jrN|j��|j��D])}|D]$\}}|rm|jrm|j�
d�durm|��n|��|j}r{|�|�qWqS|jD]"}|r�|jr�|j�
d�dur�|��n|��|j}r�|�|�q�|j
D]
}	|	dur�|	��q�|W|j��|j��|j��D]}|D]}|��q�q�|j��d|_	|j
��d|_S|j��|j��|j��D]}|D]}|��q�q�|j��d|_	|j
��d|_w)NT�
sslcontext)r�ror�r��clearr�r�r�r�r�r�r�r��get_extra_infor�r�r�r�)
rPr�r`�
keyed_waitersZkeyed_waiter�datar��_r�r�rQrQrRr��s�

*

�

�

��


��
��


�
�


�


�

�

zBaseConnector._closecCr�)z;Is connector closed.

        A readonly property.
        )r�rVrQrQrRr�4szBaseConnector.closedrjrGcCs\d}|jr|jt|j�}dkr|S|j}r,|j�|�}r&|t|�8}||kr,|S|S)z�
        Return number of available connections.

        The limit, limit_per_host and the connection key are taken into account.

        If it returns less than 1 means that there are no connections
        available.
        rr)r��lenr�r�r��get)rPrjZtotal_remainZhost_remainZacquiredrQrQrR�_available_connections<s
z$BaseConnector._available_connections�reqcCs�|j}|dus	J�i}|jdur|j}|jtj|tj<ttj|||j|j|j	d�}|j�
tjd�}|durH|��sB||jtj
<|S||jtj
<|S)znSet Proxy-Authorization header for non-SSL proxy requests and builds the proxy request for SSL proxy requests.N)�headers�authrl�ssl)�proxyZ
proxy_headersr�rZHOSTr*ZMETH_GET�
proxy_authror��popZ
AUTHORIZATIONr�ZPROXY_AUTHORIZATION)rPr��urlr��	proxy_reqr�rQrQrR�-_update_proxy_auth_header_and_build_proxy_reqUs*
��z;BaseConnector._update_proxy_auth_header_and_build_proxy_req�tracesrHr�rFc
	�s��|j}|�||�IdH}dur|jr|�|�|St|j|j�4IdH��|�|�dkrX|�||�IdH|�||�IdH}durX|jrL|�|�|Wd�IdHSt	t
t|j��}|j
�|�|jrq|j|�|�z(|r�|D]	}|��IdHqv|�|||�IdH}|r�|D]	}|��IdHq�Wnty�|�||��w|jr�|��td��Wd�IdHn1IdHs�wY|j
�|�|j
�|�|jr�|j|}	|	�|�|	�|�t||||j�S)z'Get from pool or create new connection.NrzConnector is closed.)�connection_key�_getr�r�r.�connect�ceil_thresholdr��_wait_for_available_connectionrr)r�r�r��addr�r�Zsend_connection_create_start�_create_connectionZsend_connection_create_end�
BaseException�_release_acquiredr�r�r�removerhro)
rPr�r�r�rj�conn�placeholder�tracer�Zacquired_per_hostrQrQrRrosX�

�
���
(�'


zBaseConnector.connectc
�s��d}	|j��}|j|}d||<|r|j|dd�z4|r*|D]	}|��IdHq |IdH|r=|D]	}|��IdHq3W|�|d�|j�|d�sO|j|=n|�|d�|j�|d�sa|j|=w|�|�dkrkdS|d7}q)z&Wait for an available connection slot.rTNF��lastr)	ror�r��move_to_endZsend_connection_queued_startZsend_connection_queued_endr�r�r�)rPrjr��attempts�futr�rrQrQrRr�s8�



���
�z,BaseConnector._wait_for_available_connectionc		�s��|j�|�}dur
dSt�}|ru|��\}}|��r`|||jkr`|s)|j|=|j�|�|jr:|j	|�|�|rX|D]}z	|�
�IdHWq>tyW|�||��wt
||||j�S|j}|��|jss|jrs|j�|�|s|j|=dS)znGet next reusable connection for the key or None.

        The connection will be marked as acquired.
        N)r�r�r�popleftr�r�r�rr�r�Zsend_connection_reuseconnrrrhror�r�r�r�r�r�)	rPrjr�r��t1r��t0rr�rQrQrRr�s8���zBaseConnector._getcCsv|jsdSt|j�}t�|�|D]'}|�|�dkrq|j|}|r8|jdd�\}}|��s6|�d�dS|s"qdS)z�
        Iterates over all waiters until one to be released is found.

        The one to be released is not finished and
        belongs to a host that has available connections.
        NrFr)r��list�random�shuffler��popitem�doner4)rPZqueuesrjr`�waiterr�rQrQrR�_release_waiter�s 



���zBaseConnector._release_waiterr�cCsN|jrdS|j�|�|jr!|j�|�}r!|�|�|s!|j|=|��dS)zRelease acquired connection.N)r�r��discardr�r�r�r)rPrjr�r�rQrQrRrs
zBaseConnector._release_acquiredr|rkr}cCs�|jrdS|�||�|js|s|jr(|j}|��|jr&|js&|j�	|�dS|j
|�	|t�f�|jdurHt
j|d|j|j|jd�|_dSdS)Nr�r�)r�rr�r}r�r�r�r�r�r�r�rr�rr�r�ror�)rPrjrkr}r�rQrQrRr�%s&
��zBaseConnector._releasec�s�t��r�)�NotImplementedError)rPr�r�r�rQrQrRrEs�z BaseConnector._create_connection)rNrB)NNNr[)2r\r]r^r�r�rwr��HIGH_LEVEL_SCHEMA_SET�allowed_protocol_schema_setr2�objectr�r��intrar�rSrWrrZr�r�r��typerrr�r�r�r�r�r�r�rr�rr�r�r�r*r�rhrrrrr)rr�rrQrQrQrRrB�s��
������	�

�M

�
���
�

' >�
����
�;��
�*��
�
*����
� ����rBc@s�eZdZddedBdeddfdd�Zdedefd	d
�Zde	e
efdeeddfd
d�Z
de	e
efddfdd�Zddd�Zde	e
efdeefdd�Zde	e
efdefdd�ZdS)�_DNSCacheTableN���ttl�max_sizerNcCst�|_i|_||_||_dSr�)r�	_addrs_rr�_timestamps�_ttl�	_max_size)rPr$r%rQrQrRrSLs
�
z_DNSCacheTable.__init__�hostcCs
||jvSr�)r&)rPr*rQrQrR�__contains__Ts
z_DNSCacheTable.__contains__rj�addrscCsz||jvr|j�|�t|�t|�f|j|<|jdur!t�|j|<t|j�|jkr;|jjdd�\}}|j�	|d�dSdS)NFr)
r&rrr�r(rr'r)rr�)rPrjr,Z
oldest_keyr�rQrQrRrWs

�z_DNSCacheTable.addcCs |j�|d�|j�|d�dSr�)r&r�r'�rPrjrQrQrRrdsz_DNSCacheTable.removecCs|j��|j��dSr�)r&r�r'rVrQrQrRr�hs
z_DNSCacheTable.clearcCs4|j|\}}tt||��}t|�|j�|�|Sr�)r&rr
�nextr)rPrjrl�lengthr,rQrQrR�
next_addrsls
z_DNSCacheTable.next_addrscCs$|jdurdS|j||jt�kSrO)r(r'rr-rQrQrR�expiredts
z_DNSCacheTable.expired)Nr#r[)r\r]r^r�r rSrr�r+�tupler�rrrrr�r0r1rQrQrQrRr"Ks"
r"�verifiedcCsztdurdS|r
t��}n)t�tj�}|jtjO_|jtjO_d|_tj|_	|jtj
O_|��|�d�|S)z�Create SSL context.

    This method is not async-friendly and should be called from a thread
    because it will load certificates from disk and do other blocking I/O.
    NF)zhttp/1.1)
r��create_default_context�
SSLContext�PROTOCOL_TLS_CLIENT�options�OP_NO_SSLv2�OP_NO_SSLv3�check_hostname�	CERT_NONE�verify_mode�OP_NO_COMPRESSION�set_default_verify_paths�set_alpn_protocols)r3r�rQrQrR�_make_ssl_context{s

r@TFc,s�eZdZdZeedh�BZdddddejj	dddde
ddd	ddd
ddde
d�d
ededBdede
dBde
dejdedBdeeBeBdeee
fdBdedBddeBeBdede
de
dedejdBdededBde
dBd edBd!edBeBf*�fd"d#�Zdd$�d%ed&eeef�fd'd(�Zdd$�d%ed&df�fd)d*�Zed&e
fd+d,��Zed&efd-d.��Z dbd/edBd0e
dBd&dfd1d2�Z!	dcd/ed0e
d3e"d4dBd&ee#fd5d6�Z$d7eee
fd/ed0e
d8e%d9d3e"d4dBd&ee#fd:d;�Z&d<e'd3ed4d=d>d&e(fd?d@�Z)d<e'd&edBfdAdB�Z*d<e'd&e+dCfdDdE�Z,e-dF�dGe.dHee/d<e'd=d>dIe0e1dJe.d&eej2e(ffdKdL�Z3e-dF�dGe.d<e'd=d>dIe0e1dJe.d&eej2e(ffdMdN�Z4dddPdQ�Z5dedRdS�Z6d&efdTdU�Z7dVej2d<e'd&dfdWdX�Z8e-fdVej2d<e'd=d>dIe0e1d&eej9e(ff
dYdZ�Z:d[ee#d&ee/fd\d]�Z;e-dF�d<e'd3ed4d=d>dIe0e1d&eej2e(ff
d^d_�Z<d<e'd3ed4d=d>d&eej9e(ffd`da�Z=�Z>S)frCu�TCP connector.

    verify_ssl - Set to True to check ssl certifications.
    fingerprint - Pass the binary sha256
        digest of the expected certificate in DER format to verify
        that the certificate the server presents matches. See also
        https://en.wikipedia.org/wiki/HTTP_Public_Key_Pinning
    resolver - Enable DNS lookups and use this
        resolver
    use_dns_cache - Use memory cache for DNS lookups.
    ttl_dns_cache - Max seconds having cached a DNS entry, None forever.
    family - socket address family
    local_addr - local tuple of (host, port) to bind socket to

    keepalive_timeout - (optional) Keep-alive timeout.
    force_close - Set to True to force close and do reconnect
        after each request (and between redirects).
    limit - The total number of simultaneous connections.
    limit_per_host - Number of simultaneous connections to one host.
    enable_cleanup_closed - Enables clean-up closed ssl transports.
                            Disabled by default.
    happy_eyeballs_delay - This is the “Connection Attempt Delay”
                           as defined in RFC 8305. To disable
                           the happy eyeballs algorithm, set to None.
    interleave - “First Address Family Count” as defined in RFC 8305
    loop - Optional event loop.
    socket_factory - A SocketFactoryType function that, if supplied,
                     will be used to create sockets given an
                     AddrInfoType.
    ssl_shutdown_timeout - DEPRECATED. Will be removed in aiohttp 4.0.
                           Grace period for SSL shutdown handshake on TLS
                           connections. Default is 0 seconds (immediate abort).
                           This parameter allowed for a clean SSL shutdown by
                           notifying the remote peer of connection closure,
                           while avoiding excessive delays during connector cleanup.
                           Note: Only takes effect on Python 3.11+.
    ZtcpTN�
r#Fr�rr�g�?)�
verify_ssl�fingerprint�
use_dns_cache�
ttl_dns_cache�dns_cache_max_size�family�ssl_contextr��
local_addr�resolverr�r�r�r�r�rlr��happy_eyeballs_delay�
interleave�socket_factory�ssl_shutdown_timeoutrBrCrDrErFrGrHr�rIrJr�r�r�r�r�rlr�rKrLrMrNc	st�j|||
||||d�t||||�|_||
dur&t|jd�|_d|_n|
|_d|_||_t	||d�|_
i|_||_t
�|	�|_||_||_t�|_||_||turZd|_dStjdtdd	�tjd
kr{|dur{|dkr{tjd|�d�tdd	�||_dS)
Nr�r�TF)r$r%rzSThe ssl_shutdown_timeout parameter is deprecated and will be removed in aiohttp 4.0r�r��r8�zssl_shutdown_timeout=zd is ignored on Python < 3.11; only ssl_shutdown_timeout=0 is supported. The timeout will be ignored.)�superrSr,�_sslr6ro�	_resolver�_resolver_owner�_use_dns_cacher"�
_cached_hosts�_throttle_dns_futures�_family�aiohappyeyeballsZaddr_to_addr_infos�_local_addr_infos�_happy_eyeballs_delay�_interleaver��_resolve_host_tasks�_socket_factoryr2�_ssl_shutdown_timeoutrWrXrYrur��RuntimeWarning)rPrBrCrDrErFrGrHr�rIrJr�r�r�r�r�rlr�rKrLrMrN��	__class__rQrRrS�sZ�
��
�

�
zTCPConnector.__init__r�r�rNcsNt�|j���D]}|��qt�j|d�}|jD]}|��|�|�q|S)zClose all ongoing DNS calls.r�)	r�
from_iterablerWr�r�rQr�r]r�)rPr�rr`�trarQrRr�s

zTCPConnector._closec�s>�t�j|p
|jdkd�IdH|jr|j��IdHdSdS)a�
        Close all opened transports.

        :param abort_ssl: If True, SSL connections will be aborted immediately
                         without performing the shutdown handshake. If False (default),
                         the behavior is determined by ssl_shutdown_timeout:
                         - If ssl_shutdown_timeout=0: connections are aborted
                         - If ssl_shutdown_timeout>0: graceful shutdown is performed
        rr�N)rQr�r_rTrS)rPr�rarQrRr�"s
��zTCPConnector.closecCr�)zSocket family like AF_INET.)rXrVrQrQrRrG1r�zTCPConnector.familycCr�)z%True if local DNS caching is enabled.)rUrVrQrQrRrD6r�zTCPConnector.use_dns_cacher*�portcCsJ|dur|dur|j�||f�dS|dus|durtd��|j��dS)z8Remove specified host/port or clear all dns local cache.Nz5either both host and port or none of them are allowed)rVrr�r�)rPr*rerQrQrR�clear_dns_cache;s
zTCPConnector.clear_dns_cacher�rHc	�s�t|�rd|vrt|�st|d��||||jddd�gS|jsT|r/|D]
}|�|�IdHq$|jr6td��|jj	|||jd�IdH}|rR|D]
}|�
|�IdHqG|S||f}||jvrz|j�|�sz|j�
|�}|rx|D]
}|�|�IdHqm|S||jvr�|j|}|j��}	|�|	�|r�|D]
}|�|�IdHq�z|	IdHW|�|	�n|�|	�w|j�
|�St�|j|<}|�|||||�}
t��}tjdkr�tj|
|d	d
�}n|�|
�}|��s�|j�|�|�|jj�z	t�|�IdHWStj �yddd�}
|�|
��w)z*Resolve host and return list of addresses.�:zis not a canonical IPv4 addressr)�hostnamer*rerGr��flagsNzConnector is closed�rGr7Tr�r�#asyncio.Future[list[ResolveResult]]rNcSs:tttj��
|��Wd�dS1swYdSr�)r	rcra�CancelledError�result)rrQrQrR�drop_exception�s
"�z2TCPConnector._resolve_host.<locals>.drop_exception)rrkrNN)!r0r/r$rXrU�send_dns_resolvehost_startr�rrS�resolve�send_dns_resolvehost_endrVr1r0Zsend_dns_cache_hitrWror�rrr��_resolve_host_with_throttlerar�rur�r�r�rr]Zadd_done_callbackZshieldrl)rPr*rer�rrfrjrm�futuresZfuturer�rlZresolved_host_taskrnrQrQrR�
_resolve_hostDsr�
��
	






�zTCPConnector._resolve_hostrjrszasyncio.Future[None]c

�s��zkzK|r|D]
}|�|�IdHq|D]
}|�|�IdHq|jj|||jd�IdH}|r;|D]
}|�|�IdHq0|j�||�|D]}t|d�qDWnt	yd}	z|D]}t
||	�qW�d}	~	wwW|j�|�n|j�|�w|j�
|�S)z�Resolve host and set result for all waiters.

        This method must be run in a task and shielded from cancellation
        to avoid cancelling the underlying lookup.
        Nrj)Zsend_dns_cache_missrorSrprXrqrVrr4rr3rWr�r0)
rPrjr*rersr�rr,r�erQrQrRrr�s0�
����
z(TCPConnector._resolve_host_with_throttler�r�rFc�s@�|jr|�|||�IdH\}}|S|�|||�IdH\}}|S)zcCreate connection.

        Has same keyword arguments as BaseEventLoop.create_connection.
        N)r��_create_proxy_connection�_create_direct_connection)rPr�r�r�r�r�rQrQrRr�s��zTCPConnector._create_connectioncCsd|��sdStdurtd��|j}t|tj�r|S|durtS|j}t|tj�r*|S|dur0tStS)a*Logic to get the correct SSL context

        0. if req.ssl is false, return None

        1. if ssl_context is specified in req, use it
        2. if _ssl_context is specified in self, use it
        3. otherwise:
            1. if verify_ssl is not specified in req, use self.ssl_context
               (will generate a default context according to self.verify_ssl)
            2. if verify_ssl is True in req, generate a default SSL context
            3. if verify_ssl is False in req, generate a SSL context that
               won't verify
        NzSSL is not supported.T)r�r��RuntimeErrorrbr5�_SSL_CONTEXT_UNVERIFIEDrR�_SSL_CONTEXT_VERIFIED)rPr�r�rQrQrR�_get_ssl_context�szTCPConnector._get_ssl_contextr+cCs,|j}t|t�r
|S|j}t|t�r|SdSr�)r�rbr+rR)rPr��retrQrQrR�_get_fingerprint�s

zTCPConnector._get_fingerprint��client_error�args�
addr_infosrr�c	
�s@�z[t|j|jd�4IdH�Atj||j|j|j|j|j	d�IdH}|�
d�r4|jr4tj
dkr4|j|d<|jj|i|�d|i��IdHWd�IdHWS1IdHsUwYWdStyo}zt|j|�|�d}~wty�}zt|j|�|�d}~wty�}z|jdur�t|tj�r��||j|�|�d}~ww)N�r)r�Zlocal_addr_infosrKrLrlrMr�rOrN�sock)r.�sock_connectrrYZstart_connectionrZr[r\ror^r�r_rur��create_connectionr'rr�r(r!�OSError�errnorbra�TimeoutError)	rPr�r�r�rr�r�r�r�rQrQrR�_wrap_create_connectionsB�	��
��

4�����z$TCPConnector._wrap_create_connectionc
�s��z2t|j|jd�4IdH�|jj|i|��IdHWd�IdHWS1IdHs,wYWdStyF}zt|j|�|�d}~wtyX}zt	|j|�|�d}~wt
yv}z|jdurkt|t
j�rk�||j|�|�d}~ww�Nr�)r.r�rror�r'rr�r(r!r�r�rbrar�)rPr�r�rr�r�r�rQrQrR�_wrap_existing_connection.s&��4�����z&TCPConnector._wrap_existing_connectionr*cCs8|��sdS|j}|dusJ�|jdkrdS|��dS)z�Raise a :py:exc:`RuntimeError` on missing ``start_tls()``.

        It is necessary for TLS-in-TLS so that it is possible to
        send HTTPS queries through HTTPS proxies.

        This doesn't affect regular HTTP requests, though.
        Nr=)r�r��scheme�_check_loop_for_start_tls)rPr�Z	proxy_urlrQrQrR�_fail_on_no_start_tlsDs
z"TCPConnector._fail_on_no_start_tlsc
Cs2z|jjWdSty}ztd�|�d}~ww)Na�An HTTPS request is being sent through an HTTPS proxy. This needs support for TLS in TLS but it is not implemented in your runtime for the stdlib asyncio.

Please upgrade to Python 3.11 or higher. For more details, please see:
* https://bugs.python.org/issue37179
* https://github.com/python/cpython/pull/28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* https://github.com/aio-libs/aiohttp/discussions/6044
)ro�	start_tls�AttributeErrorrx)rPZattr_excrQrQrRr�Vs����z&TCPConnector._check_loop_for_start_tlscCs$z|��WdStyYdSw)NFT)r�rxrVrQrQrR�_loop_supports_start_tlsgs
��z%TCPConnector._loop_supports_start_tls�underlying_transportcCst|jjjdkr	dS|jdus|jjdkrdSt|�j�d�r dStjdkp*t	|dd�}|r/dSt
jdt|dd	�dS)
z6Issue a warning if the requested URL has HTTPS scheme.r=NZuvlooprOZ_start_tls_compatibleFaAn HTTPS request is being sent through an HTTPS proxy. This support for TLS in TLS is known to be disabled in the stdlib asyncio (Python <3.11). This is why you'll probably see an error in the log below.

It is possible to enable it via monkeypatching. For more details, see:
* https://bugs.python.org/issue37179
* https://github.com/python/cpython/pull/28073

You can temporarily patch this as follows:
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* https://github.com/aio-libs/aiohttp/discussions/6044
r8)r{r�)
�request_infor�r�r�r!r]�
startswithrur��getattrrWrXr`)rPr�r�Zasyncio_supports_tls_in_tlsrQrQrR�_warn_about_tls_in_tlsos&�
�z#TCPConnector._warn_about_tls_in_tlsc�sf�|��}|�|�}tr|dusJ�z�t|j|jd�4IdH��z7tjdkrA|jrA|j	j
||||jp4|j|j
p8d|jd�IdH}n|j	j
||||jpL|j|j
pPdd�IdH}Wntym|jdkrh|���|���wt|tj�r�|�|�}|r�z|�|�Wnty�|��|js�|j�|��wWd�IdHn1IdHs�wYWnlty�}	zt|j|	�|	�d}	~	wty�}	zt|j|	�|	�d}	~	wty�}	z|	j dur�t|	tj!�r�||j|	�|	�d}	~	wt"�y}
zt#d|j�d|j$d	�d
|j%�d|j&�p
d�d
|
�d��|
�d}
~
ww|du�r*d}||jt|���|�'|�||fS)z$Wrap the raw TCP transport with TLS.Nr�rO)�server_hostname�ssl_handshake_timeoutrN)r�r�rz2Cannot initialize a TLS-in-TLS connection to host rg�dz4 through an underlying connection to an HTTPS proxy z ssl:�defaultz [�]z:Failed to start TLS (possibly caused by closing transport))(r�r{rr.r�rrur�r_ror�r�r*�totalrr�r�rbrar�r}�checkr%r�r�r�r'rr�r(r!r�r�r��	TypeErrorrrer�r�Zconnection_made)rPr�r�r�rZ	tls_protor�Z
tls_transportrCr�Ztype_err�msgrQrQrR�_start_tls_connection�s��
�
�	
��
��	
��(��)������
������
�z"TCPConnector._start_tls_connection�hostscCs|g}|D]7}|d}d|v}|rtjntj}|jr|j|krq|r)||dddfn||df}|�|tjtjd|f�q|S)z�Converts the list of hosts to a list of addr_infos.

        The list of hosts is the result of a DNS lookup. The list of
        addr_infos is the result of a call to `socket.getaddrinfo()`.
        r*rgrerr;)�socket�AF_INET6�AF_INETrXr��SOCK_STREAM�IPPROTO_TCP)rPr�r�Zhinfor*Zis_ipv6rG�addrrQrQrR�_convert_hosts_to_addr_infos�s �z)TCPConnector._convert_hosts_to_addr_infosc
�s��|�|�}|�|�}|jj}|dusJ�|�d�r!|�d�d}|j}|dus*J�z
|j|||d�IdH}	WntyV}
z|
j	durKt
|
tj�rK�t
|j|
�|
�d}
~
wwd}|�|	�}|r�|rj|jpf|�d�nd}
z|j|j||||
||d�IdH\}}Wnttjfy�}
z|
}t�||j�WYd}
~
q^d}
~
ww|��r�|r�z
|�|�W||fSty�}
z$|��|js�|j�|�|
}|�d�}|��}t� ||�WYd}
~
q^d}
~
ww||fS|dus�J�|�)Nz..�.)r�)r�r�r�r�r�rr�)!r{r}r�Zraw_host�endswith�rstriprertr�r�rbrar�rr�r�r�r�r�r rYZpop_addr_infos_interleaver\r�r�r%r�r�r�r�r��getpeernameZremove_addr_infos)rPr�r�r�rr�rCr*rer�r��last_excr�r�Ztranspr�r�Zbad_peerrQrQrRrwsp�


��
��	���
��z&TCPConnector._create_direct_connectionc�s�|�|�|��}|�|�}|j|g|td�IdH\}}|��r�|r)|�||�tj|_	|j
|_
|jjdddd�}t
||||j�}	|�|	�IdH}
z�z|	j}|dusUJ�|j||jd�|
�|	�IdH}Wntyv|
��|	���wd|	_zKz6|jdkr�|j}
|
dur�t|j�j}
t|
j|j|j|
|jd��|s�|jddd�}|dur�td��|� �}Wnty�|���wW|s�|��n|s�|��ww|s�|�!|�}|j"|j#||||j$|d	�IdHW|
��S|j%|||d
�IdHW|
��S|
��w||fS)Nr~)r�r�Zproxy_headers_hash)Zread_until_eofr���)�statusr~r�r�)r�z)Transport does not expose socket instance)r�r�r�r�r�)r�r�)&r�r�r�rwr#r�r�rZMETH_CONNECT�methodr�r��_replacer�ro�sendrpZset_response_paramsr��startrr�r��reasonr
�phraser"r��historyr�r�rx�dupr{r�r�r*r�)rPr�r�r�Zruntime_has_start_tlsr�r�r�rjr	Z
proxy_resprkZrespr~Zrawsockr�rQrQrRrvVs��

����
�������
�
�
��z%TCPConnector._create_proxy_connection)NNr�)r�r*rNNr[)?r\r]r^r�r�	frozensetrr��
AddressFamily�	AF_UNSPECr2r��bytesr r5r+r2r�rr�rrar�rr-rSrrr�r�r�rGrDrfrrrtr�rrr*r)rr{rr}r rrr!rcr�r�r�r�r�r�r�Z
BaseTransportr�r�rwrv�
__classcell__rQrQrarRrC�st&�������	�

���

����������
�$R
 
���
�
�c
����
�
�)���
�!�������
�+������
�

��
�6�����
�V�
������
�K����rCc�eZdZdZeedh�BZdedddfdede	d	e
eBdBd
edede
jdBd
df�fdd�
Zed
efdd��Zdededddd
efdd�Z�ZS)rDa�Unix socket connector.

    path - Unix socket path.
    keepalive_timeout - (optional) Keep-alive timeout.
    force_close - Set to True to force close and do reconnect
        after each request (and between redirects).
    limit - The total number of simultaneous connections.
    limit_per_host - Number of simultaneous connections to one host.
    loop - Optional event loop.
    ZunixFr�rN�pathr�r�r�r�rlrNcs t�j|||||d�||_dS)N�r�r�r�r�rl)rQrS�_path�rPr�r�r�r�r�rlrarQrRrS�s	�
zUnixConnector.__init__cCr�)zPath to unix socket.�r�rVrQrQrRr��r�zUnixConnector.pathr�r�rHr�rFc
�s��z5t|j|jd�4IdH�|j�|j|j�IdH\}}Wd�IdHW|S1IdHs/wYW|StyW}z|jdurJt	|t
j�rJ�t|j
|j|�|�d}~wwr�)r.r�rroZcreate_unix_connectionr�r�r�r�rbrar�r&r�r��rPr�r�r�r�r�r�rQrQrRr�s$��������z UnixConnector._create_connection�r\r]r^r�rr�rr2r�r�rr�r rar�rSr�r�r*rr)rr�rQrQrarRrD�sD���
���������rDcr�)rEa�Named pipe connector.

    Only supported by the proactor event loop.
    See also: https://docs.python.org/3/library/asyncio-eventloop.html

    path - Windows named pipe path.
    keepalive_timeout - (optional) Keep-alive timeout.
    force_close - Set to True to force close and do reconnect
        after each request (and between redirects).
    limit - The total number of simultaneous connections.
    limit_per_host - Number of simultaneous connections to one host.
    loop - Optional event loop.
    ZnpipeFr�rNr�r�r�r�r�rlrNcs6t�j|||||d�t|jtj�std��||_dS)Nr�z9Named Pipes only available in proactor loop under windows)rQrSrbroraZProactorEventLooprxr�r�rarQrRrSs	���
zNamedPipeConnector.__init__cCr�)zPath to the named pipe.r�rVrQrQrRr� r�zNamedPipeConnector.pathr�r�rHr�rFc
�s��z:t|j|jd�4IdH�!|j�|j|j�IdH\}}t�d�IdHWd�IdHn1IdHs5wYWnt	yZ}z|j
durOt|tj�rO�t
|j|�|�d}~wwtt|�S)Nr�r)r.r�rroZcreate_pipe_connectionr�r�ra�sleepr�r�rbr�r r�rr)r�rQrQrRr%s$���(��
��
z%NamedPipeConnector._create_connectionr�rQrQrarRrE�sD���
���������rE)orar�rr�rursrW�collectionsrrr�collections.abcrrrr�
contextlibr	r<r
�	itertoolsrrr
�timer�typesr�typingrrrrrrrYrrr;rr�abcrrZclient_exceptionsrrrr r!r"r#r$r%r&r'r(Zclient_protor)Z
client_reqrepr*r+r,r-r.r/r0r1r2r3r4�logr5rJr6r�r:r��	bytearrayr�r5�ImportErrorrr�ZEMPTY_SCHEMA_SETZHTTP_SCHEMA_SETZ
WS_SCHEMA_SETZHTTP_AND_EMPTY_SCHEMA_SETrr��__all__�clientrFrG�tracingrHrIrrgrhr�r�rBr"r�r@rzryrCrDrErQrQrQrR�<module>s� 8(


�
�	
XQ0+7