CYhddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddlmZddlmZddlmZdd lmZmZmZmZmZmZmZmZdd lmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd l,m-Z-dd l.m/Z/ddl0m1Z1ddl2m3Z3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;mZ>m?Z?ddl=m@ZAddl=mBZBddlCmDZDejrddlFZFddlGmHZHddlmIZImJZJejeLZMejePool reached maximum size and no more connections are allowed.zLConnection pool is full, discarding connection: %s. Connection pool size: %s) rnrrrr_FullrNrorrwarningr:qsizers r@ _put_connzHTTPConnectionPool._put_conn*s 99   d% 0.  JJL -" :: JJL::'X   bIIIIOO% sA C A6CCcy)U Called right before a request is made, after the socket is created. NrKrs r@_validate_connz!HTTPConnectionPool._validate_connUrUrBcyrJrKrs r@_prepare_proxyz!HTTPConnectionPool._prepare_proxyZs rBc|tur|jjSt|tr|jSt j |S)z:Helper that always returns a :class:`urllib3.util.Timeout`)r(rclonerjr*rk)r?rs r@ _get_timeoutzHTTPConnectionPool._get_timeout^sG & &<<%%' ' gw '==? "%%g. .rBct|trt||d|d|t|dr%|jt vrt||d|d|yy)zAIs the error actually a timeout? Will raise a ReadTimeout or passRead timed out. (read timeout=rDerrnoN)rj SocketTimeoutrhasattrr_blocking_errnos)r?errurl timeout_values r@_raise_timeoutz!HTTPConnectionPool._raise_timeoutjsq c= )"c;M?!L  3 SYY2B%B"c;M?!L &C rBTc |xjdz c_|j|} | jtj| j |_ |j| |j+|||||| | | | j2}|j4s|dk(rt7||d|d||_ |j9}||_| |_||_t@jCd|j(|jD|jF|||jH|jJ|jL |S#ttf$r$}|j|||j d}~wwxYw#ttttttf$r}|}t!|ttfr t|}t!|ttttfr:|r8|j"r,|j$s t'||j"j(}|d}~wwxYw#t,$rYt$r)}|j.t.j0k7rYd}~d}~wwxYw#ttf$r}|j|||d}~wwxYw) a8 Perform a request on a given urllib connection object taken from our pool. :param conn: a connection from one of our connection pools :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 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 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 response_conn: Set this to ``None`` if you will handle releasing the connection or set the connection to have the response release it. :param preload_content: If True, the response's body will be preloaded during construction. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. :param enforce_content_length: Enforce content length checking. Body returned by server must match value of Content-Length header, if present. Otherwise, raise error. rrrrN)bodyr{chunkedpreload_contentdecode_contentenforce_content_lengthrrrDz%s://%s:%s "%s %s %s" %s %s)'rtr start_connectr*resolve_default_timeoutrrrrr rOSErrorrr r'rrjrhhas_connected_to_proxyrr7requestr r EPROTOTYPE read_timeout is_closedr getresponserm _connection_poolrrr:r; _http_vsn_strstatuslength_remaining)r?rmethodrrr{rmrr response_connrrr timeout_objenew_erresponses r@ _make_requestz HTTPConnectionPool._make_request}sp\ Q''0 !!#66{7R7RS   ##D)8  LL /-'=  0#// ~~ q &#!? ~QO(DL '')H #, ) KK II II      OO  % % w"<0 ##s$,,#O           !E!l,<=>  !3\8LDJJt/J/J)%1B1BCK# H   ww%***+  2g&    A3l  K  sgD?0H?I?E2E--E22E55#HA?HH I+I3IIJ.JJc\|jy|jdc}|_t|yrT)rnry)r?old_pools r@rNzHTTPConnectionPool.close2s- 99  "ii$) )rBcV|jdryt|^}}}}}|xsd}| t||}|jr|st j |}n&|js|t j |k(rd}|||f|j |j|jfk(S)zj Check if the given ``url`` is a member of the same host as this connection pool. /TrdNr9) startswithr.r-r;rrr7r:)r?rr7rr:r;s r@ is_same_hostzHTTPConnectionPool.is_same_host>s >># %.cN!4!6  "47D 99T!%%f-Dt~'9'9&'AADd# TYY 'JJJrBc  t|}|j}| |j}t|ts"t j |||j }| | } |r|j|s t||||jdrtt|}nt|j}d}| }t|j|j|}|s+|j!}|j#|j$d}d}t'|| } |j)|}|j+| }|j,|_|j |r|j0r |j3|| s|nd}|j<|||f|||| ||| |d|}d}|s|r|j[d}d}|r|j]| |s9t^jad ||||jb|||||||f|| | | | | |d |S|xrje}|rjfdk(rd}d}ti|jk} |jS||||}|jq|js|t^jud|||jb||||f||||| | | | | |d |Stwjjyd}|j{||jf|rn |jS||||}|jq|jY|t^jud||jb||||f||||| | | | | |d |S|S#t4t6t8f$r8}|j;||jj|j.d}~wwxYw#t>$rd}d}t@tBt6tDt4tFtHtJf$r}d}|}t|t4tHfr tG|}t|t6tLt@tFtBfr;|r9|jr-|jNs!tQ||jj}n"t|t6tBfr tEd |}|jS||||tUjVd  }|jY|}Yd}~ %s) rmrassert_same_hostrrrrrrrz Retry-Afterz Retry: %s)?r.r7r{rjr&from_intrmrrrr/r,rr#rhricopyupdaterpr%rrrrrrr rrrrrr rrrr'rrrr incrementsysexc_infosleeprNrrrurlopenget_redirect_locationrr _prepare_for_method_changerraise_on_redirect drain_connsleep_for_retryrboolris_retryraise_on_status)r?rrrr{rmrrrrrrrrr response_kw parsed_urldestination_schemerrelease_this_connhttp_tunnel_requiredr clean_exitrrrrrredirect_locationhas_retry_afters r@rzHTTPConnectionPool.urlopenTsbs^ '.. ?llG'5)nnWxVG  *L D$5$5c$:"4g6 6 >># ,-C(C)> JJ))+= $llnG NN4-- . %T84e %++G4K>>,>7D&66DLzz%*>4>>''-)5D$M*t)) $+ /-  H J^ JJLD$(! t$ KKCWcSV  4<<  ))! /- &%I)G)G)I #%(1LLN !++FC(RV+W    !  # #H - II,c3D E4<<!   !!1))! /- &x//33MBC   FHOO_ E !++FC(RV+W    ! MM( # IIk3 '4<<   !!1))! /- $u%g}=''4::>>( > J %            $ J E!l,<=>  & !  DJJt/J/J)%1B1BCEG]#;<%&;UC''5#,,.QRBS(G MMOCI$ N JJLD$(! t$ !R! ,,'')  @! **'')  stAN8)M):&N8 T:U)N5=3N00N55N88:S!2C$SS$S!!S$$.T(U?U(U.-U.)r:rVr;rWr_TYPE_TIMEOUT | Nonerzintrorr{typing.Mapping[str, str] | NonermRetry | bool | int | Noner| Url | Noner}rr~zProxyConfig | Noneru typing.Any)rXr1rJ)rz float | NonerXr1)rBaseHTTPConnection | NonerXrYrr1rXrY)r _TYPE_TIMEOUTrXr*)rz&BaseSSLError | OSError | SocketTimeoutrrVrrrXrY)rr1rrVrrVr_TYPE_BODY | Noner{rrmz Retry | NonerrrrrrrrrrrrrXr!rZ)rrVrXr) rrVrrVrrr{rrmrrrrrrrrrWrz bool | Nonerrrz_TYPE_BODY_POSITION | NonerrrrrrrXr!)rFr[r\r]r7rrer^r(rArrrrrrrrrNrrrKrBr@rcrczs1fF < (837-1!:>,0;>;>;>& ;>  ;>  ;>1;>+;>;>8;>*;>;>z($(L)V   / 3,   0#'37 $!137 $#'+s ss s  s 1 ssss1sss!%s sj *K4#'37-1!%!1#'$(/3 $#ppp p 1 p + pppp!p"pp-ppp "!p" #prBrcceZdZUdZdZeZded<dedddddddddddddddddf d fd Z d d Z dd Z dfd Z xZ S)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. httpsztype[BaseHTTPSConnection]reNrFc t|||||||||| f i|| |_| |_| |_| |_||_||_||_||_ ||_ ||_ ||_ yrJ) superrAkey_file cert_file cert_reqs key_passwordca_certs ca_cert_dir ssl_versionssl_minimum_versionssl_maximum_versionassert_hostnameassert_fingerprint)r?r:r;rrzror{rmr|r}rrrrrrrrrrrru __class__s r@rAzHTTPSConnectionPool.__init__s0            ! ""(  &&#6 #6 ."4rBc|jr|jjdk(rd}nd}|j||j|j|j |j y)z5Establishes a tunnel connection through HTTP CONNECT.rrd)r7r:r;r{N)rhr7 set_tunnelr>r;rpconnect)r?r tunnel_schemes r@rz"HTTPSConnectionPool._prepare_proxy s\ ::$**++w6#M"M  ""&&  rBc|xjdz c_tjd|j|j|jxsd|j r|j t ur td|j}|j}|jB|jj,|jj}|jj}|j d|||jj|j|j|j|j|j|j |j"|j$|j&|j(|j*d|j,S)zL Return a fresh :class:`urllib3.connection.HTTPConnection`. rz)Starting new HTTPS connection (%d): %s:%s443zCCan't connect to HTTPS URL because the SSL module is not available.)r:r;rrrrrrrrrrrrrK)rsrrr:r;rer ImportErrorrhrrrrrrrrrrrrrru)r? actual_host actual_ports r@rzHTTPSConnectionPool._new_connsC ! 7  II II   !!T%7%7?%JU  99 ii :: !djjoo&A**//K**//K!t!! LL00nn]]**nn]](( 00#66(( $ 8 8 $ 8 8 ll  rBct|||jr|j|js)t j d|jdtyy)rz0Unverified HTTPS request is being made to host 'z'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warningsN) rrrr is_verifiedwarningswarnr:r)r?rrs r@rz"HTTPSConnectionPool._validate_connAsY t$ >> LLN MMFtyykR$$ '  rB),r:rVr;rWrrrzrrorr{rrmrr|rr}rrr6rr6rint | str | Nonerr6rr6rrrssl.TLSVersion | Nonerrrzstr | Literal[False] | Nonerr6rr6rurrXrY)rrrXrY)rXr2r)rFr[r\r]r7rrer^r(rArrr __classcell__)rs@r@rrsJ F/>M,>  (837-1!:># $&*#'#(,59597;)-"&+/5/5/5& /5  /5  /51/5+/5/58/5/5/5$/5!/5/5 &!/5"3#/5$3%/5&5'/5(')/5* +/5,-/5. //5b ' RrBrc t|^}}}}}|xsd}|xstj|d}|dk(rt|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', '/') rdPrr;)r.rrrrc)rkwr7rr:r;s r@connection_from_urlrWsk(!*#FAtTA  vF  1>%%fb1D "49d9b99!$8T8R88rBcyrJrKr:r7s r@r-r-trBcyrJrKrs r@r-r-yrrBcpt||}|r'|jdr|jdr|dd}|S)z? Normalize hosts for comparisons and use with sockets. []r)r<rendswithrs r@r-r-~s; $ 'D $s);Abz KrBcpt|j|j|j|jS)zZReturns the URL from a given connection pool. This is mainly used for testing and logging.)r7r:r;path)r+r7r:r;r)rnr#s r@_url_from_poolr$s' dkk   M Q QQrBc |jd}|r|j%#tj$rYywxYw)z2Drains a queue of connections and closes each one.FrN)rrNr_r)rnrs r@ryrysC 88%8(D  ;;   s &(>>)rrVrrrXrc)r:rYr7r6rXrY)r:rVr7r6rXrV)r:r6r7r6rXr6rJ)rnz(HTTPConnectionPool | HTTPSConnectionPoolr#r6rXrV)rnzqueue.LifoQueue[typing.Any]rXrY)] __future__rrloggingr_rtypingrrwsocketrrtypesr_base_connectionr _collectionsr _request_methodsr connectionr r r rrrrrr exceptionsrrrrrrrrrrrrr rr!util.connectionr" util.proxyr# util.requestr$r% util.retryr&util.ssl_match_hostnamer' util.timeoutr(r)r*util.urlr+r,r-r<r. util.utilr/ TYPE_CHECKINGssltyping_extensionsr0r1r2 getLoggerrFrUnionfloatrTypeVarr3r5EAGAIN EWOULDBLOCKrrcrroverloadr$ryrKrBr@rBso"  +((,   9'27@5BB)7 )Ig! We]D@A  !. . dLL%"3"34J J ZM,M`9:&HLR 2R:DRR rB