B `ا@sNddlZddlZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z ddl mZmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#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/m0Z0m1Z1m2Z2d d l3m4Z4d dl5m6Z6m7Z7m8Z8d dl&m9Z9m:Z:m;Z;mZ>d dl?m@Z@d dlAmBZBd dlCmDZDyddlEZEeEjFZFWneGk rdZEeHZFYnXdZIerd dlJmKZKd dl5mLZLd dlMmNZNGdddZOGdddZPGdddZQGdddZRGdd d ZSGd!d"d"eRZTGd#d$d$eRZUGd%d&d&eRZVdS)'N) defaultdictdeque)suppress) SimpleCookie)cycleislice) monotonic) TracebackType) TYPE_CHECKINGAny AwaitableCallable DefaultDictDictIteratorListOptionalSetTupleTypeUnioncast)hdrshelpers)AbstractResolver) ClientConnectionErrorClientConnectorCertificateErrorClientConnectorErrorClientConnectorSSLErrorClientHttpProxyErrorClientProxyConnectionErrorServerFingerprintMismatch cert_errors ssl_errors)ResponseHandler) ClientRequest Fingerprint_merge_ssl_params)PY_36 CeilTimeoutget_running_loop is_ip_addressnoopsentinel) RESPONSES)EventResultOrError)DefaultResolver) BaseConnector TCPConnector UnixConnectorNamedPipeConnector) ClientTimeout) ConnectionKey)Tracec@s@eZdZdZeeddddZedddZddd d ZdS) _DeprecationWaiter) _awaitable_awaitedN) awaitablereturncCs||_d|_dS)NF)r:r;)selfr<r?l/private/var/folders/7j/8686xlfs15q3tgljmghtvg0r0000gn/T/pip-target-isidps9b/lib/python/aiohttp/connector.py__init__Isz_DeprecationWaiter.__init__)r=cCsd|_|jS)NT)r;r: __await__)r>r?r?r@rBMsz_DeprecationWaiter.__await__cCs|jstdtdS)NzDConnector.close() is a coroutine, please use await connector.close())r;warningswarnDeprecationWarning)r>r?r?r@__del__Qsz_DeprecationWaiter.__del__) __name__ __module__ __qualname__ __slots__r r rArBrFr?r?r?r@r9Fsr9c@seZdZdZdZddeejddddZe ddd Z e fe dd d d Z eejdd dZeeejdddZeeedddZegdfddddZddddZddddZddddZeedddZdS) ConnectionNr2r7) connectorkeyprotocolloopr=cCs<||_||_||_||_g|_|r8tt d|_ dS)Nr) _key _connector_loop _protocol _callbacks get_debug traceback extract_stacksys _getframe_source_traceback)r>rLrMrNrOr?r?r@rA_szConnection.__init__)r=cCsd|jdS)Nz Connection<>)rP)r>r?r?r@__repr__oszConnection.__repr__) _warningsr=cCs|jdk rtrd|i}ni}|jd|tf||jr@dS|jj|j|jdd|dd}|j dk rt|j |d<|j |dS)NsourcezUnclosed connection T) should_closezUnclosed connection)Zclient_connectionmessagesource_traceback) rSr)rDResourceWarningrR is_closedrQ_releaserPrZcall_exception_handler)r>r]kwargscontextr?r?r@rFrs      zConnection.__del__cCstjdtdd|jS)Nz%connector.loop property is deprecated) stacklevel)rCrDrErR)r>r?r?r@rOs zConnection.loopcCs|jdkrdS|jjS)N)rS transport)r>r?r?r@rjs zConnection.transportcCs|jS)N)rS)r>r?r?r@rNszConnection.protocol)callbackr=cCs|dk r|j|dS)N)rTappend)r>rkr?r?r@ add_callbackszConnection.add_callbackc CsB|jddg}|_x&|D]}tt |WdQRXqWdS)N)rTr Exception)r> callbackscbr?r?r@_notify_releases  zConnection._notify_releasecCs2||jdk r.|jj|j|jddd|_dS)NT)r_)rqrSrQrdrP)r>r?r?r@closes zConnection.closecCs6||jdk r2|jj|j|j|jjdd|_dS)N)r_)rqrSrQrdrPr_)r>r?r?r@releases  zConnection.releasecCs|jdkp|j S)N)rS is_connected)r>r?r?r@closedszConnection.closed)rGrHrIrZ _transportr%asyncioAbstractEventLooprAstrr\rCr rFpropertyrOr TransportrjrNr rmrqrrrsboolrur?r?r?r@rKZs*  rKc@seZdZdZddddZdS)_TransportPlaceholderz0 placeholder for BaseConnector.connect function N)r=cCsdS)Nr?)r>r?r?r@rrsz_TransportPlaceholder.close)rGrHrI__doc__rrr?r?r?r@r}sr}c @seZdZdZdZdZdZeddddddee de fe e e e e ejdd d d Zefedd d dZddddZeddddZddddZdDe eee ee eddddZee dddZee dddZee dddZddd d!Zd"e dd#d$d%Z!ddd&d'Z"e#ddd(d)Z$ddd*d+Z%ee dd,d-Z&d"e d.d/d0Z'd1e(d2d3e)d4d5d6Z*d"e e d.d7d8Z+ddd9d:Z,d"e dd;dd"e e dd?d@dAZ.d1e(d2d3e d4dBdCZ/dS)Er2aBase 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@Fdr)keepalive_timeout force_closelimitlimit_per_hostenable_cleanup_closedrO)rrrrrrOr=cCs|r|dk r*|tk r*tdn |tkr*d}t|}d|_|rRttd|_ i|_ ||_ ||_ t |_tt |_tt||_||_tt|_||_tjt|d|_t|_d|_d|_| |_ g|_!|"dS)Nz6keepalive_timeout cannot be set if force_close is Trueg.@Fr)rO)#r. ValueErrorr+_closedrUrVrWrXrYrZ_conns_limit_limit_per_hostset _acquiredr_acquired_per_hostrfloat_keepalive_timeout _force_closer_waitersrR functoolspartialr%_factoryrcookies_cleanup_handle_cleanup_closed_handle_cleanup_closed_disabled_cleanup_closed_transports_cleanup_closed)r>rrrrrrOr?r?r@rAs6   zBaseConnector.__init__)r]r=cCs|jr dS|jsdSdd|jD}|tr>d|i}ni}|jd|tf|||dd}|jdk rx|j|d<|j |dS)NcSsg|] }t|qSr?)repr).0cr?r?r@ sz)BaseConnector.__del__..r^zUnclosed connector zUnclosed connector)rL connectionsr`ra) rrvalues_closer)rDrbrZrRre)r>r]connsrfrgr?r?r@rFs    zBaseConnector.__del__)r=cCstdt|S)NzH"witn Connector():" is deprecated, use "async with Connector():" instead)rCrDrE)r>r?r?r@ __enter__szBaseConnector.__enter__)excr=cGs |dS)N)rr)r>rr?r?r@__exit__%szBaseConnector.__exit__cs|S)Nr?)r>r?r?r@ __aenter__(szBaseConnector.__aenter__)exc_type exc_value exc_tracebackr=cs|IdHdS)N)rr)r>rrrr?r?r@ __aexit__+szBaseConnector.__aexit__cCs|jS)z1Ultimately close connection on releasing if True.)r)r>r?r?r@r3szBaseConnector.force_closecCs|jS)zThe total number for simultaneous connections. If limit is 0 the connector has no limit. The default limit size is 100. )r)r>r?r?r@r8szBaseConnector.limitcCs|jS)zThe limit_per_host for simultaneous connections to the same endpoint. Endpoints are the same if they are have equal (host, port, is_ssl) triple. )r)r>r?r?r@rAs zBaseConnector.limit_per_hostc Cs |jr|jd|_|j}|j}|jri}||}x|jD]\}}g}x|D]z\}} |r| |dkr|j} | |j r|j s|j | q| || fqV|j} | |j rV|j sV|j | qVW|rD|||<qDW||_|jrt|d||j|_dS)zCleanup unused transports.Nr_cleanup)rcancelrRtimerritemsrtrjrris_sslrrrlrweakref_handle) r>nowtimeoutrdeadlinerMraliveprotoZuse_timerjr?r?r@rLs8      zBaseConnector._cleanupr7)rMvalr=cCs4|j}||krdS||}|||s0|j|=dS)N)rremove)r>rMrZacquired_per_hostrr?r?r@_drop_acquired_per_hostus z%BaseConnector._drop_acquired_per_hostcCsV|jr|jx|jD]}|dk r|qWg|_|jsRt|d|j|j|_dS)z}Double confirmation for transport close. Some broken ssl servers may leave socket open without proper close. Nr) rrrabortrrr_cleanup_closed_periodrR)r>rjr?r?r@rs   zBaseConnector._cleanup_closedcCs|ttS)zClose all opened transports.)rr9r-)r>r?r?r@rrszBaseConnector.closecCs|jr dSd|_z|jr dS|jr0|j|jr@|jx,|jD]}x|D]\}}|qVWqLWx|j D] }|qvWx|j D]}|dk r| qWWd|j |j |j d|_|j d|_XdS)NT)rrRrcrrrrrrrrrrclearr)r>datart0rjr?r?r@rs0          zBaseConnector._closecCs|jS)z;Is connector closed. A readonly property. )r)r>r?r?r@ruszBaseConnector.closed)rMr=cCs|jrV|jt|j}|jr|dkr||jkr|j|}|dk sFt|jt|}n<|jr||jkr|j|}|dk s~t|jt|}nd}|S)z Return number of available connections taking into account the limit, limit_per_host and the connection key. If it returns less than 1 means that there is no connections availables. rNr)rlenrrrgetAssertionError)r>rM availableZacquiredr?r?r@_available_connectionss      z$BaseConnector._available_connectionsr&r8r6)reqtracesrr=c sv|j}||}|dks$||jkr|j}|j|||r^x|D]}|IdHqHWzny|IdHWnZtk r}z<||jkry|j||Wnt k rYnX|Wdd}~XYnXWd||jkr|j|s|j|=X|rx|D]}| IdHqW| |} | dkr&t t t} |j| |j|| |rnx|D]}|IdHqVWy0||||IdH} |jr| tdWn@tk r|js|j| ||| |Yn"X|js|j| ||| |rJxB|D]}|IdHq Wn$|rJx|D]}|IdHq2W|j| |j|| t||| |jS)z'Get from pool or create new connection.rNzConnector is closed.)connection_keyrrrRZ create_futurerlZsend_connection_queued_start BaseExceptionrrZsend_connection_queued_end_getrr%r}raddrZsend_connection_create_start_create_connectionrrrrr_release_waiterZsend_connection_create_endZsend_connection_reuseconnrK) r>rrrrMrfuttraceer placeholderr?r?r@connectsj                   zBaseConnector.connectcCsy|j|}Wntk r"dSX|j}x|r|\}}|r|||jkr~|j}||j r|j s|j |q|s|j|=|Sq0|j}||j r0|j s0|j |q0W|j|=dS)N) rKeyErrorrRrpoprtrrjrrrrrrl)r>rMrt1rrrjr?r?r@r2s,    zBaseConnector._getcCsv|js dSt|j}t|xN|D]F}||dkrZqueuesrMwaiterswaiterr?r?r@rQs    zBaseConnector._release_waiter)rMrr=cCsH|jr dSy|j||||Wntk r:Yn X|dS)N)rrrrrr)r>rMrr?r?r@_release_acquiredis zBaseConnector._release_acquired)r_)rMrNr_r=cCs|jr dS||||jr d}|s*|jrR|j}||jr|js|j |nV|j |}|dkrtg}|j |<| ||j f|jdkrt|d|j|j |_dS)NTr)rrrr_rjrrrrrrlrrrRrrrrr)r>rMrNr_rjrr?r?r@rdxs"     zBaseConnector._releasecs tdS)N)NotImplementedError)r>rrrr?r?r@rsz BaseConnector._create_connection)NNN)0rGrHrIr~rrZrr.robjectrr|intrrwrxrArCr rFrrrrrr rrzrrrrr%rrr rrrrurrrKrrrrrdrr?r?r?r@r2sV ". * %" K  r2c@seZdZdeeddddZeedddZe e e fe e e efddd d Ze e e fdd d d ZddddZe e e fe e e efd ddZe e e fed ddZdS)_DNSCacheTableN)ttlr=cCsi|_i|_||_dS)N) _addrs_rr _timestamps_ttl)r>rr?r?r@rAsz_DNSCacheTable.__init__)hostr=cCs ||jkS)N)r)r>rr?r?r@ __contains__sz_DNSCacheTable.__contains__)rMaddrsr=cCs,t|t|f|j|<|jr(t|j|<dS)N)rrrrrr)r>rMrr?r?r@rsz_DNSCacheTable.add)rMr=cCs&|j|d|jr"|j|ddS)N)rrrr)r>rMr?r?r@rsz_DNSCacheTable.remove)r=cCs|j|jdS)N)rrr)r>r?r?r@rs z_DNSCacheTable.clearcCs(|j|\}}tt||}t||S)N)rrrnext)r>rMrOlengthrr?r?r@ next_addrssz_DNSCacheTable.next_addrscCs$|jdkrdS|j||jtkS)NF)rrr)r>rMr?r?r@expireds z_DNSCacheTable.expired)N)rGrHrIrrrArr|rrryrrrr rrrrrr?r?r?r@rs&$rcseZdZdZdddddddddeddddddeeeeeeeee e dee e fee e efeee deefeeeeeejdfd d Zedd fd d Zeed ddZeed ddZd0ee eeddddZd1e eeedeee efdddZdeddedddZe e!"dee ddd Z#dee d!d"d#Z$ded$d!d%d&Z%e&d'edde'e(ee ej)efd(d)d*Z*e&d'dedde'e(e ej)efd+d,d-Z+dedde ej)efdd.d/Z,Z-S)2r3a/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 rFr) verify_ssl fingerprint use_dns_cache ttl_dns_cachefamily ssl_contextssl local_addrresolverrrrrrrOcsjtj| | | | ||dt|||||_| dkrrrrrrrrrrrrrrrrO) __class__r?r@rAs   zTCPConnector.__init__)r=cs&x|jD] }|q WtS)zClose all ongoing DNS calls.)rrrrrr)r>Zev)rr?r@rr s zTCPConnector.closecCs|jS)zSocket family like AF_INET.)r)r>r?r?r@rszTCPConnector.familycCs|jS)z%True if local DNS caching is enabled.)r)r>r?r?r@rszTCPConnector.use_dns_cache)rportr=cCsJ|dk r"|dk r"|j||fn$|dk s2|dk rrrr?r?r@clear_dns_caches  zTCPConnector.clear_dns_cacher8)rrrr=c s8t|r||||jdddgS|js|rFx|D]}||IdHq.W|jj|||jdIdH}|rx|D]}||IdHqjW|S||f}||jkr|j|s|j |}|rx|D]}| |IdHqW|S||j kr"|j |}|rx|D]}| |IdHqW| IdHn t |j|j |<|rXx|D]}||IdHq>Wzy|rx|D]}||IdHqhW|jj|||jdIdH} |rx|D]}||IdHqW|j|| |j |Wn8tk r} z|j |j| dWdd} ~ XYnXWd|j |X|j |S)Nr)hostnamerrrrflags)r)r)r,rrZsend_dns_resolvehost_startrresolveZsend_dns_resolvehost_endrrrZsend_dns_cache_hitrwaitr0rRZsend_dns_cache_missrrrr) r>rrrrresrMresulteventrrr?r?r@ _resolve_host&s`           zTCPConnector._resolve_hostr&r6)rrrr=cs<|jr ||||IdH\}}n||||IdH\}}|S)zcCreate connection. Has same keyword arguments as BaseEventLoop.create_connection. N)proxy_create_proxy_connection_create_direct_connection)r>rrr_rr?r?r@rrszTCPConnector._create_connection)verifiedr=c Cs|r tSttj}|jtjO_|jtjO_y|jtjO_Wn2tk r~}zt d |Wdd}~XYnX| |SdS)Nz{!s}: The Python interpreter is compiled against OpenSSL < 1.0.0. Ref: https://docs.python.org/3/library/ssl.html#ssl.OP_NO_COMPRESSION) rcreate_default_context SSLContextPROTOCOL_SSLv23options OP_NO_SSLv2 OP_NO_SSLv3OP_NO_COMPRESSIONAttributeErrorrCrDformatset_default_verify_paths)r  sslcontextZattr_errr?r?r@_make_ssl_contexts zTCPConnector._make_ssl_context)rr=cCsz|rrtdkrtd|j}t|tjr.|S|dk r@|dS|j}t|tjrV|S|dk rh|dS|dSdSdS)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.FT)rr RuntimeError isinstancer rr)r>rrr?r?r@_get_ssl_contexts     zTCPConnector._get_ssl_contextr'cCs,|j}t|tr|S|j}t|tr(|SdS)N)rrr'r)r>rretr?r?r@_get_fingerprints  zTCPConnector._get_fingerprint) client_error)argsrrrrfr=c sy*t|j|jj||IdHSQRXWntk rZ}zt|j||Wdd}~XYn^tk r}zt|j||Wdd}~XYn0t k r}z||j||Wdd}~XYnXdS)N) r* sock_connectrRcreate_connectionr#rrr$rOSError)r>rrrrrfrr?r?r@_wrap_create_connections z$TCPConnector._wrap_create_connection)rrrrr=cs||}||}|jj}|dk s(t|j}|dk s:ttj|j|||d|j d} yt | IdH} Wn`tj k rddddd} | | Yn0t k r} zt|j| | Wdd} ~ XYnXd} x| D]}|d}|d}yN|j|j|||||d |d |d |r|d nd|j||d IdH\}}Wn*tk rd} z | } wWdd} ~ XYnX|r|ry||WnFtk r} z&||js|j|| } wWdd} ~ XYnX||fSW| dk st| dS)N)r)rOz$asyncio.Future[List[Dict[str, Any]]])rr=c Ss$tttj|WdQRXdS)N)rrnrwCancelledErrorr)rr?r?r@drop_exceptionsz>TCPConnector._create_direct_connection..drop_exceptionrrrrrr) rrrrrserver_hostnamerrr)rrurlZraw_hostrrrwZ ensure_futurerrRZshieldr#Zadd_done_callbackr!rrr"rrrcheckr"rrrrrl)r>rrrrrrrrZ host_resolvedhostsr$rlast_excZhinfoZtransprr?r?r@r sb         z&TCPConnector._create_direct_connectioncs*i}|jdk r|j}|jtj|tj<|j}|dk s8tttj|||j|j |j d}|j |g|t dIdH\}}| |jtjd} | dk r|s| |jtj<n | |jtj<|r"||} tj|_|j|_tj|jdddd} t|| ||j } || IdH} z y0| j}|dk s$t|| | IdH}Wn(tk rf| | YnXd| _d| _ zp|j!dkr|j"}|dkrt#|j!d}t$| j%|j&|j!||jd|j'ddd}|dkrt(d |)}Wd|X|j*|j+|| ||j,|d IdH\}}Wd| X||fS) N)headersauthrOr)r)r proxy_authZproxy_headers_hashr)statusr`r*socket)defaultz)Transport does not expose socket instance)rrsockr%r)- proxy_headersr*rZHOSTrrr&ZMETH_GETr,rRrr r!rrZ AUTHORIZATIONrZPROXY_AUTHORIZATIONrZ METH_CONNECTmethodr&attrZevolverrKsendrSZset_response_paramsstartrrrrvr.reasonr/r Z request_infohistoryZget_extra_infordupr"rr)r>rrrr*r&Z proxy_reqrjrr+rrMconnZ proxy_resprNrespr`Zrawsockr?r?r@rs             z%TCPConnector._create_proxy_connection)NN)N).rGrHrIr~r.r|rbytesrr rr'rryrrrrwrxrAr rrrzrrrrrr rr%r staticmethodr lru_cacherrrrrrnr{r"r r __classcell__r?r?)rr@r3sNl K  !F r3c sxeZdZdZdedddfeeeee dfe e e e j ddfdd Zeed d d Zd ed dedddZZS)r4aUnix 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. FrrN)pathrrrrrOr=cs tj|||||d||_dS)N)rrrrrO)rrA_path)r>r@rrrrrO)rr?r@rAs zUnixConnector.__init__)r=cCs|jS)zPath to unix socket.)rA)r>r?r?r@r@szUnixConnector.pathr&r8r6)rrrr=c sry6t|j"|j|j|jIdH\}}WdQRXWn0tk rf}zt|j||Wdd}~XYnXt t |S)N) r*rrRZcreate_unix_connectionrrAr!rrrr%)r>rrrr rrr?r?r@rs $ z UnixConnector._create_connection)rGrHrIr~r.ryr|rrrrrrwrxrArzr@rr%rr?r?r?)rr@r4s    r4c sxeZdZdZdedddfeeeee dfe e e e j ddfdd Zeed d d Zd ed dedddZZS)r5aNamed 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. FrrN)r@rrrrrOr=cs6tj|||||dt|jtjs,td||_dS)N)rrrrrOz9Named Pipes only available in proactor loop under windows)rrArrRrwZProactorEventLooprrA)r>r@rrrrrO)rr?r@rAs zNamedPipeConnector.__init__)r=cCs|jS)zPath to the named pipe.)rA)r>r?r?r@r@szNamedPipeConnector.pathr&r8r6)rrrr=c syFt|j2|j|j|jIdH\}}tdIdHWdQRXWn0tk rv}zt |j ||Wdd}~XYnXt t |S)Nr) r*rrRZcreate_pipe_connectionrrArwsleepr!rrrr%)r>rrrr rrr?r?r@rs  z%NamedPipeConnector._create_connection)rGrHrIr~r.ryr|rrrrrrwrxrArzr@rr%rr?r?r?)rr@r5s   r5)WrwrrrXrVrC collectionsrr contextlibr http.cookiesr itertoolsrrrrtypesr typingr r r r rrrrrrrrrrr4rrabcrZclient_exceptionsrrrrr r!r"r#r$Z client_protor%Z client_reqrepr&r'r(r)r*r+r,r-r.httpr/Zlocksr0rr1rr  ImportErrorr__all__clientr6r7tracingr8r9rKr}r2rr3r4r5r?r?r?r@s^    @ ,          Zg)<1