o ˆü?cµ˜ã@sÞddlmZddlZddlZddlZddlZddlZddlZddlmZ ddlm Z ddl m Z mZmZmZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$dd l%m&Z&dd l'm(Z(dd l)m*Z*dd l+m,Z,dd l-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ?ddl;m@Z@mAZAe$jBjCZCe DeE¡ZFeGƒZHGdd„deGƒZIejJejKhZLGdd„deIe(ƒZMGdd„deMƒZNdd„ZOdd „Z>dS)!é)Úabsolute_importN)Úerror©Útimeouté)Ú BaseSSLErrorÚBrokenPipeErrorÚDummyConnectionÚHTTPConnectionÚ HTTPExceptionÚHTTPSConnectionÚVerifiedHTTPSConnectionÚport_by_scheme) ÚClosedPoolErrorÚEmptyPoolErrorÚHeaderParsingErrorÚHostChangedErrorÚInsecureRequestWarningÚLocationValueErrorÚ MaxRetryErrorÚNewConnectionErrorÚ ProtocolErrorÚ ProxyErrorÚReadTimeoutErrorÚSSLErrorÚ TimeoutError)Úsix)Úqueue)ÚRequestMethods)Ú HTTPResponse)Úis_connection_dropped)Úconnection_requires_http_tunnel)Ú LifoQueue)Úset_file_position)Úassert_header_parsing)ÚRetry)ÚCertificateError)ÚTimeout)ÚUrlÚ_encode_target)Ú_normalize_host)Úget_hostÚ parse_urlc@sBeZdZdZdZeZd dd„Zdd„Zdd„Z d d „Z d d „Z dS)ÚConnectionPoola; Base class for all connection pools, such as :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`. .. note:: ConnectionPool.urlopen() does not normalize or percent-encode target URIs which is useful if your target server doesn't support percent-encoded target URIs. NcCs0|stdƒ‚t||jd�|_| ¡|_||_dS)NzNo host specified.©Úscheme)rr*r/ÚhostÚlowerÚ _proxy_hostÚport)Úselfr0r3©r5úq/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/urllib3/connectionpool.pyÚ__init__Ks   zConnectionPool.__init__cCsdt|ƒj|j|jfS)Nz%s(host=%r, port=%r))ÚtypeÚ__name__r0r3©r4r5r5r6Ú__str__SózConnectionPool.__str__cCs|S©Nr5r:r5r5r6Ú __enter__VszConnectionPool.__enter__cCs | ¡dS)NF)Úclose)r4Úexc_typeÚexc_valÚexc_tbr5r5r6Ú__exit__YszConnectionPool.__exit__cCódS)úD Close all pooled connections and disable the pool. Nr5r:r5r5r6r?^ózConnectionPool.closer=) r9Ú __module__Ú __qualname__Ú__doc__r/r"ÚQueueClsr7r;r>rCr?r5r5r5r6r-=s   r-c @sºeZdZdZdZeZeZdde j dddddddf dd„Z dd „Z d!d d „Z d d „Zdd„Zdd„Zdd„Zdd„Zedfdd„Zdd„Zdd„Zdd„Zdddddeddddf dd „ZdS)"ÚHTTPConnectionPoola: Thread-safe connection pool for one host. :param host: Host used for this HTTP Connection (e.g. "localhost"), passed into :class:`http.client.HTTPConnection`. :param port: Port used for this HTTP Connection (None is equivalent to 80), passed into :class:`http.client.HTTPConnection`. :param strict: Causes BadStatusLine to be raised if the status line can't be parsed as a valid HTTP/1.0 or 1.1 status line, passed into :class:`http.client.HTTPConnection`. .. note:: Only works in Python 2. This parameter is ignored in Python 3. :param timeout: Socket timeout in seconds for each individual connection. This can be a float or integer, which sets the timeout for the HTTP request, or an instance of :class:`urllib3.util.Timeout` which gives you more fine-grained control over request timeouts. After the constructor has been parsed, this is always a `urllib3.util.Timeout` object. :param maxsize: Number of connections to save that can be reused. More than 1 is useful in multithreaded situations. If ``block`` is set to False, more connections will be created but they will not be saved once they've been used. :param block: If set to True, no more than ``maxsize`` connections will be used at a time. When no free connections are available, the call will block until a connection has been released. This is a useful side effect for particular multithreaded situations where one does not want to use more than maxsize connections per host to prevent flooding. :param headers: Headers to include with all requests, unless other headers are given explicitly. :param retries: Retry configuration to use by default with requests in this pool. :param _proxy: Parsed proxy URL, should not be used directly, instead, see :class:`urllib3.ProxyManager` :param _proxy_headers: A dictionary with proxy headers, should not be used directly, instead, see :class:`urllib3.ProxyManager` :param \**conn_kw: Additional parameters are used to create fresh :class:`urllib3.connection.HTTPConnection`, :class:`urllib3.connection.HTTPSConnection` instances. ÚhttpNFrc KsÖt |||¡t ||¡||_t|tƒst |¡}|dur!tj}||_ ||_ |  |¡|_ ||_ | |_| p6i|_| |_t|ƒD]} |j  d¡q?d|_d|_| |_|jri|j dg¡|j|jd<|j|jd<dSdS)NrÚsocket_optionsÚproxyÚ proxy_config)r-r7rÚstrictÚ isinstancer'Ú from_floatr%ÚDEFAULTrÚretriesrJÚpoolÚblockrNÚ proxy_headersrOÚxrangeÚputÚnum_connectionsÚ num_requestsÚconn_kwÚ setdefault)r4r0r3rPrÚmaxsizerVÚheadersrTÚ_proxyÚ_proxy_headersÚ _proxy_configr\Ú_r5r5r6r7©s0       ùzHTTPConnectionPool.__init__cCsR|jd7_t d|j|j|jpd¡|jd|j|j|jj|jdœ|j ¤Ž}|S)z9 Return a fresh :class:`HTTPConnection`. rz(Starting new HTTP connection (%d): %s:%sÚ80)r0r3rrPNr5) rZÚlogÚdebugr0r3Ú ConnectionClsrÚconnect_timeoutrPr\©r4Úconnr5r5r6Ú _new_connßs üüûzHTTPConnectionPool._new_conncCs˜d}z |jj|j|d�}Wntyt|dƒ‚tjy*|jr(t|dƒ‚Ynw|rFt|ƒrFt   d|j ¡|  ¡t |ddƒdkrFd}|pK| ¡S) a™ Get a connection. Will return a pooled connection if one is available. If no connections are available and :prop:`.block` is ``False``, then a fresh connection is returned. :param timeout: Seconds to wait before giving up and raising :class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and :prop:`.block` is ``True``. N)rVrzPool is closed.z>Pool reached maximum size and no more connections are allowed.z Resetting dropped connection: %sÚ auto_openrr)rUÚgetrVÚAttributeErrorrrÚEmptyrr rerfr0r?Úgetattrrk)r4rrjr5r5r6Ú _get_connôs&   þú  zHTTPConnectionPool._get_connc Csfz |jj|dd�WdStyYntjy(t d|j|j ¡¡Ynw|r1|  ¡dSdS)aä Put a connection back into the pool. :param conn: Connection object for the current host and port as returned by :meth:`._new_conn` or :meth:`._get_conn`. If the pool is already full, the connection is closed and discarded because we exceeded maxsize. If connections are discarded frequently, then maxsize should be increased. If the pool is closed, then the connection will be closed and discarded. F©rVNzLConnection pool is full, discarding connection: %s. Connection pool size: %s) rUrYrnrÚFullreÚwarningr0Úqsizer?rir5r5r6Ú _put_conns ýþ ÿzHTTPConnectionPool._put_conncCrD)úU Called right before a request is made, after the socket is created. Nr5rir5r5r6Ú_validate_conn:rFz!HTTPConnectionPool._validate_conncCsdSr=r5rir5r5r6Ú_prepare_proxy@sz!HTTPConnectionPool._prepare_proxycCs.|tur |j ¡St|tƒr| ¡St |¡S)z:Helper that always returns a :class:`urllib3.util.Timeout`)Ú_DefaultrÚclonerQr'rR)r4rr5r5r6Ú _get_timeoutDs    zHTTPConnectionPool._get_timeoutcCsjt|tƒr t||d|ƒ‚t|dƒr|jtvrt||d|ƒ‚dt|ƒvs+dt|ƒvr3t||d|ƒ‚dS)zAIs the error actually a timeout? Will raise a ReadTimeout or passú!Read timed out. (read timeout=%s)Úerrnoz timed outzdid not complete (read)N)rQÚ SocketTimeoutrÚhasattrr~Ú_blocking_errnosÚstr)r4ÚerrÚurlÚ timeout_valuer5r5r6Ú_raise_timeoutPs  ÿ ÿÿ ÿýz!HTTPConnectionPool._raise_timeoutc KsX|jd7_| |¡}| ¡|j|_z| |¡Wnttfy3}z |j|||jd�‚d}~wwz|rB|j ||fi|¤Žn |j ||fi|¤ŽWn&t yVYnt ys}z|j t jt jt jhvri‚WYd}~nd}~ww|j} t|ddƒr�| dkr‰t||d| ƒ‚| tjur—|j t ¡¡n|j | ¡z3z|jdd�} Wn(tyÎz| ¡} WntyË}z t |d¡WYd}~nd}~wwYnwWntttfyè}z |j||| d�‚d}~wwt|d d ƒ} t  !d |j"|j#|j$||| | j%| j&¡ zt'| j(ƒW| St)tf�y+} zt j*d | +|¡| dd �WYd} ~ | Sd} ~ ww)a Perform a request on a given urllib connection object taken from our pool. :param conn: a connection from one of our connection pools :param timeout: Socket timeout in seconds for the request. This can be a float or integer, which will set the same timeout value for the socket connect and the socket read, or an instance of :class:`urllib3.util.Timeout`, which gives you more fine-grained control over your timeouts. r)rƒr„r…NÚsockrr}T)Ú bufferingÚ _http_vsn_strzHTTP/?z%s://%s:%s "%s %s %s" %s %sz$Failed to parse headers (url=%s): %s)Úexc_info),r[r|Ú start_connectrhrrxrrr†Úrequest_chunkedÚrequestrÚIOErrorr~ÚEPIPEÚ ESHUTDOWNÚ EPROTOTYPEÚ read_timeoutrprr'ÚDEFAULT_TIMEOUTr‡Ú settimeoutÚsocketÚgetdefaulttimeoutÚ getresponseÚ TypeErrorÚ BaseExceptionrÚ raise_fromÚ SocketErrorrerfr/r0r3ÚstatusÚlengthr$ÚmsgrrtÚ _absolute_url) r4rjÚmethodr„rÚchunkedÚhttplib_request_kwÚ timeout_objÚer’Úhttplib_responseÚ http_versionÚhper5r5r6Ú _make_requestis  €ý€ ý û€ü  ÿ    €ü€ü€ €þ ÷  øü€øz HTTPConnectionPool._make_requestcCst|j|j|j|d�jS)N)r/r0r3Úpath)r(r/r0r3r„)r4r©r5r5r6rŸàr<z HTTPConnectionPool._absolute_urlcCsP|jdurdS|jd}|_z |jdd�}|r| ¡qtjy'YdSw)rENTFrr)rUrmr?rro)r4Úold_poolrjr5r5r6r?ãs  ýÿzHTTPConnectionPool.closecCsx| d¡rdSt|ƒ\}}}|durt||d�}|jr#|s#t |¡}n |js/|t |¡kr/d}|||f|j|j|jfkS)zj Check if the given ``url`` is a member of the same host as this connection pool. ú/TNr.)Ú startswithr+r*r3rrmr/r0)r4r„r/r0r3r5r5r6Ú is_same_hostõs    zHTTPConnectionPool.is_same_hostTc Ksnt|ƒ}|j}|dur|j}t|tƒstj|||jd�}| dur&|  dd¡} |r3| |¡s3t |||ƒ‚|  d¡r@t   t |ƒ¡}nt   |j¡}d}| }t|j|j|ƒ}|s^| ¡}| |j¡d}d}t|| ƒ} zêzL| |¡}|j| d�}|j|_|jduoƒt|ddƒ }|r�|r�| |¡|j||||||| d �}| s�|nd}|| d <|jj|f|||d œ| ¤Ž}d}Wn‡tyÀd}d}‚t t!t"t#t$t%t&f�y;}zhd}d d „}t|t$ƒrò|jrò||ƒrò|jrò|jjdkròt'dt%|ƒƒ}n+t|t$t&fƒrþt%|ƒ}nt|t"t(fƒ�r|j�rt'd|ƒ}n t|t"t!fƒ�rt#d|ƒ}|j)||||t* +¡dd�}| ,¡|}WYd}~nd}~wwW|�sI|�oF| -¡}d}|�rQ| .|¡n|�s^|�o[| -¡}d}|�rg| .|¡ww|�sˆt/ 0d|||¡|j1|||||||f|| | | | dœ| ¤ŽS|�oŽ| 2¡}|�rà|j3dk�ršd}z |j)||||d�}Wnt4�yº|j5�r¶| 6¡‚|YSw| 6¡| 7|¡t/ 8d||¡|j1||||f||||| | | | dœ| ¤ŽSt9| :d¡ƒ}| ;||j3|¡�r5z |j)||||d�}Wnt4�y|j<�r | 6¡‚|YSw| 6¡| ,|¡t/ 8d|¡|j1||||f||||| | | | dœ| ¤ŽS|S)a+ Get a connection from the pool and perform an HTTP request. This is the lowest level call for making a request, so you'll need to specify all the raw details. .. note:: More commonly, it's appropriate to use a convenience method provided by :class:`.RequestMethods`, such as :meth:`request`. .. note:: `release_conn` will only behave as expected if `preload_content=False` because we want to make `preload_content=False` the default behaviour someday soon without breaking backwards compatibility. :param method: HTTP request method (such as GET, POST, PUT, etc.) :param url: The URL to perform the request on. :param body: Data to send in the request body, either :class:`str`, :class:`bytes`, an iterable of :class:`str`/:class:`bytes`, or a file-like object. :param headers: Dictionary of custom headers to send, such as User-Agent, If-None-Match, etc. If None, pool headers are used. If provided, these headers completely replace any pool-specific headers. :param retries: Configure the number of retries to allow before raising a :class:`~urllib3.exceptions.MaxRetryError` exception. Pass ``None`` to retry until you receive a response. Pass a :class:`~urllib3.util.retry.Retry` object for fine-grained control over different types of retries. Pass an integer number to retry connection errors that many times, but no other types of errors. Pass zero to never retry. If ``False``, then retries are disabled and any exception is raised immediately. Also, instead of raising a MaxRetryError on redirects, the redirect response will be returned. :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. :param redirect: If True, automatically handle redirects (status codes 301, 302, 303, 307, 308). Each redirect counts as a retry. Disabling retries will disable redirect, too. :param assert_same_host: If ``True``, will make sure that the host of the pool requests is consistent else will raise HostChangedError. When ``False``, you can use the pool on an HTTP proxy and request foreign hosts. :param timeout: If specified, overrides the default timeout for this one request. It may be a float (in seconds) or an instance of :class:`urllib3.util.Timeout`. :param pool_timeout: If set and the pool is set to block=True, then this method will block for ``pool_timeout`` seconds and raise EmptyPoolError if no connection is available within the time period. :param release_conn: If False, then the urlopen call will not release the connection back into the pool once a response is received (but will release if you read the entire contents of the response such as when `preload_content=True`). This is useful if you're not preloading the response's content immediately. You will need to call ``r.release_conn()`` on the response ``r`` to return the connection back into the pool. If None, it takes the value of ``response_kw.get('preload_content', True)``. :param chunked: If True, urllib3 will send the body using chunked transfer encoding. Otherwise, urllib3 will send the body using the standard content-length form. Defaults to False. :param int body_pos: Position to seek to in file-like body in the event of a retry or redirect. Typically this won't need to be set because urllib3 will auto-populate the value when needed. :param \**response_kw: Additional parameters are passed to :meth:`urllib3.response.HTTPResponse.from_httplib` N)ÚredirectÚdefaultÚpreload_contentTr«Frr‡)rÚbodyr_r¡Úrequest_method)rUÚ connectionrTcSs*d t dt|ƒ ¡¡¡}d|vpd|vS)Nú z[^a-z]zwrong version numberzunknown protocol)ÚjoinÚreÚsplitr‚r1)Ú ssl_errorÚmessager5r5r6Ú%_is_ssl_error_message_from_http_proxyñsÿzIHTTPConnectionPool.urlopen.._is_ssl_error_message_from_http_proxyÚhttpsz¹Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxyzCannot connect to proxy.zConnection aborted.é)rÚ_poolÚ _stacktracez1Retrying (%r) after connection broken by '%r': %s)rÚ pool_timeoutÚ release_connr¡Úbody_posi/ÚGET)Úresponser½zRedirecting %s -> %s)rTr®Úassert_same_hostrr¿rÀr¡rÁz Retry-Afterz Retry: %s)=r,r/r_rQr%Úfrom_intrTrmr­rr¬rÚ ensure_strr)r„r!rNrOÚcopyÚupdaterWr#r|rqrhrrpryr¨Ú ResponseClsÚ from_httplibrrr r›rrrr&rrÚ incrementÚsysrŠÚsleepr?rvrertÚurlopenÚget_redirect_locationrœrÚraise_on_redirectÚ drain_connÚsleep_for_retryrfÚboolÚ getheaderÚis_retryÚraise_on_status)r4r r„r±r_rTr®rÄrr¿rÀr¡rÁÚ response_kwÚ parsed_urlÚdestination_schemerjÚrelease_this_connÚhttp_tunnel_requiredrƒÚ clean_exitr£Úis_new_proxy_connr¥Ú response_connrÃr¤rºÚredirect_locationÚhas_retry_afterr5r5r6rÎ s‚m       ÿ     ÿ ù ÿüû ù ÿþýü ûû   ÿ€Ë€8 €ô üÿùô ó ü üô óü  üô ózHTTPConnectionPool.urlopenr=)r9rGrHrIr/r rgrrÉr'r“r7rkrqrvrxryr|r†rzr¨rŸr?r­rÎr5r5r5r6rKisN; ô6 '  ÿwórKcspeZdZdZdZeZddejdddddddddddddddfdd„Z dd „Z d d „Z d d „Z ‡fdd„Z ‡ZS)ÚHTTPSConnectionPoola Same as :class:`.HTTPConnectionPool`, but HTTPS. :class:`.HTTPSConnection` uses one of ``assert_fingerprint``, ``assert_hostname`` and ``host`` in this order to verify connections. If ``assert_hostname`` is False, no verification is done. The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs``, ``ca_cert_dir``, ``ssl_version``, ``key_password`` are only used if :mod:`ssl` is available and are fed into :meth:`urllib3.util.ssl_wrap_socket` to upgrade the connection socket into an SSL socket. r»NFrc Ks`tj|||||||||| | f i|¤Ž| |_| |_| |_||_||_||_||_||_ ||_ dSr=) rKr7Úkey_fileÚ cert_fileÚ cert_reqsÚ key_passwordÚca_certsÚ ca_cert_dirÚ ssl_versionÚassert_hostnameÚassert_fingerprint)r4r0r3rPrr^rVr_rTr`rarârãrärårærèrérêrçr\r5r5r6r7’s0õ ô zHTTPSConnectionPool.__init__c Cs@t|tƒr|j|j|j|j|j|j|j|j |j d�|j |_ |S)zˆ Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket` and establish the tunnel if proxy is used. )rârårãrärærçrérê) rQr Úset_certrârårãrärærçrérêrèrir5r5r6Ú _prepare_connÃs ø z!HTTPSConnectionPool._prepare_conncCs2| |j|j|j¡|jjdkrd|_| ¡dS)zÏ Establishes a tunnel connection through HTTP CONNECT. Tunnel connection is established early because otherwise httplib would improperly set Host: header to proxy's IP:port. r»TN)Ú set_tunnelr2r3rWrNr/Útls_in_tls_requiredÚconnectrir5r5r6ry×s  z"HTTPSConnectionPool._prepare_proxyc Csž|jd7_t d|j|j|jpd¡|jr|jtur tdƒ‚|j}|j}|jdur3|jj}|jj}|jd|||j j |j |j |j |jdœ|j¤Ž}| |¡S)zF Return a fresh :class:`http.client.HTTPSConnection`. rz)Starting new HTTPS connection (%d): %s:%sÚ443zCCan't connect to HTTPS URL because the SSL module is not available.N)r0r3rrPrãrârår5)rZrerfr0r3rgr rrNrrhrPrãrârår\rì)r4Ú actual_hostÚ actual_portrjr5r5r6rkæs8üÿ ùø zHTTPSConnectionPool._new_conncs`tt|ƒ |¡t|ddƒs| ¡|jst d|jt ¡t|ddƒdur.t dt ¡dSdS)rwr‡Nz¸Unverified HTTPS request is being made to host '%s'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warningsÚproxy_is_verifiedFz·Unverified HTTPS connection done to an HTTPS proxy. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings) ÚsuperrárxrprïÚ is_verifiedÚwarningsÚwarnr0rri©Ú __class__r5r6rx s  ýù ùÿz"HTTPSConnectionPool._validate_conn)r9rGrHrIr/r rgr'r“r7rìryrkrxÚ __classcell__r5r5rør6rá�s6  ì1$rácKsNt|ƒ\}}}|pt |d¡}|dkrt|fd|i|¤ŽSt|fd|i|¤ŽS)a€ Given a url, return an :class:`.ConnectionPool` instance of its host. This is a shortcut for not having to parse out the scheme, host, and port of the url before creating an :class:`.ConnectionPool` instance. :param url: Absolute URL string that must include the scheme. Port is optional. :param \**kw: Passes additional parameters to the constructor of the appropriate :class:`.ConnectionPool`. Useful for specifying things like timeout, maxsize, headers, etc. Example:: >>> conn = connection_from_url('http://google.com/') >>> r = conn.request('GET', '/') éPr»r3)r+rrmrárK)r„Úkwr/r0r3r5r5r6Úconnection_from_url+s rýcCs.t||ƒ}| d¡r| d¡r|dd…}|S)z? Normalize hosts for comparisons and use with sockets. ú[ú]réÿÿÿÿ)Únormalize_hostr¬Úendswith)r0r/r5r5r6r*Gs  r*)PÚ __future__rr~Úloggingr¶r•rÌrörr›rrr³rrr r r r r rÚ exceptionsrrrrrrrrrrrrrÚpackagesrZpackages.six.movesrr�rrÃrZutil.connectionr Z util.proxyr!Z util.queuer"Z util.requestr#Z util.responser$Z util.retryr%Zutil.ssl_match_hostnamer&Z util.timeoutr'Zutil.urlr(r)r*rr+r,ÚmovesrXÚ getLoggerr9reÚobjectrzr-ÚEAGAINÚ EWOULDBLOCKr�rKrárýr5r5r5r6ÚsT   (<               )+