a
    }3e                     @   sP  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" d dl#Z#d	d
l$m%Z%m&Z& d	dl'm(Z( d	dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 d	dl4m5Z5 d	dl6m7Z7m8Z8m9Z9 d	dl&m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? d	dl@mAZA d	dlBmCZC d	dlDmEZE zd dlFZFeFjGZGW n eHy   dZFeIZGY n0 dZJerd	dlKmLZL d	dl6mMZM d	dlNmOZO G dd dZPG dd dZQG dd dZRG dd dZSG dd  d ZTG d!d" d"eSZUG d#d$ d$eSZVG d%d& d&eSZWdS )'    N)defaultdictdeque)suppress)SimpleCookie)cycleislice)	monotonic)TracebackType)TYPE_CHECKINGAny	AwaitableCallableDefaultDictDictIteratorListOptionalSetTupleTypeUnioncast   )hdrshelpers)AbstractResolver)
ClientConnectionErrorClientConnectorCertificateErrorClientConnectorErrorClientConnectorSSLErrorClientHttpProxyErrorClientProxyConnectionErrorServerFingerprintMismatchUnixClientConnectorErrorcert_errors
ssl_errors)ResponseHandler)ClientRequestFingerprint_merge_ssl_params)PY_36ceil_timeoutget_running_loopis_ip_addressnoopsentinel)	RESPONSES)EventResultOrError)DefaultResolver)BaseConnectorTCPConnectorUnixConnectorNamedPipeConnector)ClientTimeout)ConnectionKey)Tracec                   @   s@   e Zd ZdZee ddddZedddZddd	d
ZdS )_DeprecationWaiter
_awaitable_awaitedN)	awaitablereturnc                 C   s   || _ d| _d S NFr;   )selfr>    rB   D/home/pi/bot/my_env/lib/python3.9/site-packages/aiohttp/connector.py__init__Q   s    z_DeprecationWaiter.__init__r?   c                 C   s   d| _ | j S NT)r=   r<   	__await__rA   rB   rB   rC   rG   U   s    z_DeprecationWaiter.__await__c                 C   s   | j stdt d S )NzDConnector.close() is a coroutine, please use await connector.close())r=   warningswarnDeprecationWarningrH   rB   rB   rC   __del__Y   s
    z_DeprecationWaiter.__del__)	__name__
__module____qualname__	__slots__r   r   rD   rG   rL   rB   rB   rB   rC   r:   N   s   r:   c                   @   s   e Zd ZdZdZddeejddddZe	ddd	Z
efedd
ddZeejdddZeeej dddZeee dddZeg df ddddZddddZddddZddddZeedddZdS )
ConnectionNr3   r8   )	connectorkeyprotocolloopr?   c                 C   s<   || _ || _|| _|| _g | _| r8tt	d| _
d S )Nr   )_key
_connector_loop	_protocol
_callbacks	get_debug	tracebackextract_stacksys	_getframe_source_traceback)rA   rR   rS   rT   rU   rB   rB   rC   rD   g   s    zConnection.__init__rE   c                 C   s   d| j  dS )NzConnection<>)rV   rH   rB   rB   rC   __repr__w   s    zConnection.__repr__	_warningsr?   c                 C   s   | j d urtrd| i}ni }|jd| tfi | | j rDd S | jj| j| j dd | dd}| j	d urx| j	|d< | j
| d S )NsourcezUnclosed connection Tshould_closezUnclosed connection)Zclient_connectionmessagesource_traceback)rY   r*   rJ   ResourceWarningrX   	is_closedrW   _releaserV   r`   call_exception_handler)rA   rd   kwargscontextrB   rB   rC   rL   z   s    





zConnection.__del__c                 C   s   t jdtdd | jS )Nz%connector.loop property is deprecated   )
stacklevel)rI   rJ   rK   rX   rH   rB   rB   rC   rU      s    zConnection.loopc                 C   s   | j d u rd S | j jS N)rY   	transportrH   rB   rB   rC   rs      s    
zConnection.transportc                 C   s   | j S rr   )rY   rH   rB   rB   rC   rT      s    zConnection.protocol)callbackr?   c                 C   s   |d ur| j | d S rr   )rZ   append)rA   rt   rB   rB   rC   add_callback   s    zConnection.add_callbackc              	   C   sR   | j d d  g  }| _ |D ]2}tt |  W d    q1 sB0    Y  qd S rr   )rZ   r   	Exception)rA   	callbackscbrB   rB   rC   _notify_release   s    
zConnection._notify_releasec                 C   s2   |    | jd ur.| jj| j| jdd d | _d S )NTrf   )rz   rY   rW   rl   rV   rH   rB   rB   rC   close   s    
zConnection.closec                 C   s6   |    | jd ur2| jj| j| j| jjd d | _d S )Nrf   )rz   rY   rW   rl   rV   rg   rH   rB   rB   rC   release   s    
zConnection.releasec                 C   s   | j d u p| j   S rr   )rY   is_connectedrH   rB   rB   rC   closed   s    zConnection.closed)rM   rN   rO   r`   
_transportr&   asyncioAbstractEventLooprD   strrb   rI   r   rL   propertyrU   r   	Transportrs   rT   r   rv   rz   r{   r|   boolr~   rB   rB   rB   rC   rQ   b   s,   	rQ   c                   @   s   e Zd ZdZddddZdS )_TransportPlaceholderz.placeholder for BaseConnector.connect functionNrE   c                 C   s   d S rr   rB   rH   rB   rB   rC   r{      s    z_TransportPlaceholder.close)rM   rN   rO   __doc__r{   rB   rB   rB   rC   r      s   r   c                	   @   s  e Zd ZdZdZdZdZeddddddee	de
f eeeeeej dd	d
dZefeddddZd dddZeddddZd dddZdDeee  ee ee ddddZeedddZeedddZeedddZddd d!Zd"e dd#d$d%Z!ddd&d'Z"e#d dd(d)Z$ddd*d+Z%eedd,d-Z&d"ed.d/d0Z'd1e(d2 d3e)d4d5d6Z*d"ee  d.d7d8Z+ddd9d:Z,d"e dd;d<d=Z-dd>d"e edd?d@dAZ.d1e(d2 d3e d4dBdCZ/dS )Er3   a  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.
    loop - Optional event loop.
    TNg       @Fd   r   keepalive_timeoutforce_closelimitlimit_per_hostenable_cleanup_closedrU   )r   r   r   r   r   rU   r?   c                C   s   |r|d ur*|t ur*tdn|t u r*d}t|}d| _| rRttd| _	i | _
|| _|| _t | _tt| _tt|| _|| _tt| _|| _tjt|d| _t | _d | _d | _| | _ g | _!| "  d S )Nz6keepalive_timeout cannot be set if force_close is Trueg      .@Fr   rU   )#r/   
ValueErrorr,   _closedr[   r\   r]   r^   r_   r`   _conns_limit_limit_per_hostset	_acquiredr   _acquired_per_hostr   float_keepalive_timeout_force_closer   _waitersrX   	functoolspartialr&   _factoryr   cookies_cleanup_handle_cleanup_closed_handle_cleanup_closed_disabled_cleanup_closed_transports_cleanup_closed)rA   r   r   r   r   r   rU   rB   rB   rC   rD      s8    
zBaseConnector.__init__rc   c                 C   s   | j r
d S | jsd S dd | j D }|   tr>d| i}ni }|jd| tfi | | |dd}| jd ur|| j|d< | j	| d S )Nc                 S   s   g | ]}t |qS rB   )repr).0crB   rB   rC   
<listcomp>      z)BaseConnector.__del__.<locals>.<listcomp>re   zUnclosed connector zUnclosed connector)rR   connectionsrh   ri   )
r   r   values_closer*   rJ   rj   r`   rX   rm   )rA   rd   connsrn   ro   rB   rB   rC   rL     s"    


zBaseConnector.__del__rE   c                 C   s   t dt | S )NzH"with Connector():" is deprecated, use "async with Connector():" instead)rI   rJ   rK   rH   rB   rB   rC   	__enter__#  s
    zBaseConnector.__enter__)excr?   c                 G   s   |    d S rr   )r   )rA   r   rB   rB   rC   __exit__+  s    zBaseConnector.__exit__c                    s   | S rr   rB   rH   rB   rB   rC   
__aenter__.  s    zBaseConnector.__aenter__)exc_type	exc_valueexc_tracebackr?   c                    s   |   I d H  d S rr   )r{   )rA   r   r   r   rB   rB   rC   	__aexit__1  s    zBaseConnector.__aexit__c                 C   s   | j S )z1Ultimately close connection on releasing if True.)r   rH   rB   rB   rC   r   9  s    zBaseConnector.force_closec                 C   s   | j S )zThe total number for simultaneous connections.

        If limit is 0 the connector has no limit.
        The default limit size is 100.
        )r   rH   rB   rB   rC   r   >  s    zBaseConnector.limitc                 C   s   | j S )zThe limit for simultaneous connections to the same endpoint.

        Endpoints are the same if they are have equal
        (host, port, is_ssl) triple.
        )r   rH   rB   rB   rC   r   G  s    zBaseConnector.limit_per_hostc                 C   s   | j r| j   d| _ | j }| j}| jri }|| }| j D ]\}}g }|D ]z\}}	| r|	| dk r|j}
|	  |j
r| js| j|
 q|||	f qR|j}
|	  |j
rR| jsR| j|
 qR|rB|||< qB|| _| jrt| d|| j| _ dS )zCleanup unused transports.Nr   _cleanup)r   cancelrX   timer   r   itemsr}   rs   r{   is_sslr   r   ru   r   weakref_handle)rA   nowtimeoutr   deadlinerS   r   aliveprotoZuse_timers   rB   rB   rC   r   P  s:    



zBaseConnector._cleanupr8   )rS   valr?   c                 C   s4   | j }||vrd S || }|| |s0| j |= d S rr   )r   remove)rA   rS   r   Zacquired_per_hostr   rB   rB   rC   _drop_acquired_per_hosty  s    
z%BaseConnector._drop_acquired_per_hostc                 C   sR   | j r| j   | jD ]}|dur|  qg | _| jsNt| d| j| j| _ dS )z~Double confirmation for transport close.

        Some broken ssl servers may leave socket open without proper close.
        Nr   )	r   r   r   abortr   r   r   _cleanup_closed_periodrX   )rA   rs   rB   rB   rC   r     s    


zBaseConnector._cleanup_closedc                 C   s   |    tt S )zClose all opened transports.)r   r:   r.   rH   rB   rB   rC   r{     s    zBaseConnector.closec                 C   s>  | j r
d S d| _ z| j rVW | j  | j  | j  d | _| j  d | _	d S | jrf| j
  | j	rv| j	
  | j D ]}|D ]\}}|  qq| jD ]}|  q| jD ]}|d ur|  qW | j  | j  | j  d | _| j  d | _	n6| j  | j  | j  d | _| j  d | _	0 d S rF   )r   rX   rk   r   clearr   r   r   r   r   r   r   r{   r   )rA   datar   t0rs   rB   rB   rC   r     sJ    

















zBaseConnector._closec                 C   s   | j S )z;Is connector closed.

        A readonly property.
        )r   rH   rB   rB   rC   r~     s    zBaseConnector.closedrS   r?   c                 C   s   | j rV| j t| j }| jr|dkr|| jv r| j|}|dusFJ | jt| }n<| jr|| jv r| j|}|dus~J | jt| }nd}|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.
        r   Nr   )r   lenr   r   r   get)rA   rS   	availableZacquiredrB   rB   rC   _available_connections  s"    	z$BaseConnector._available_connectionsr'   r9   r7   reqtracesr   r?   c                    s  |j }| |}|dks$|| jv r(| j }| j| | |rZ|D ]}| I dH  qFzz|I dH  W nZ ty } zB|| jv rz| j| | W n t	y   Y n0 |W Y d}~n
d}~0 0 W || jv r| j| s| j|= n"|| jv r| j| s| j|= 0 |r(|D ]}|
 I dH  q| |}	|	du r6ttt }
| j|
 | j| |
 |r|D ]}| I dH  qnz0| |||I dH }	| jr|	  tdW n> ty   | js| j|
 | ||
 |    Y n"0 | js| j|
 | ||
 |r|D ]}| I dH  qn`|rttt }
| j|
 | j| |
 |D ]}| I dH  qh| j|
 | ||
 | j|	 | j| |	 t| ||	| jS )z'Get from pool or create new connection.r   NzConnector is closed.)connection_keyr   r   rX   Zcreate_futureru   Zsend_connection_queued_startBaseExceptionr   r   Zsend_connection_queued_end_getr   r&   r   r   addr   Zsend_connection_create_start_create_connectionr   r{   r   r   _release_waiterZsend_connection_create_endZsend_connection_reuseconnrQ   )rA   r   r   r   rS   r   futtraceer   placeholderrB   rB   rC   connect  sx    






zBaseConnector.connectc                 C   s   z| j | }W n ty"   Y d S 0 | j }|r| \}}| r|| | jkr||j}|  |j	r| j
s| j| q|s| j |= |S q.|j}|  |j	r.| j
s.| j| q.| j |= d S rr   )r   KeyErrorrX   r   popr}   r   rs   r{   r   r   r   ru   )rA   rS   r   t1r   r   rs   rB   rB   rC   r   =  s,    
zBaseConnector._getc                 C   sp   | j s
dS t| j  }t| |D ]D}| |dk r:q&| j | }|r&| }| sD|d  dS qDq&dS )z
        Iterates over all waiters until one to be released is found.

        The one to be released is not finsihed and
        belongs to a host that has available connections.
        Nr   )	r   listkeysrandomshuffler   popleftdoneZ
set_result)rA   ZqueuesrS   waiterswaiterrB   rB   rC   r   \  s    


zBaseConnector._release_waiter)rS   r   r?   c                 C   sF   | j r
d S z| j| | || W n ty8   Y n
0 |   d S rr   )r   r   r   r   r   r   )rA   rS   r   rB   rB   rC   _release_acquiredv  s    zBaseConnector._release_acquiredrf   )rS   rT   rg   r?   c                C   s   | j r
d S | || | jr d}|s*|jrR|j}|  |jr| js| j	| nV| j
|}|d u rtg  }| j
|< |	|| j f | jd u rt| d| j| j| _d S )NTr   )r   r   r   rg   rs   r{   r   r   r   ru   r   r   rX   r   r   r   r   r   )rA   rS   rT   rg   rs   r   rB   rB   rC   rl     s$    

zBaseConnector._releasec                    s
   t  d S rr   )NotImplementedError)rA   r   r   r   rB   rB   rC   r     s    z BaseConnector._create_connection)NNN)0rM   rN   rO   r   r   r`   r   r/   r   objectr   r   intr   r   r   rD   rI   r   rL   r   r   r   r   r   r	   r   r   r   r   r   r   r&   r   r   r   r{   r   r~   r   r   rQ   r   r   r   r   rl   r   rB   rB   rB   rC   r3      s   5   
*%"
S"
r3   c                   @   s   e Zd Zdee ddddZeedddZe	e
ef eee
ef  ddd	d
Ze	e
ef ddddZddddZe	e
ef eee
ef  dddZe	e
ef edddZdS )_DNSCacheTableN)ttlr?   c                 C   s   i | _ i | _|| _d S rr   )	_addrs_rr_timestamps_ttl)rA   r   rB   rB   rC   rD     s    z_DNSCacheTable.__init__)hostr?   c                 C   s
   || j v S rr   )r   )rA   r   rB   rB   rC   __contains__  s    z_DNSCacheTable.__contains__)rS   addrsr?   c                 C   s,   t |t|f| j|< | jr(t | j|< d S rr   )r   r   r   r   r   r   )rA   rS   r   rB   rB   rC   r     s    z_DNSCacheTable.addr   c                 C   s&   | j |d  | jr"| j|d  d S rr   )r   r   r   r   rA   rS   rB   rB   rC   r     s    z_DNSCacheTable.removerE   c                 C   s   | j   | j  d S rr   )r   r   r   rH   rB   rB   rC   r     s    
z_DNSCacheTable.clearc                 C   s(   | j | \}}tt||}t| |S rr   )r   r   r   next)rA   rS   rU   lengthr   rB   rB   rC   
next_addrs  s    z_DNSCacheTable.next_addrsc                 C   s$   | j d u rdS | j| | j  t k S r@   )r   r   r   r   rB   rB   rC   expired  s    
z_DNSCacheTable.expired)N)rM   rN   rO   r   r   rD   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rB   rB   rB   rC   r     s   &$r   c                       s`  e Zd ZdZdddddddddeddddddeee eee eee	 e
deee	f eeeef  ee e
deef eeeeeej d fd	d
Zed d fddZeedddZeedddZd<ee ee ddddZd=eeeed  eeeef  dddZded dedddZe e!"dee	ddd Z#dee	 d!d"d#Z$ded$ d!d%d&Z%e&d'edde'e( eeej)ef d(d)d*Z*ddd!d+d,Z+ddd-d.Z,edd/d0Z-ej)ddd1d2d3Z.e&fej)dde'e( eej/ef d4d5d6Z0e&d'ded de'e( eej)ef d7d8d9Z1ded deej/ef dd:d;Z2  Z3S )>r4   a/  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/Transport_Layer_Security#Certificate_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.
    loop - Optional event loop.
    TN
   r   Fr   )
verify_sslfingerprintuse_dns_cachettl_dns_cachefamilyssl_contextssl
local_addrresolverr   r   r   r   r   rU   c                   sj   t  j|
|||||d t||||| _|	d u r<t| jd}	|	| _|| _t|d| _	i | _
|| _|| _d S )Nr   r   )r   )superrD   r)   _sslr2   rX   	_resolver_use_dns_cacher   _cached_hosts_throttle_dns_events_family_local_addr)rA   r   r   r   r   r   r   r   r   r  r   r   r   r   r   rU   	__class__rB   rC   rD     s"    	zTCPConnector.__init__rE   c                    s"   | j  D ]}|  q
t  S )zClose all ongoing DNS calls.)r  r   r   r  r{   )rA   Zevr
  rB   rC   r{     s    
zTCPConnector.closec                 C   s   | j S )zSocket family like AF_INET.)r  rH   rB   rB   rC   r     s    zTCPConnector.familyc                 C   s   | j S )z%True if local DNS caching is enabled.)r  rH   rB   rB   rC   r     s    zTCPConnector.use_dns_cache)r   portr?   c                 C   sJ   |dur"|dur"| j ||f n$|dus2|dur<tdn
| j   dS )z8Remove specified host/port or clear all dns local cache.Nz5either both host and port or none of them are allowed)r  r   r   r   )rA   r   r  rB   rB   rC   clear_dns_cache$  s
    
zTCPConnector.clear_dns_cacher9   )r   r  r   r?   c              
      s(  t |r|||| jdddgS | js~|rB|D ]}||I d H  q,| jj||| jdI d H }|rz|D ]}||I d H  qd|S ||f}|| jv r| j|s| j	|}|r|D ]}|
|I d H  q|S || jv r| j| }|r|D ]}|
|I d H  q| I d H  nt| j| j|< |rB|D ]}||I d H  q*zz~|rh|D ]}||I d H  qP| jj||| jdI d H }	|r|D ]}||I d H  q| j||	 | j|   W n: ty }
 z | j| j|
d  W Y d }
~
n
d }
~
0 0 W | j| n| j| 0 | j	|S )Nr   )hostnamer   r  r   r   flags)r   )r   )r-   r  r  Zsend_dns_resolvehost_startr  resolveZsend_dns_resolvehost_endr  r   r   Zsend_dns_cache_hitr  waitr1   rX   Zsend_dns_cache_missr   r   r   r   )rA   r   r  r   r   resrS   resulteventr   r   rB   rB   rC   _resolve_host/  sd    
zTCPConnector._resolve_hostr'   r7   r   c                    s<   |j r | |||I dH \}}n| |||I dH \}}|S )zcCreate connection.

        Has same keyword arguments as BaseEventLoop.create_connection.
        N)proxy_create_proxy_connection_create_direct_connection)rA   r   r   r   _r   rB   rB   rC   r   {  s    zTCPConnector._create_connection)verifiedr?   c              
   C   s   | rt  S t t j}| jt jO  _| jt jO  _d|_t j|_	z| jt j
O  _W n4 ty } ztd| W Y d }~n
d }~0 0 |  |S d S )NFz{!s}: The Python interpreter is compiled against OpenSSL < 1.0.0. Ref: https://docs.python.org/3/library/ssl.html#ssl.OP_NO_COMPRESSION)r   create_default_context
SSLContextPROTOCOL_TLS_CLIENToptionsOP_NO_SSLv2OP_NO_SSLv3check_hostname	CERT_NONEverify_modeOP_NO_COMPRESSIONAttributeErrorrI   rJ   formatset_default_verify_paths)r  
sslcontextZattr_errrB   rB   rC   _make_ssl_context  s"    zTCPConnector._make_ssl_context)r   r?   c                 C   sz   |  rrtdu rtd|j}t|tjr.|S |dur@| dS | j}t|tjrV|S |durh| dS | dS dS dS )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
        NzSSL is not supported.FT)r   r   RuntimeError
isinstancer  r)  r  )rA   r   r(  rB   rB   rC   _get_ssl_context  s    


zTCPConnector._get_ssl_contextr(   c                 C   s,   |j }t|tr|S | j}t|tr(|S d S rr   )r   r+  r(   r  )rA   r   retrB   rB   rC   _get_fingerprint  s    

zTCPConnector._get_fingerprintclient_error)argsr   r   r0  rn   r?   c             
      s  z\t |j4 I d H 0 | jj|i |I d H W  d   I d H  W S 1 I d H sP0    Y  W n ty } zt|j||W Y d }~nd }~0  ty } zt|j||W Y d }~nTd }~0  t	y } z2|j
d u rt|tjr ||j||W Y d }~n
d }~0 0 d S rr   )r+   sock_connectrX   create_connectionr$   r   r   r%   r   OSErrorerrnor+  r   TimeoutError)rA   r   r   r0  r1  rn   r   rB   rB   rC   _wrap_create_connection  s    H""z$TCPConnector._wrap_create_connectionc                 C   s8   |  sdS |j}|dusJ |jdkr,dS |   dS )aW  Raise a :py:exc:`RuntimeError` on missing ``start_tls()``.

        One case is that :py:meth:`asyncio.loop.start_tls` is not yet
        implemented under Python 3.6. 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.
        Nhttps)r   r  scheme_check_loop_for_start_tls)rA   r   	proxy_urlrB   rB   rC   _fail_on_no_start_tls  s    	
z"TCPConnector._fail_on_no_start_tlsc              
   C   s@   z| j j W n. ty: } ztd|W Y d }~n
d }~0 0 d S )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.7 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
)rX   	start_tlsr%  r*  )rA   Zattr_excrB   rB   rC   r:    s    z&TCPConnector._check_loop_for_start_tlsc                 C   s*   z|    W n ty    Y dS 0 dS d S )NFT)r:  r*  rH   rB   rB   rC   _loop_supports_start_tls  s
    z%TCPConnector._loop_supports_start_tls)underlying_transportr   r?   c                 C   s<   |j jjdkrdS t|dd}|r&dS tjdt| dd dS )z6Issue a warning if the requested URL has HTTPS scheme.r8  NZ_start_tls_compatibleFa  An HTTPS request is being sent through an HTTPS proxy. This support for TLS in TLS is known to be disabled in the stdlib asyncio. This is why you'll probably see an error in the log below.

It is possible to enable it via monkeypatching under Python 3.7 or higher. 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
   )re   rq   )request_infourlr9  getattrrI   rJ   RuntimeWarning)rA   r?  r   Zasyncio_supports_tls_in_tlsrB   rB   rC   _warn_about_tls_in_tls
  s    z#TCPConnector._warn_about_tls_in_tls)r?  r   r   r0  r?   c                    s  |   }ttj| |}zt|j4 I dH X z$| jj||||j	|j
dI dH }W n typ   |   Y n0 W d  I dH  q1 I dH s0    Y  W n ty } zt|j||W Y d}~nd}~0  ty } zt|j||W Y d}~nd}~0  tyT } z6|jdu r2t|tjr2 ||j||W Y d}~nd}~0  ty }	 zFtd|j	d|jdd|jd|jpd d	|	d
|	W Y d}	~	n2d}	~	0 0 |du rd}
||jt|
|| ||fS )z$Wrap the raw TCP transport with TLS.N)server_hostnameZ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   r   r   r  r,  r+   r2  rX   r=  r   totalr   r{   r$   r   r   r%   r   r4  r5  r+  r   r6  	TypeErrorr   r  r  Zconnection_made)rA   r?  r   r   r0  Z	tls_protor(  Ztls_transportr   Ztype_errmsgrB   rB   rC   _start_tls_connection/  s\    8$""

z"TCPConnector._start_tls_connection)r   r   r   r0  r?   c                   s  |  |}| |}|jj}|d us(J |j}|d us:J tj| j|||d| jd}	zt	|	I d H }
W nx tj
y   dd ddd}|	|  Y nJ ty } z2|jd u rt|tjr t|j||W Y d }~n
d }~0 0 d }|
D ]}|d }|d }zN| j| j|||||d	 |d
 |d |r4|d nd | j||dI d H \}}W n6 ty } z|}W Y d }~qW Y d }~n
d }~0 0 | r|rz|| W nR ty } z8|  | js| j| |}W Y d }~qW Y d }~n
d }~0 0 ||f  S |d usJ |d S )N)r   r   z$asyncio.Future[List[Dict[str, Any]]])r   r?   c                 S   s8   t ttj |   W d    n1 s*0    Y  d S rr   )r   rw   r   CancelledErrorr  )r   rB   rB   rC   drop_exception  s    z>TCPConnector._create_direct_connection.<locals>.drop_exceptionr   r  r   r   r  r  )	r   r   r   r   r  rF  r   r   r0  )r,  r.  rB  Zraw_hostr  r   Zensure_futurer  rX   ZshieldrO  Zadd_done_callbackr4  r5  r+  r6  r   r   r7  r   r	  r   checkr"   r{   r   r   ru   )rA   r   r   r   r0  r(  r   r   r  Zhost_resolvedhostsrP  r   last_excZhinfoZtranspr   rB   rB   rC   r  m  sj    


$
""z&TCPConnector._create_direct_connectionc                    s  |  | |  }i }|jd ur&|j}|jtj |tj< |j}|d usJJ ttj|||j	| j
|jd}| j|g |tdI d H \}}	|	  |jtjd }
|
d ur| s|
|jtj< n|
|jtj< | r|r| || tj|_|j|_tj|jd d d d}t| ||	| j
}||I d H }zz4|j}|d us<J |j|d ||I d H }W n( ty   |   |    Y n"0 d |_d |_!zzv|j"dkr|j#}|d u rt$|j" d }t%|j&|j'|j"||jd|s|j(dd d	}|d u rt)d
|* }W n ty&   |    Y n0 W |sJ|   n|sH|   0 |s| +|}| j,| j-||||j.|dI d H W |   S | j/|||dI d H W |   S W |   n
|   0 ||	fS )N)headersauthrU   r   r/  )r  
proxy_authZproxy_headers_hash)Zread_until_eof   r   )statusrh   rT  socket)rI  z)Transport does not expose socket instance)r   r   sockrF  r   )r   r   )0r<  r>  proxy_headersrT  r   ZHOSTr  r'   ZMETH_GETrV  rX   r   r  r!   r   r   ZAUTHORIZATIONr   ZPROXY_AUTHORIZATIONrE  ZMETH_CONNECTmethodrB  attrZevolver   rQ   sendrY   Zset_response_paramsstartr   r{   r   rX  reasonr0   r    rA  historyZget_extra_infor*  dupr,  r7  r   r   rN  )rA   r   r   r   Zruntime_has_start_tlsrT  rB  Z	proxy_reqrs   r   rU  rS   connZ
proxy_resprT   resprh   Zrawsockr(  rB   rB   rC   r    s    











	z%TCPConnector._create_proxy_connection)NN)N)4rM   rN   rO   r   r/   r   r   bytesr   r  r   r(   r   r   r   r   r   r   r   rD   r   r{   r   r   r   r  r   r   r   r  r&   r   staticmethodr   	lru_cacher)  r,  r.  r   r   rw   r   r7  r<  r:  r>  rE  ZBaseTransportrN  r  r  __classcell__rB   rB   r
  rC   r4     s   '  M
!
*DO
r4   c                	       sx   e Zd ZdZdedddfeeeee	df e
e
eej dd fddZeed	d
dZded dedddZ  ZS )r5   a  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.
    Fr   r   Npathr   r   r   r   rU   r?   c                    s    t  j|||||d || _d S )Nr   r   r   r   rU   )r  rD   _pathrA   rj  r   r   r   r   rU   r
  rB   rC   rD   I  s    	zUnixConnector.__init__rE   c                 C   s   | j S )zPath to unix socket.rl  rH   rB   rB   rC   rj  [  s    zUnixConnector.pathr'   r9   r7   r   c              
      s   z^t |j4 I d H 2 | j| j| jI d H \}}W d   I d H  q\1 I d H sR0    Y  W nN ty } z6|jd u rt|t	j
r t| j|j||W Y d }~n
d }~0 0 tt|S rr   )r+   r2  rX   Zcreate_unix_connectionr   rl  r4  r5  r+  r   r6  r#   rj  r   r   r&   rA   r   r   r   r  r   r   rB   rB   rC   r   `  s    <(z UnixConnector._create_connectionrM   rN   rO   r   r/   r   r   r   r   r   r   r   r   r   rD   r   rj  r   r&   r   rh  rB   rB   r
  rC   r5   =  s(   
r5   c                	       sx   e Zd ZdZdedddfeeeee	df e
e
eej dd fddZeed	d
dZded dedddZ  ZS )r6   a   Named pipe connector.

    Only supported by the proactor event loop.
    See also: https://docs.python.org/3.7/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.
    Fr   r   Nri  c                    s6   t  j|||||d t| jtjs,td|| _d S )Nrk  z9Named Pipes only available in proactor loop under windows)r  rD   r+  rX   r   ZProactorEventLoopr*  rl  rm  r
  rB   rC   rD     s    	zNamedPipeConnector.__init__rE   c                 C   s   | j S )zPath to the named pipe.rn  rH   rB   rB   rC   rj    s    zNamedPipeConnector.pathr'   r9   r7   r   c              
      s   znt |j4 I d H B | j| j| jI d H \}}tdI d H  W d   I d H  ql1 I d H sb0    Y  W nJ ty } z2|j	d u rt
|tjr t|j||W Y d }~n
d }~0 0 tt|S )Nr   )r+   r2  rX   Zcreate_pipe_connectionr   rl  r   sleepr4  r5  r+  r6  r   r   r   r&   ro  rB   rB   rC   r     s    >$z%NamedPipeConnector._create_connectionrp  rB   rB   r
  rC   r6   p  s(   
r6   )Xr   r   r   r^   r\   rI   collectionsr   r   
contextlibr   http.cookiesr   	itertoolsr   r   r   r   typesr	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   r   r   abcr   Zclient_exceptionsr   r   r   r   r    r!   r"   r#   r$   r%   Zclient_protor&   Zclient_reqrepr'   r(   r)   r*   r+   r,   r-   r.   r/   httpr0   locksr1   r  r2   r   r  ImportErrorr   __all__clientr7   r8   tracingr9   r:   rQ   r   r3   r   r4   r5   r6   rB   rB   rB   rC   <module>   s`   @0 

Z   l'    n3