a †oe]�ã@s&ddlmZddlZddlZddlZddlZddlZddlZddlmZ ddlm Z ddl m Z ddlmZmZmZmZmZmZmZmZddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#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>m?Z?ddl=m@ZAddl=mBZBmCZCzddlDZDeDjEZFWn eG�y²ddlHmFZFYn0e&jIjJZJe KeL¡ZMeNƒZOGdd„deNƒZPejQejRhZSGdd„dePe*ƒZTGdd„deTƒZUdd „ZVd!d"„Z@d#d$„ZWdS)%é)Úabsolute_importN)Úerror©Útimeouté)ÚHTTPHeaderDict)Ú 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_url)Úweakref_finalizec@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|s tdƒ‚t||jd�|_| ¡|_||_dS)NzNo host specified.©Úscheme)rr+r1ÚhostÚlowerÚ _proxy_hostÚport)Úselfr2r5©r7ú7C:\Program Files\Certbot\pkgs\urllib3\connectionpool.pyÚ__init__Ss  zConnectionPool.__init__cCsdt|ƒj|j|jfS)Nz%s(host=%r, port=%r))ÚtypeÚ__name__r2r5©r6r7r7r8Ú__str__[szConnectionPool.__str__cCs|S©Nr7r<r7r7r8Ú __enter__^szConnectionPool.__enter__cCs | ¡dS)NF)Úclose)r6Úexc_typeZexc_valZexc_tbr7r7r8Ú__exit__aszConnectionPool.__exit__cCsdS©zD Close all pooled connections and disable the pool. Nr7r<r7r7r8r@fszConnectionPool.close)N) r;Ú __module__Ú __qualname__Ú__doc__r1r#ÚQueueClsr9r=r?rBr@r7r7r7r8r/Es  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ƒs4t |¡}|durBtj}||_ ||_ |  |¡|_ ||_ | |_| pli|_| |_t|ƒD]} |j  d¡q~d|_d|_| |_|jrÎ|j dg¡|j|jd<|j|jd<|j }t|t|ƒdS)NrZsocket_optionsÚproxyÚ proxy_config)r/r9rÚstrictÚ isinstancer(Ú from_floatr&ZDEFAULTrÚretriesrGÚpoolÚblockrJÚ proxy_headersrKÚxrangeÚputÚnum_connectionsÚ num_requestsÚconn_kwÚ setdefaultr.Ú_close_pool_connections)r6r2r5rLrÚmaxsizerQÚheadersrOÚ_proxyÚ_proxy_headersZ _proxy_configrWÚ_rPr7r7r8r9±s2        zHTTPConnectionPool.__init__cCsR|jd7_t d|j|j|jp$d¡|jf|j|j|jj|jdœ|j ¤Ž}|S)z9 Return a fresh :class:`HTTPConnection`. rz(Starting new HTTP connection (%d): %s:%sZ80)r2r5rrL) rUÚlogÚdebugr2r5Ú ConnectionClsrÚconnect_timeoutrLrW©r6Úconnr7r7r8Ú _new_connñs üüûzHTTPConnectionPool._new_conncCsœd}z|jj|j|d�}Wn>ty6t|dƒ‚Yn$tjyX|jrTt|dƒ‚Yn0|r�t|ƒr�t   d|j ¡|  ¡t |ddƒdkr�d}|pš| ¡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)rQrzPool is closed.z>Pool reached maximum size and no more connections are allowed.z Resetting dropped connection: %sZ auto_openrr)rPÚgetrQÚAttributeErrorrrÚEmptyrr!r_r`r2r@Úgetattrre)r6rrdr7r7r8Ú _get_conns$  þ zHTTPConnectionPool._get_connc Csbz|jj|dd�WdSty(Yn*tjyPt d|j|j ¡¡Yn0|r^|  ¡dS)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©rQNzLConnection pool is full, discarding connection: %s. Connection pool size: %s) rPrTrgrZFullr_Úwarningr2Zqsizer@rcr7r7r8Ú _put_conn-s ý zHTTPConnectionPool._put_conncCsdS)úU Called right before a request is made, after the socket is created. Nr7rcr7r7r8Ú_validate_connLsz!HTTPConnectionPool._validate_conncCsdSr>r7rcr7r7r8Ú_prepare_proxyRsz!HTTPConnectionPool._prepare_proxycCs2|tur|j ¡St|tƒr$| ¡St |¡SdS)z:Helper that always returns a :class:`urllib3.util.Timeout`N)Ú_DefaultrZclonerMr(rN)r6rr7r7r8Ú _get_timeoutVs   zHTTPConnectionPool._get_timeoutcCsjt|tƒrt||d|ƒ‚t|dƒr>|jtvr>t||d|ƒ‚dt|ƒvsVdt|ƒvrft||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)rMÚ SocketTimeoutrÚhasattrrtÚ_blocking_errnosÚstr)r6ÚerrÚurlÚ timeout_valuer7r7r8Ú_raise_timeoutbs  ÿ ÿÿ ÿz!HTTPConnectionPool._raise_timeoutc Ks‚|jd7_| |¡}| ¡t |j¡|_z| |¡Wn<tt fyx}z |j |||jd�‚WYd}~n d}~00z2|r–|j ||fi|¤Žn|j ||fi|¤ŽWnLt y¾Yn<tyø}z$|jtjtjtjhvrä‚WYd}~n d}~00|j} t|ddƒ�rR| dk�r(t||d| ƒ‚| tju�rF|j t ¡¡n |j | ¡zjz|jdd�} WnTt�y¸z | ¡} Wn2t�y²}zt |d¡WYd}~n d}~00Yn0Wn>tt t f�yú}z|j ||| d�‚WYd}~n d}~00t|d d ƒ} t! "d |j#|j$|j%||| | j&| j'¡ zt(| j)ƒWnBt*tf�y|} z$t!j+d | ,|¡| dd �WYd} ~ n d} ~ 00| S)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)ryrzr{NÚsockrrsT)Ú bufferingZ _http_vsn_strzHTTP/?z%s://%s:%s "%s %s %s" %s %sz$Failed to parse headers (url=%s): %s)Úexc_info)-rVrrZ start_connectr(Zresolve_default_timeoutrbrrorurr|Zrequest_chunkedÚrequestr ÚIOErrorrtZEPIPEZ ESHUTDOWNZ EPROTOTYPEÚ read_timeoutrirÚDEFAULT_TIMEOUTr}Z settimeoutÚsocketZgetdefaulttimeoutZ getresponseÚ TypeErrorÚ BaseExceptionrZ raise_fromÚ SocketErrorr_r`r1r2r5ÚstatusÚlengthr%ÚmsgrrlÚ _absolute_url) r6rdÚmethodrzrÚchunkedZhttplib_request_kwÚ timeout_objÚer‚Úhttplib_responseZ http_versionZhper7r7r8Ú _make_request{s€  ý  ÿ   , ÷ üz HTTPConnectionPool._make_requestcCst|j|j|j|d�jS)N)r1r2r5Úpath)r)r1r2r5rz)r6r’r7r7r8r‹òsz HTTPConnectionPool._absolute_urlcCs(|jdurdS|jd}|_t|ƒdSrC)rPrY)r6Zold_poolr7r7r8r@õs zHTTPConnectionPool.closecCsx| d¡rdSt|ƒ\}}}|dur0t||d�}|jrF|sFt |¡}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. ú/TNr0)Ú startswithr,r+r5rrfr1r2)r6rzr1r2r5r7r7r8Ú is_same_hosts    zHTTPConnectionPool.is_same_hostTc Ksžt|ƒ}|j}|dur|j}t|tƒs8tj|||jd�}| durL|  dd¡} |rf| |¡sft |||ƒ‚|  d¡r€t   t |ƒ¡}n t   |j¡}d}| }t|j|j|ƒ}|s¼| ¡}| |j¡d}d}t|| ƒ} �zòz¢| |¡}|j| d�}|j|_|jdu�o t|ddƒ }|�r"|�r"| |¡|j||||||| d �}| �sD|nd}|| d <|jj|f|||d œ| ¤Ž}d}W�n"t�y”d}d}‚Y�nt t!t"t#t$t%t&f�y–}zÜd}d d „}t|t$ƒ�r|j�r||ƒ�r|j�r|jjdk�rt'dt%|ƒƒ}nXt|t$t&fƒ�rt%|ƒ}n>t|t"t(fƒ�r@|j�r@t'd|ƒ}nt|t"t!fƒ�rZt#d|ƒ}|j)||||t* +¡dd�}| ,¡|}WYd}~n d}~00W|�s²|�o¬| -¡}d}|�rî| .|¡n*|�sÜ|�oÖ| -¡}d}|�rì| .|¡0|�s.t/ 0d|||¡|j1|||||||f|| | | | dœ| ¤ŽS|�o:| 2¡}|�rî|j3dk�rbd}d}t4|ƒ 5¡}z|j)||||d�}Wn*t6�y¢|j7�rš| 8¡‚|YS0| 8¡| 9|¡t/ :d||¡|j1||||f||||| | | | dœ| ¤ŽSt;|j d¡ƒ}| <||j3|¡�ršz|j)||||d�}Wn*t6�yP|j=�rH| 8¡‚|YS0| 8¡| ,|¡t/ :d|¡|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ÚdefaultZpreload_contentTr“Frr})rÚbodyr[r�Zrequest_method)rPÚ connectionrOcSs*d t dt|ƒ ¡¡¡}d|vp(d|vS)Nú z[^a-z]zwrong version numberzunknown protocol)ÚjoinÚreÚsplitrxr3)Z ssl_errorÚmessager7r7r8Ú%_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Ú_poolZ _stacktracez1Retrying (%r) after connection broken by '%r': %s)rÚ pool_timeoutÚ release_connr�Úbody_posi/ZGET)Úresponser¢zRedirecting %s -> %s)rOr–Úassert_same_hostrr£r¤r�r¥z Retry-Afterz Retry: %s)>r-r1r[rMr&Zfrom_intrOrfr•rr”rZ ensure_strr*rzr"rJrKÚcopyÚupdaterRr$rrrjrbrrirpr‘Ú ResponseClsZ from_httplibrrr r‡rrrr'rrZ incrementÚsysrÚsleepr@rmr_rlÚurlopenZget_redirect_locationrˆrZ_prepare_for_method_changerZraise_on_redirectZ drain_connZsleep_for_retryr`ÚboolZis_retryZraise_on_status)r6rŒrzr˜r[rOr–r§rr£r¤r�r¥Z response_kwZ parsed_urlZdestination_schemerdZrelease_this_connZhttp_tunnel_requiredryZ clean_exitrŽZis_new_proxy_connr�Z response_connr¦r�rŸZredirect_locationZhas_retry_afterr7r7r8r­sxm       ÿ    ÿ  ùÿüû ù ÿþýü ûû   ÿ ô ÿùô ó    üô ó   üô ózHTTPConnectionPool.urlopen)N)r;rDrErFr1r rar rªr(rƒr9rerjrmrorprrr|rqr‘r‹r@r•r­r7r7r7r8rHqsL;ô @ ' ÿ w órHcspeZdZdZdZeZddejdddddddddddddddfdd„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>) rHr9Úkey_fileÚ cert_fileÚ cert_reqsÚ key_passwordÚca_certsÚ ca_cert_dirÚ ssl_versionÚassert_hostnameÚassert_fingerprint)r6r2r5rLrrZrQr[rOr\r]r°r±r²r³r´r¶r·r¸rµrWr7r7r8r9¢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¸) rMrZset_certr°r³r±r²r´rµr·r¸r¶rcr7r7r8Ú _prepare_connÓs ø z!HTTPSConnectionPool._prepare_conncCs2| |j|j|j¡|jjdkr&d|_| ¡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)Z set_tunnelr4r5rRrJr1Ztls_in_tls_requiredÚconnectrcr7r7r8rpçs z"HTTPSConnectionPool._prepare_proxyc Csž|jd7_t d|j|j|jp$d¡|jr8|jtur@tdƒ‚|j}|j}|jdurf|jj}|jj}|jf|||j j |j |j |j |jdœ|j¤Ž}| |¡S)zF Return a fresh :class:`http.client.HTTPSConnection`. rz)Starting new HTTPS connection (%d): %s:%sZ443zCCan't connect to HTTPS URL because the SSL module is not available.N)r2r5rrLr±r°r³)rUr_r`r2r5rar rrJrrbrLr±r°r³rWr¹)r6Z actual_hostZ actual_portrdr7r7r8reös8üÿ ùø zHTTPSConnectionPool._new_conncs\tt|ƒ |¡t|ddƒs$| ¡|js>> conn = connection_from_url('http://google.com/') >>> r = conn.request('GET', '/') éPr r5N)r,rrfr¯rH)rzÚkwr1r2r5r7r7r8Ú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)r2r1r7r7r8r+Ws  r+cCs8z|jdd�}|r| ¡qWntjy2Yn0dS)z2Drains a queue of connections and closes each one.FrkN)rfr@rrh)rPrdr7r7r8rYis  rY)XZ __future__rrtZloggingrœr„r«r¼rr‡rruÚ _collectionsrr™rr r r r r rrÚ exceptionsrrrrrrrrrrrrrZpackagesrZpackages.six.movesrr€rr¦r Zutil.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+rÇr,r-ÚweakrefÚfinalizer.rgZ#packages.backports.weakref_finalizeZmovesrSZ getLoggerr;r_Úobjectrqr/ZEAGAINZ EWOULDBLOCKrwrHr¯rÃrYr7r7r7r8Ús`    ( <               ) &+