kb'SdZddlZddlZddlmZmZddlmZddlm Z ddlm Z m Z m Z mZddlmZddlmZmZdd lmZdd lmZmZdd lmZdd lmZdd lmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m Z m*Z*m+Z+m,Z,mZm-Z-m.Z.mZddl/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;mdZ?dZ@dZAGddZBGddeBZCdS)z requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. N)ClosedPoolErrorConnectTimeoutError) HTTPError) InvalidHeader)LocationValueError MaxRetryErrorNewConnectionError ProtocolError) ProxyError)ReadTimeoutError ResponseError)SSLError) PoolManagerproxy_from_url) HTTPResponse)Timeout) parse_url)Retry)_basic_auth_str) basestringurlparse)extract_cookies_to_jar) ConnectionErrorConnectTimeoutrInvalidProxyURL InvalidSchema InvalidURLr ReadTimeout RetryErrorr)Response)CaseInsensitiveDict)DEFAULT_CA_BUNDLE_PATHextract_zipped_pathsget_auth_from_urlget_encoding_from_headersprepend_scheme_if_needed select_proxy urldefragauth)SOCKSProxyManagerc td)Nz'Missing dependencies for SOCKS support.)r)argskwargss 3/usr/lib/python3/dist-packages/requests/adapters.pyr*r*=sEFFFF c2eZdZdZfdZ ddZdZxZS) BaseAdapterzThe Base Transport AdaptercHtdSN)super__init__)self __class__s r.r6zBaseAdapter.__init__Js r/FNTct)aCSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. NotImplementedError)r7requeststreamtimeoutverifycertproxiess r.sendzBaseAdapter.sendMs ""!r/ct)z!Cleans up adapter specific items.r:r7s r.closezBaseAdapter.close`s!!r/FNTNN)__name__ __module__ __qualname____doc__r6rBrE __classcell__r8s@r.r2r2Gsh$$TX""""&"""""""r/r2ceZdZdZgdZeeeeffd ZdZ dZ efdZ dZ dZ d Zdd Zd Zd ZdZdZ ddZxZS) HTTPAdapteraThe built-in HTTP Adapter for urllib3. Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the :class:`Session ` class under the covers. :param pool_connections: The number of urllib3 connection pools to cache. :param pool_maxsize: The maximum number of connections to save in the pool. :param max_retries: The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3's ``Retry`` class and pass that instead. :param pool_block: Whether the connection pool should block for connections. Usage:: >>> import requests >>> s = requests.Session() >>> a = requests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a) ) max_retriesconfig_pool_connections _pool_maxsize _pool_blockc4|tkrtdd|_ntj||_i|_i|_t ||_||_ ||_ | |||dS)NrF)readblock) DEFAULT_RETRIESrrOfrom_intrP proxy_managerr5r6rQrRrSinit_poolmanager)r7pool_connections pool_maxsizerO pool_blockr8s r.r6zHTTPAdapter.__init__s / ) )$QU333D  $~k::D   !1)% . JOOOOOr/c*fdjDS)Nc4i|]}|t|dSr4)getattr).0attrr7s r. z,HTTPAdapter.__getstate__..s'KKKDgdD$//KKKr/) __attrs__rDs`r. __getstate__zHTTPAdapter.__getstate__sKKKKDNKKKKr/ci|_i|_|D]\}}t|||||j|j|jdS)NrV)rZrPitemssetattrr[rQrRrS)r7statercvalues r. __setstate__zHTTPAdapter.__setstate__sz   ;;== ' 'KD% D$ & & & &   "D$6d>N      r/c \||_||_||_td|||dd||_dS)aInitializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param connections: The number of urllib3 connection pools to cache. :param maxsize: The maximum number of connections to save in the pool. :param block: Block when no free connections are available. :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager. T) num_poolsmaxsizerWstrictN)rQrRrSr poolmanager)r7 connectionsrorW pool_kwargss r.r[zHTTPAdapter.init_poolmanagersT"-$ & !      r/c ||jvr|j|}n|dr?t|\}}t |f|||j|j|jd|x}|j|<n@||}t|f||j|j|jd|x}|j|<|S)aReturn urllib3 ProxyManager for the given proxy. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param proxy: The proxy to return a urllib3 ProxyManager for. :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager. :returns: ProxyManager :rtype: urllib3.ProxyManager socks)usernamepasswordrnrorW) proxy_headersrnrorW) rZlower startswithr%r*rQrRrSryr)r7proxy proxy_kwargsmanagerrwrxrys r.proxy_manager_forzHTTPAdapter.proxy_manager_fors D& & &(/GG [[]] % %g . . !25!9!9 Hh2C3!!0*& 3333 Gd(//!..u55M2@3+0*& 33  33 Gd(/r/c |dr|rd}|dur|}|stt}|rtj|std|d|_tj |s||_ n||_ nd|_d|_ d|_ |rt|ts|d|_|d|_n||_d|_|jr;tj|jstd |j|jr=tj|jstd |jdSdSdS) aAVerify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param conn: The urllib3 connection object associated with the cert. :param url: The requested URL. :param verify: Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: The SSL certificate to verify. httpsNTzCCould not find a suitable TLS CA certificate bundle, invalid path: CERT_REQUIRED CERT_NONErrz7Could not find the TLS certificate file, invalid path: z/Could not find the TLS key file, invalid path: )rzr{r$r#ospathexistsOSError cert_reqsisdirca_certs ca_cert_dir isinstancer cert_filekey_file)r7connurlr?r@cert_locs r. cert_verifyzHTTPAdapter.cert_verifys 99;; ! !' * * $v $HT!!! H/0FGG 27>>(#;#; 0%-00 -DN7==** , ( #+  (DN DM#D   dJ// %!%a $Q !% $ ~ bgnnT^&D&D 6%)^66} RW^^DM%B%B UdmUU      r/ct}t|dd|_tt|di|_t |j|_||_|jj|_t|j tr |j d|_ n |j |_ t|j||||_||_|S)aBuilds a :class:`Response ` object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter ` :param req: The :class:`PreparedRequest ` used to generate the response. :param resp: The urllib3 response object. :rtype: requests.Response statusNheadersutf-8)r!ra status_coder"rr&encodingrawreasonrrbytesdecodercookiesr< connection)r7reqrespresponses r.build_responsezHTTPAdapter.build_response(s:: 'tXt<</wtY/K/KLL6h6FGG ",- cgu % % #7>>'22HLL7HL x/d;;;"r/Ncdt||}|r`t|d}t|}|jst d||}||}n=t|}|}|j |}|S)aReturns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. :rtype: urllib3.ConnectionPool httpzFPlease check proxy URL. It is malformed and could be missing the host.) r(r'rhostrrconnection_from_urlrgeturlrr)r7rrAr| proxy_urlrZrparseds r.get_connectionzHTTPAdapter.get_connectionMsS'**  =,UF;;E!%((I> %5!22599M 44S99DDc]]F--//C#77<`. :param request: The :class:`PreparedRequest ` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. :rtype: str rFrv)r(rrschemerzr{path_urlr)) r7r<rAr|ris_proxied_http_requestusing_socks_proxy proxy_schemers r. request_urlzHTTPAdapter.request_urltsW['22'+&&-"'"=Fg,=!  A#E??17799L , 7 7 @ @  " -+< - ,,C r/c dS)a"Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the :class:`HTTPAdapter `. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` to add headers to. :param kwargs: The keyword arguments from the call to send(). Nrq)r7r<r-s r. add_headerszHTTPAdapter.add_headerss  r/cXi}t|\}}|rt|||d<|S)aReturns a dictionary of the headers to add to any request sent through a proxy. This works with urllib3 magic to ensure that they are correctly sent to the proxy, rather than in a tunnelled request if CONNECT is being used. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param proxy: The url of the proxy being used for this request. :rtype: dict zProxy-Authorization)r%r)r7r|rrwrxs r.ryzHTTPAdapter.proxy_headerss>.u55(  Q-$r| wxYwn#tBtDf$r}tG||d}~wtH$r}t|j%tLr+t|j%tNstQ||t|j%tRrtU||t|j%tVrtY||t|j%tZrt]||tG||d}~wt^$r}tG||d}~wtV$r}tY|d}~wtZt`f$rx}t|tZrt]||t|tbrte||t|tfrti||d}~wwxYw|5|| S)aSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple or urllib3 Timeout object :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. :rtype: requests.Response )r<N)r=r>r?r@rAzContent-Length)connectrUzInvalid timeout za. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same value.F) methodrbodyrredirectassert_same_hostpreload_contentdecode_contentretriesr> proxy_pool)r>HostT)skip_accept_encoding skip_hostrs s0 )poolrrr)6rrrrrrrrrrtuple TimeoutSauce ValueErrorurlopenrrOhasattrr _get_connDEFAULT_POOL_TIMEOUT putrequestrh putheader endheadersrBhexlenencode getresponser from_httplib ExceptionrEr rrrrrr rr r _ProxyErrorr _SSLErrorrr _HTTPErrorr r_InvalidHeaderrr)r7r<r=r>r?r@rArerchunkedrrUrlow_connrheaderrkirerrs r.rBzHTTPAdapter.sends& 1&&w{G< #O"%*$)#( ,#$  4..+?D>>2F>GG# &'/ 9I''-1"+ (*1)>)>)@)@::  **659999'')))$\// c#a&&kk!""o&<&??=(G<<<<!(M22 5 G4444!(K00 5 G4444!(I.. 3q'2222!!W555 5 6 6 6!!W555 5   Q-- :&   !Y'' q'2222A/00 !!W5555A~.. #Aw7777 ""7D111s >9>8CC-A)K-EKK- K((K--R9>L R9CO33 R9P R9P--R9A3R44R9r4rF)rGrHrIrJreDEFAULT_POOLSIZErXDEFAULT_POOLBLOCKr6rfrlr[rrrrrErrryrBrKrLs@r.rNrNesI4I*%#$ PPPPPP,LLL    +<    6$$$L777r###J::    ,TXT2T2T2T2T2T2T2T2r/rN)DrJos.pathrsocketurllib3.exceptionsrrrrrrrrr r r rr r rrurllib3.poolmanagerrrurllib3.responser urllib3.utilrrrurllib3.util.retryrauthrcompatrrrr exceptionsrrrrrrr modelsr! structuresr"utilsr#r$r%r&r'r(r)urllib3.contrib.socksr* ImportErrorrrrXrr2rNrqr/r.rsD CCCCCCCC666666>>>>>> 988888>>>>>>>>444444;;;;;;;;))))))000000""""""$$$$$$!!!!!!((((((((++++++                        ++++++G7777777GGGGGGGGG """"""""