HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/aiohttp/__pycache__/connector.cpython-310.pyc
o

���gA��@s�ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
ddlmZddl
mZddlmZmZmZddlmZddlmZddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)Z)d	d
l*m+Z+m,Z,d	dl-m.Z.m/Z/d	dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;d	d
l<m=Z=d	dl>m?Z?m@Z@mAZAd	dl,mBZBmCZCmDZDmEZEmFZFmGZGd	dlHmIZIer�ddlJZJeJjKZKnz	ddlJZJeJjKZKWn
eLy�dZJeMZKYnweNdh�ZOeNddh�ZPeNddh�ZQePeOBZReReQBZSdejTk�odkn�pejTdkZUdZVe�r'd	dlWmXZXd	dl>mYZYd	dlZm[Z[Gdd�d�Z\Gdd �d �Z]Gd!d"�d"�Z^Gd#d$�d$�Z_Gd%d&�d&�Z`d'ead(eKfd)d*�Zbebd+�Zcebd,�ZdGd-d.�d.e_�ZeGd/d0�d0e_�ZfGd1d2�d2e_�ZgdS)3�N)�OrderedDict�defaultdict�deque)�suppress)�
HTTPStatus)�chain�cycle�islice)�	monotonic)�
TracebackType)�
TYPE_CHECKING�Any�	Awaitable�Callable�DefaultDict�Deque�Dict�Iterator�List�Literal�Optional�Sequence�Set�Tuple�Type�Union�cast�)�hdrs�helpers)�AbstractResolver�
ResolveResult)�ClientConnectionError�ClientConnectorCertificateError�ClientConnectorDNSError�ClientConnectorError�ClientConnectorSSLError�ClientHttpProxyError�ClientProxyConnectionError�ServerFingerprintMismatch�UnixClientConnectorError�cert_errors�
ssl_errors)�ResponseHandler)�
ClientRequest�Fingerprint�_merge_ssl_params)�ceil_timeout�
is_ip_address�noop�sentinel�
set_exception�
set_result)�DefaultResolver��http�https�ws�wss)��
r)r=r>r)r=��)�
BaseConnector�TCPConnector�
UnixConnector�NamedPipeConnector)�
ClientTimeout)�
ConnectionKey)�Tracec@s>eZdZdZdeeddfdd�Zdefdd�Zdd	d
�ZdS)�_DeprecationWaiter��
_awaitable�_awaited�	awaitable�returnNcCs||_d|_dS�NFrI)�selfrL�rP�</usr/local/lib/python3.10/dist-packages/aiohttp/connector.py�__init__h�
z_DeprecationWaiter.__init__cCsd|_|j��S�NT)rKrJ�	__await__�rOrPrPrQrUlrSz_DeprecationWaiter.__await__cCs|jst�dt�dSdS)NzDConnector.close() is a coroutine, please use await connector.close())rK�warnings�warn�DeprecationWarningrVrPrPrQ�__del__ps��z_DeprecationWaiter.__del__�rMN)	�__name__�
__module__�__qualname__�	__slots__rr
rRrUrZrPrPrPrQrHes
rHc
@s�eZdZdZdddddedejddf
d	d
�Zdefdd�Z	e
fd
eddfdd�Zde
dfdd�Zedejfdd��Zedeejfdd��Zedeefdd��Zdegdfddfdd�Zd$dd�Zd$dd�Zd$d d!�Zedefd"d#��ZdS)%�
ConnectionN�	connectorrA�keyrF�protocol�looprMcCs@||_||_||_||_g|_|��rt�t�	d��|_
dSdS)Nr)�_key�
_connector�_loop�	_protocol�
_callbacks�	get_debug�	traceback�
extract_stack�sys�	_getframe�_source_traceback)rOrarbrcrdrPrPrQrR}s�zConnection.__init__cCsd|j�d�S)NzConnection<�>)rerVrPrPrQ�__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)�client_connection�message�source_traceback)
rhrX�ResourceWarningrg�	is_closedrf�_releaserero�call_exception_handler)rOrr�kwargs�contextrPrPrQrZ�s




�zConnection.__del__TcC�dS)z9Force subclasses to not be falsy, to make checks simpler.TrPrVrPrPrQ�__bool__�szConnection.__bool__cCstjdtdd�|jS)Nz%connector.loop property is deprecated���
stacklevel)rWrXrYrgrVrPrPrQrd�s�zConnection.loopcCs|jdurdS|jjS�N)rh�	transportrVrPrPrQr��s
zConnection.transportcC�|jSr�)rhrVrPrPrQrc�szConnection.protocol�callbackcCs|dur|j�|�dSdSr�)ri�append)rOr�rPrPrQ�add_callback�s�zConnection.add_callbackc	CsR|jdd�g}|_|D]}tt��|�Wd�n1s!wYq
dSr�)rir�	Exception)rO�	callbacks�cbrPrPrQ�_notify_release�s
���zConnection._notify_releasecCs6|��|jdur|jj|j|jdd�d|_dSdS)NTrt�r�rhrfr{rerVrPrPrQ�close�s


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


�zConnection.releasecCs|jdup
|j��Sr�)rh�is_connectedrVrPrPrQ�closed�szConnection.closedr[)r\r]r^ror-�asyncio�AbstractEventLooprR�strrqrWr
rZrr��propertyrdr�	Transportr�rcrr�r�r�r��boolr�rPrPrPrQr`ys8����
�


r`c@seZdZdZdZddd�ZdS)�_TransportPlaceholderz.placeholder for BaseConnector.connect functionrPrMNcCr)z Close the placeholder transport.NrPrVrPrPrQr��sz_TransportPlaceholder.closer[)r\r]r^�__doc__r_r�rPrPrPrQr��sr�c@seZdZdZdZdZdZeZe	ddddddd	�d
e
edefde
ded
ede
deejdeddfdd�Zefdeddfdd�ZdNdd�Zdeddfdd�ZdNdd�Z			dOdeeedeed eeddfd!d"�Zede
fd#d$��Zedefd%d&��Zedefd'd(��Z dPd)d*�Z!dPd+d,�Z"de#dfd-d.�Z$dPd/d0�Z%ede
fd1d2��Z&d3d4defd5d6�Z'd7e(d8e)d9d:d;de*fd<d=�Z+d3d4d8e)d9ddfd>d?�Z,d3d4d8e)d9dee*fd@dA�Z-dPdBdC�Z.d3d4dDe/ddfdEdF�Z0ddG�d3d4dHe/dIe
ddfdJdK�Z1d7e(d8e)d9d:d;de/fdLdM�Z2dS)QrAa\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_closedrd�timeout_ceil_thresholdr�r�r�r�r�rdr�rMcCs|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|_'|�(�dS)	Nz6keepalive_timeout cannot be set if force_close is Trueg.@Fr�rdzoenable_cleanup_closed ignored because https://github.com/python/cpython/pull/118960 is fixed in Python version r�r�))r4�
ValueErrorr��get_running_loop�_timeout_ceil_threshold�_closedrjrkrlrmrnrorr�_conns�_limit�_limit_per_host�set�	_acquired�_acquired_per_hostr�float�_keepalive_timeout�_force_closer�_waitersrg�	functools�partialr-�_factory�_cleanup_handle�_cleanup_closed_handle�NEEDS_CLEANUP_CLOSEDrWrX�version_inforY�_cleanup_closed_disabled�_cleanup_closed_transports�_cleanup_closed)rOr�r�r�r�r�rdr�rPrPrQrR�sP�������zBaseConnector.__init__rrcCs�|jrdS|js
dSdd�|j��D�}|��d|i}|jd|��tfi|��||dd�}|jdur9|j|d<|j�|�dS)NcSsg|]}t|��qSrP)�repr)�.0�crPrPrQ�
<listcomp>@sz)BaseConnector.__del__.<locals>.<listcomp>rszUnclosed connector zUnclosed connector)ra�connectionsrwrx)	r�r��values�_closerXryrorgr|)rOrr�connsr}r~rPrPrQrZ:s�

zBaseConnector.__del__cCst�dt�|S)NzH"with Connector():" is deprecated, use "async with Connector():" instead)rWrXrYrVrPrPrQ�	__enter__Os
�zBaseConnector.__enter__�exccGs|��dSr�)r�)rOr�rPrPrQ�__exit__WszBaseConnector.__exit__c�s�|Sr�rPrVrPrPrQ�
__aenter__Zs�zBaseConnector.__aenter__�exc_type�	exc_value�
exc_tracebackc�s�|��IdHdSr�)r�)rOr�r�r�rPrPrQ�	__aexit__]s�zBaseConnector.__aexit__cCr�)z1Ultimately close connection on releasing if True.)r�rVrPrPrQr�e�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�rVrPrPrQr�j�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�rVrPrPrQr�sr�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��cancelr
r�r�rr�itemsr�r�r�r�r��is_sslr�r�weakref_handlergr�)rO�now�timeoutr��deadlinerbr��alive�proto�use_timer�rPrPrQr�|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��abortr�rr��_cleanup_closed_periodrgr�)rOr�rPrPrQr��s 

���zBaseConnector._cleanup_closedcCs|��tt��S)zClose all opened transports.)r�rHr3rVrPrPrQr��s
zBaseConnector.closec
Cs�|jrdSd|_z�|j��r<W|j��|j��|j��D]}|D]}|��q"q|j��d|_	|j
��d|_dS|j	rD|j	��|jrL|j��|j��D]
}|D]\}}|��qUqQ|jD]}|��qb|j
D]
}|durv|�
�qlW|j��|j��|j��D]}|D]}|��q�q�|j��d|_	|j
��d|_dS|j��|j��|j��D]}|D]}|��q�q�|j��d|_	|j
��d|_wrT)r�rgrzr��clearr�r�r�r�r�r�r�r�r�)rO�
keyed_waiters�keyed_waiter�datar��t0r�rPrPrQr��sf



�


�


�


��


�



�

�

zBaseConnector._closecCr�)z;Is connector closed.

        A readonly property.
        )r�rVrPrPrQr��szBaseConnector.closedrbrFcCs\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)rOrb�total_remain�host_remain�acquiredrPrPrQ�_available_connections�s
z$BaseConnector._available_connections�req�tracesrGr�rEc
	�s��|j}|�||�IdH}dur|St|j|j�4IdH��|�|�dkrH|�||�IdH|�||�IdH}durH|Wd�IdHSttt	��}|j
�|�|jr_|j
|�|�z(|rn|D]	}|��IdHqd|�|||�IdH}|r�|D]	}|��IdHq|Wnty�|�||��w|jr�|��td��Wd�IdHn1IdHs�wY|j
�|�|j
�|�|jr�|j
|}	|	�|�|	�|�t||||j�S)z'Get from pool or create new connection.NrzConnector is closed.)�connection_key�_getr1�connect�ceil_thresholdr��_wait_for_available_connectionrr-r�r��addr�r��send_connection_create_start�_create_connection�send_connection_create_end�
BaseException�_release_acquiredr�r�r"�remover`rg)
rOr�r�r�rb�conn�placeholder�tracer��acquired_per_hostrPrPrQr�sL����
(�#


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)	rg�
create_futurer��move_to_end�send_connection_queued_start�send_connection_queued_end�popr�r�)rOrbr��attempts�futr�r�rPrPrQr�=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�r�r�r��send_connection_reuseconnr�r�r`rgr�r�r�r�r�r�)	rOrbr�r��t1r�r�r�r�rPrPrQr�gs8���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�doner6)rO�queuesrb�waiters�waiter�_rPrPrQ�_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)rOrbr�r�rPrPrQr��s
zBaseConnector._release_acquiredrtrcrucCs�|jrdS|�||�|js|s|jr(|j}|��|jr&|js&|j�	|�dS|j
|�	|t�f�|jdurHt
j|d|j|j|jd�|_dSdS)Nr�r�)r�r�r�rur�r�r�r�r�r�r�r
r�rr�r�rgr�)rOrbrcrur�rPrPrQr{�s&
��zBaseConnector._releasec�s�t��r�)�NotImplementedError)rOr�r�r�rPrPrQr��s�z BaseConnector._create_connection)rMrA)NNNr[)3r\r]r^r�r�ror��HIGH_LEVEL_SCHEMA_SET�allowed_protocol_schema_setr4r�objectr�r��intrr�r�rRrWr
rZr�r�r�rr�rr�r�r�r�r�r�r�rr�r�r�r�r.rr`r�r�r�rr-r�r{r�rPrPrPrQrA�s��������	�

�I

�
���
�

'
(���
�5��
�*��
�
*����
� ����rAc@s�eZdZddeeddfdd�Zdedefdd�Zd	e	e
efd
ee
ddfdd�Zd	e	e
efddfd
d�Zddd�Zd	e	e
efdee
fdd�Zd	e	e
efdefdd�ZdS)�_DNSCacheTableN�ttlrMcCsi|_i|_||_dSr�)�	_addrs_rr�_timestamps�_ttl)rOrrPrPrQrR�s
z_DNSCacheTable.__init__�hostcCs
||jvSr�)r)rOrrPrPrQ�__contains__�s
z_DNSCacheTable.__contains__rb�addrscCs4t|�t|�f|j|<|jdurt�|j|<dSdSr�)rr�rrr
r)rOrbrrPrPrQr��s
�z_DNSCacheTable.addcCs.|j�|d�|jdur|j�|d�dSdSr�)rrrr�rOrbrPrPrQr��s
�z_DNSCacheTable.removecCs|j��|j��dSr�)rr�rrVrPrPrQr��s
z_DNSCacheTable.clearcCs(|j|\}}tt||��}t|�|Sr�)rrr	�next)rOrbrd�lengthrrPrPrQ�
next_addrs�sz_DNSCacheTable.next_addrscCs$|jdurdS|j||jt�kSrN)rrr
rrPrPrQ�expired�s
z_DNSCacheTable.expiredr�r[)r\r]r^rr�rRrr�rrr�rrr!r�r�r�r!r"rPrPrPrQr�s"
r�verifiedrMcCsztdurdS|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)
�ssl�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)r#�
sslcontextrPrPrQ�_make_ssl_contexts

r2TFc&sJeZdZdZeedh�BZddddejj	dddde
dddddd	d
dd�ded
ee
dedeedejdeedeeeefdeeeefdeededeefdededededeejdedeedeef$�fdd�Zd edf�fd!d"�Zed efd#d$��Zed efd%d&��Z	dZd'eed(eed dfd)d*�Z	d[d'ed(ed+ee d,d e!e"fd-d.�Z#d/eeefd'ed(ed0e$d1d+ee d,d e!e"fd2d3�Z%d4e&d+e!d,d5d6d e'fd7d8�Z(d4e&d eefd9d:�Z)d4e&d ed;fd<d=�Z*e+d>�d?e,d@e!e-j.d4e&d5d6dAe/e0dBe,d eej1e'ffdCdD�Z2e+d>�d?e,d4e&d5d6dAe/e0dBe,d eej1e'ffdEdF�Z3d\dHdI�Z4d]dJdK�Z5d efdLdM�Z6dNej1d4e&d dfdOdP�Z7e+fdNej1d4e&d5d6dAe/e0d eej8e'ff
dQdR�Z9dSe!e"d e!e-j.fdTdU�Z:e+d>�d4e&d+e!d,d5d6dAe/e0d eej1e'ff
dVdW�Z;d4e&d+e!d,d5d6d eej8e'ffdXdY�Z<�Z=S)^rBu-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.
    �tcpTN�
Fr�rr�g�?)�
verify_ssl�fingerprint�
use_dns_cache�
ttl_dns_cache�family�ssl_contextr$�
local_addr�resolverr�r�r�r�r�rdr��happy_eyeballs_delay�
interleaver5r6r7r8r9r:r$r;r<r�r�r�r�r�rdr�r=r>c	s�t�j|
|||
|||d�t||||�|_|	durt|jd�}	|	|_||_t|d�|_	i|_
||_t�
|�|_||_||_t�|_dS)Nr�r�)r)�superrRr0�_sslr7rg�	_resolver�_use_dns_cacher�
_cached_hosts�_throttle_dns_futures�_family�aiohappyeyeballs�addr_to_addr_infos�_local_addr_infos�_happy_eyeballs_delay�_interleaver��_resolve_host_tasks)rOr5r6r7r8r9r:r$r;r<r�r�r�r�r�rdr�r=r>��	__class__rPrQrRCs,�
�zTCPConnector.__init__rMcs<t�|j���D]}|��q|jD]}|��qt���S)zClose all ongoing DNS calls.)r�
from_iterablerDr�r�rKr?r�)rOr�trLrPrQr�ss




zTCPConnector.closecCr�)zSocket family like AF_INET.)rErVrPrPrQr9}r�zTCPConnector.familycCr�)z%True if local DNS caching is enabled.)rBrVrPrPrQr7�r�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)rCr�r�r�)rOrrPrPrPrQ�clear_dns_cache�s
zTCPConnector.clear_dns_cacher�rGc	�s��t|�r||||jddd�gS|js@|r"|D]
}|�|�IdHq|jj|||jd�IdH}|r>|D]
}|�|�IdHq3|S||f}||jvrf|j�|�sf|j�	|�}|rd|D]
}|�
|�IdHqY|S||jvr�|j|}|j�
�}	|�|	�|r�|D]
}|�
|�IdHq~z|	IdHW|�|	�n|�|	�w|j�	|�St�|j|<}|�|||||�}
t��}tjdkr�tj|
|dd�}n|�|
�}|��s�|j�|�|�|jj�z	t�|�IdHWStjy�d
dd�}
|�|
��w)z*Resolve host and return list of addresses.r)�hostnamerrPr9r��flagsN�r9)r=r?T)rd�eager_startr�#asyncio.Future[List[ResolveResult]]rMcSs:tttj��
|��Wd�dS1swYdSr�)rr�r��CancelledError�result)rrPrPrQ�drop_exception�s
"�z2TCPConnector._resolve_host.<locals>.drop_exception)rrVrMN)r2rErB�send_dns_resolvehost_startrA�resolve�send_dns_resolvehost_endrCr"r!�send_dns_cache_hitrDrgr�r�rr��_resolve_host_with_throttler�r�rmr��Task�create_taskr
rK�add_done_callback�shieldrW)rOrrPr�r��resrbrX�futures�future�corord�resolved_host_taskrYrPrPrQ�
_resolve_host�sj���
	






�zTCPConnector._resolve_hostrbrdzasyncio.Future[None]c

�s��|r|D]
}|�|�IdHqz^z>|r!|D]
}|�|�IdHq|jj|||jd�IdH}|r=|D]
}|�|�IdHq2|j�||�|D]}t|d�qFWnt	yf}	z|D]}t
||	�qY�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.
        NrT)�send_dns_cache_missrZrAr[rEr\rCr�r6r�r5rDrr!)
rOrbrrPrdr�r�rr�erPrPrQr^�s2�
����
z(TCPConnector._resolve_host_with_throttler�r�rEc�s@�|jr|�|||�IdH\}}|S|�|||�IdH\}}|S)zcCreate connection.

        Has same keyword arguments as BaseEventLoop.create_connection.
        N)�proxy�_create_proxy_connection�_create_direct_connection)rOr�r�r�rr�rPrPrQr�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$�RuntimeError�
isinstancer&�_SSL_CONTEXT_UNVERIFIEDr@�_SSL_CONTEXT_VERIFIED)rOr�r1rPrPrQ�_get_ssl_context$szTCPConnector._get_ssl_contextr/cCs,|j}t|t�r
|S|j}t|t�r|SdSr�)r$ror/r@)rOr��retrPrPrQ�_get_fingerprintEs

zTCPConnector._get_fingerprint��client_error�args�
addr_infosrvr}c	
�s�zGt|j|jd�4IdH�-tj||j|j|j|jd�IdH}|jj	|i|�d|i��IdHWd�IdHWS1IdHsAwYWdSt
y[}zt|j|�|�d}~wt
ym}zt|j|�|�d}~wty�}z|jdur�t|tj�r��||j|�|�d}~ww)N�r�)rx�local_addr_infosr=r>rd�sock)r1�sock_connectr�rF�start_connectionrHrIrJrg�create_connectionr+r#r�r,r&�OSError�errnoror��TimeoutError)	rOrxr�r�rvrwr}r{r�rPrPrQ�_wrap_create_connectionNs4�	��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�Nry)r1r|r�rgr~r+r#r�r,r&rr�ror�r�)rOr�r�rvrwr}r�rPrPrQ�_wrap_existing_connectionls&��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�rk�scheme�_check_loop_for_start_tls)rOr��	proxy_urlrPrPrQ�_fail_on_no_start_tls�s
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
)rg�	start_tls�AttributeErrorrn)rO�attr_excrPrPrQr��s����z&TCPConnector._check_loop_for_start_tlscCs$z|��WdStyYdSw)NFT)r�rnrVrPrPrQ�_loop_supports_start_tls�s
��z%TCPConnector._loop_supports_start_tls�underlying_transportcCs<|jjjdkr	dSt|dd�}|rdStjdt|dd�dS)z6Issue a warning if the requested URL has HTTPS scheme.r:N�_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
r=)rsr�)�request_info�urlr��getattrrWrX�RuntimeWarning)rOr�r��asyncio_supports_tls_in_tlsrPrPrQ�_warn_about_tls_in_tls�s�
�z#TCPConnector._warn_about_tls_in_tlsc�s�|��}|�|�}tr|dusJ�zpt|j|jd�4IdH�Wz|jj||||jp,|j	|j
d�IdH}WntyA|���wt
|tj�rl|�|�}|rlz|�|�Wntyk|��|jsj|j�|��wWd�IdHn1IdHs|wYWnjty�}	zt|j|	�|	�d}	~	wty�}	zt|j|	�|	�d}	~	wty�}	z|	jdur�t
|	tj�r��||j|	�|	�d}	~	wty�}
ztd|j	�d|j d�d|j!�d|j"p�d	�d
|
�d��|
�d}
~
ww|dur�d}||jt|���|�#|�||fS)
z$Wrap the raw TCP transport with TLS.Nry)�server_hostname�ssl_handshake_timeoutz2Cannot initialize a TLS-in-TLS connection to host �:�dz4 through an underlying connection to an HTTPS proxy z ssl:�defaultz [�]z:Failed to start TLS (possibly caused by closing transport))$r�rrrr1r|r�rgr�r�r�totalr�r�ror�r�rt�checkr)r�r�r�r+r#r�r,r&rr�r��	TypeErrorr"rPrkr$�connection_made)rOr�r�r�rv�	tls_protor1�
tls_transportr6r��type_err�msgrPrPrQ�_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()`.
        rr�rPrr8)�socket�AF_INET6�AF_INETrEr��SOCK_STREAM�IPPROTO_TCP)rOr�rx�hinfor�is_ipv6r9�addrrPrPrQ�_convert_hosts_to_addr_infoss �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$rxr�r�rvr�)!rrrtr��raw_host�endswith�rstriprPrhrr�ror�r�r$r�r�r�r�r�r%rF�pop_addr_infos_interleaverJr�r�r)r�r�r�r��get_extra_info�getpeername�remove_addr_infos)rOr�r�r�rvr1r6rrPr�r��last_excrxr��transpr�r{�bad_peerrPrPrQrm/sp�


��
��	���
��z&TCPConnector._create_direct_connectionc�s��|�|�|��}i}|jdur|j}|jtj|tj<|j}|dus&J�ttj|||j	|j
|jd�}|j|g|t
d�IdH\}}	|j�tjd�}
|
dur_|��sY|
|jtj<n|
|jtj<|���rF|rl|�||�tj|_|j|_|jjdddd�}t|||	|j
�}|�|�IdH}
z�z|j}|dus�J�|j||jd�|
�|�IdH}Wnty�|
��|���wd|_zMz6|j dkr�|j!}|dur�t"|j �j#}t$|
j%|j&|j ||jd��|s�|j'ddd�}|dur�t(d	��|�)�}Wn
t�y|���wW|�s
|��n	|�s|��ww|�s1|�*|�}|j+|j,||||j-|d
�IdHW|
��S|j.|||d�IdHW|
��S|
��w||	fS)N)�headers�authrdr$ru)rk�
proxy_auth�proxy_headers_hash)�read_until_eofr���)�statusrwr�r�)r�z)Transport does not expose socket instance)r�r$r{r�r�)r�r�)/r�r��
proxy_headersr�r�HOSTrkr.�METH_GETr�rgr$rmr(r�
AUTHORIZATIONr��PROXY_AUTHORIZATIONr��METH_CONNECT�methodr�r��_replacer`�sendrh�set_response_paramsr��startr�r�r��reasonr�phraser'r��historyr�rn�duprrr�r�rr�)rOr�r�r��runtime_has_start_tlsr�r��	proxy_reqr�r�r�rbr��
proxy_resprc�resprw�rawsockr1rPrPrQrlzs��

�
�
���
�������
�
�
��z%TCPConnector._create_proxy_connection)NNr�)r�r.rMNr[)>r\r]r^r�r�	frozensetrr��
AddressFamily�	AF_UNSPECr4r�r�bytesrr&rr/rr�r r�rr�r�rRrr�r�r9r7rQrrr!rhrr^r.r-r�rrrtr%r
rF�AddrInfoTyperr�r�r�r�r�r�r�r��
BaseTransportr�r�rmrl�
__classcell__rPrPrLrQrB$sn�������	�
���
��������0
���
����
�
�[
����
�
�)���
�!�������
�#������
�

��
�*�����
�H�
������
�K����rBc�eZdZdZeedh�BZdedddfdede	d	e
eedfd
e
de
deejd
df�fdd�
Zed
efdd��Zdededddd
efdd�Z�ZS)rCa�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.
    �unixFr�rN�pathr�r�r�r�rdrMcs t�j|||||d�||_dS)N�r�r�r�r�rd)r?rR�_path�rOr�r�r�r�r�rdrLrPrQrRs	�
zUnixConnector.__init__cCr�)zPath to unix socket.�r�rVrPrPrQr�r�zUnixConnector.pathr�r�rGr�rEc
�s��z5t|j|jd�4IdH�|j�|j|j�IdH\}}Wd�IdHW|S1IdHs/wYW|StyW}z|jdurJt	|t
j�rJ�t|j
|j|�|�d}~wwr�)r1r|r�rg�create_unix_connectionr�r�rr�ror�r�r*r�r��rOr�r�r�rr�r�rPrPrQr�s$��������z UnixConnector._create_connection�r\r]r^r�rr�rr4r�r�rrr�rrr�r�rRr�r�r.rr-r�r�rPrPrLrQrC�sD������������rCcr�)rDa�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.
    �npipeFr�rNr�r�r�r�r�rdrMcs6t�j|||||d�t|jtj�std��||_dS)Nr�z9Named Pipes only available in proactor loop under windows)r?rRrorgr��ProactorEventLooprnr�r�rLrPrQrRAs	���
zNamedPipeConnector.__init__cCr�)zPath to the named pipe.r�rVrPrPrQr�Yr�zNamedPipeConnector.pathr�r�rGr�rEc
�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)Nryr)r1r|r�rg�create_pipe_connectionr�r�r��sleeprr�ror�r%r�rr-r�rPrPrQr�^s$���(��
��
z%NamedPipeConnector._create_connectionr�rPrPrLrQrD0sD������������rD)hr�r�rr�rmrkrW�collectionsrrr�
contextlibrr9r�	itertoolsrrr	�timer
�typesr�typingrr
rrrrrrrrrrrrrrrrFr8rr�abcr r!�client_exceptionsr"r#r$r%r&r'r(r)r*r+r,�client_protor-�
client_reqrepr.r/r0r1r2r3r4r5r6r<r7r$r&�ImportErrorrr��EMPTY_SCHEMA_SET�HTTP_SCHEMA_SET�
WS_SCHEMA_SET�HTTP_AND_EMPTY_SCHEMA_SETrr�r��__all__�clientrErF�tracingrGrHr`r�rArr�r2rqrprBrCrDrPrPrPrQ�<module>s�L4
 
�
�	X	'Z7