ó b@RTc@s<ddlZddlZddlZddlZddlmZmZddlZy ddl m Z m Z m Z Wn9e k r­ddlm Z m Z m Z ddlZnXddlmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZddl m!Z!m"Z"m#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 l0m1Z1ddl2m3Z3ej4j5Z5ej6e7ƒZ8e9ƒZ:de9fd„ƒYZ;e<ej=ej>gƒZ?de;e)fd„ƒYZ@de@fd„ƒYZAd„ZBdS(iÿÿÿÿN(terrorttimeout(t LifoQueuetEmptytFulli( tClosedPoolErrort ProtocolErrortEmptyPoolErrortHostChangedErrortLocationValueErrort MaxRetryErrort ProxyErrortReadTimeoutErrortSSLErrort TimeoutErrortInsecureRequestWarning(tCertificateError(tsix(tport_by_schemetDummyConnectiontHTTPConnectiontHTTPSConnectiontVerifiedHTTPSConnectiont HTTPExceptiont BaseSSLError(tRequestMethods(t HTTPResponse(tis_connection_dropped(tRetry(tTimeout(tget_hosttConnectionPoolcBs/eZdZdZeZdd„Zd„ZRS(sz Base class for all connection pools, such as :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`. cCs4|stdƒ‚n|jdƒ|_||_dS(NsNo host specified.s[](R tstripthosttport(tselfR!R"((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt__init__?scCs dt|ƒj|j|jfS(Ns%s(host=%r, port=%r)(ttypet__name__R!R"(R#((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt__str__GsN( R&t __module__t__doc__tNonetschemeRtQueueClsR$R'(((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyR6s  tHTTPConnectionPoolc Bs°eZdZdZeZd eej ded d d d d„ Z d„Z d d„Z d„Z d„Zd„Zed „Zd „Zd „Zd d d eeed d d „ZRS(sN Thread-safe connection pool for one host. :param host: Host used for this HTTP Connection (e.g. "localhost"), passed into :class:`httplib.HTTPConnection`. :param port: Port used for this HTTP Connection (None is equivalent to 80), passed into :class:`httplib.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:`httplib.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.connectionpool.ProxyManager`" :param _proxy_headers: A dictionary with proxy headers, should not be used directly, instead, see :class:`urllib3.connectionpool.ProxyManager`" :param \**conn_kw: Additional parameters are used to create fresh :class:`urllib3.connection.HTTPConnection`, :class:`urllib3.connection.HTTPSConnection` instances. thttpic Kstj|||ƒtj||ƒ||_t|tƒsMtj|ƒ}n|dkretj }n||_ ||_ |j |ƒ|_ ||_| |_| p¤i|_x$t|ƒD]} |j jdƒq·Wd|_d|_| |_|jr |jjdgƒndS(Nitsocket_options(RR$Rtstrictt isinstanceRt from_floatR*RtDEFAULTRtretriesR,tpooltblocktproxyt proxy_headerstxrangetputtnum_connectionst num_requeststconn_kwt setdefault( R#R!R"R0RtmaxsizeR6theadersR4t_proxyt_proxy_headersR=t_((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyR$Žs(           c Csi|jd7_tjd|j|jfƒ|jd|jd|jd|jjd|j|j }|S(s9 Return a fresh :class:`HTTPConnection`. is%Starting new HTTP connection (%d): %sR!R"RR0( R;tlogtinfoR!t ConnectionClsR"Rtconnect_timeoutR0R=(R#tconn((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt _new_conn¶s  cCsÚd }y"|jjd|jd|ƒ}WnKtk rJt|dƒ‚n,tk ru|jrvt|dƒ‚qvnX|rÊt|ƒrÊt j d|j ƒ|j ƒt |ddƒdkrÊd }qÊn|pÙ|jƒS( s™ 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``. R6RsPool is closed.s>Pool reached maximum size and no more connections are allowed.s Resetting dropped connection: %st auto_openiiN(R*R5tgetR6tAttributeErrorRRRRRDRER!tclosetgetattrRI(R#RRH((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt _get_connÃs "      cCsmy|jj|dtƒdSWn5tk r1n%tk rUtjd|jƒnX|ri|jƒndS(sä 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. R6Ns2Connection pool is full, discarding connection: %s( R5R:tFalseRLRRDtwarningR!RM(R#RH((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt _put_connés  cCsdS(sU Called right before a request is made, after the socket is created. N((R#RH((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt_validate_connscCsC|tkr|jjƒSt|tƒr2|jƒStj|ƒSdS(s< Helper that always returns a :class:`urllib3.util.Timeout` N(t_DefaultRtcloneR1RR2(R#R((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt _get_timeout s    c Ksþ|jd7_|j|ƒ}|jƒ|j|_|j|ƒ|j||||j}t|dd ƒrÏ|dkr”t ||d|ƒ‚n|t j kr¼|j jtjƒƒqÏ|j j|ƒny:y|jdtƒ}Wntk r|jƒ}nXWn¶tk r2t ||d|ƒ‚ntk r„} dt| ƒksedt| ƒkr~t ||d|ƒ‚n‚n>tk rÁ} | jtkr»t ||d|ƒ‚n‚nXt|dd ƒ} tjd ||| |j|jfƒ|S( s 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. itsockis!Read timed out. (read timeout=%s)t bufferings timed outsdid not complete (read)t _http_vsn_strsHTTP/?s"%s %s %s" %s %sN(R<RVt start_connectRGRRStrequestt read_timeoutRNR*R RtDEFAULT_TIMEOUTRWt settimeouttsockettgetdefaulttimeoutt getresponsetTruet TypeErrort SocketTimeoutRtstrt SocketErrorterrnot_blocking_errnosRDtdebugtstatustlength( R#RHtmethodturlRthttplib_request_kwt timeout_objR\thttplib_responsetet http_version((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt _make_requestsL       cCsa|jd}|_y6x/trG|jdtƒ}|r|jƒqqWWntk r\nXdS(sD Close all pooled connections and disable the pool. R6N(R5R*RbRKRPRMR(R#told_poolRH((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyRMms  cCs—|jdƒrtSt|ƒ\}}}|jrJ| rJtj|ƒ}n(|j rr|tj|ƒkrrd}n|||f|j|j|jfkS(sj Check if the given ``url`` is a member of the same host as this connection pool. t/N( t startswithRbRR"RRKR*R+R!(R#RmR+R!R"((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt is_same_host}s c Ks|dkr|j}nt|tƒsHtj|d|d|jƒ}n| dkri| jdtƒ} n|r”|j|ƒ r”t |||ƒ‚nd} |j dkrÈ|j ƒ}|j |j ƒnd} z‚yh|jd| ƒ} |j| ||d|d|d|ƒ}| o| }tj|d|d || }Wntk r[t|d ƒ‚nôttfk r…}t} t|ƒ‚nÊtttfk rN}| r¶| jƒd} ntjƒd }t|tƒrð|jrðtd |ƒ}n't|ttfƒrtd |ƒ}n|j ||d|d|d|ƒ}|j!ƒ|} nXWd| ri|j"| ƒnX| s¾t#j$d|| |fƒ|j%|||||||d|d| d| | S|oÍ|j&ƒ}|rˆ|j'dkrîd}ny"|j ||d|d|ƒ}Wn!t(k r3|j)r/‚n|SXt#j*d||fƒ|j%||||d|d|d|d|d| d| | S|j+|d|j'ƒr|j ||d|d|ƒ}|j!ƒt#j*d|ƒ|j%||||d|d|d|d|d| d| | S|S(s 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 body: Data to send in the request body (useful for creating POST requests, see HTTPConnectionPool.post_url for more convenience). :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 \**response_kw: Additional parameters are passed to :meth:`urllib3.response.HTTPResponse.from_httplib` tredirecttdefaulttpreload_contentR.RtbodyR@R5t connections"No pool connections are available.isCannot connect to proxy.sConnection aborted.Rt_poolt _stacktraceNs1Retrying (%r) after connection broken by '%r': %st pool_timeoutt release_conni/tGETtresponsesRedirecting %s -> %sR4tassert_same_hostt status_codesForced retry: %s(,R*R@R1Rtfrom_intR4RKRbRwRR+tcopytupdateR8RORsRt from_httplibRRRRR RRRfRMtsystexc_infoR7R Rt incrementtsleepRRRDRQturlopentget_redirect_locationRjR traise_on_redirectREtis_forced_retry(R#RlRmR{R@R4RxRƒRRR€t response_kwRHterrRpt response_connR‚Rqt stacktracetredirect_location((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyRsšS  !              "         N(R&R(R)R+RRFR*RPRR]R$RIRORRRSRVRTRsRMRwRbR(((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyR-Os$: % &   T    tHTTPSConnectionPoolcBsqeZdZdZeZdeej dedddddddddddd„Z d„Z d„Z d„Z RS(s» Same as :class:`.HTTPConnectionPool`, but HTTPS. When Python is compiled with the :mod:`ssl` module, then :class:`.VerifiedHTTPSConnection` is used, which *can* verify certificates, instead of :class:`.HTTPSConnection`. :class:`.VerifiedHTTPSConnection` 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`` and ``ssl_version`` 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. thttpsic Ksqtj|||||||||| | | | |_| |_| |_||_||_||_||_dS(N( R-R$tkey_filet cert_filet cert_reqstca_certst ssl_versiontassert_hostnametassert_fingerprint(R#R!R"R0RR?R6R@R4RARBR˜R™RšR›RœRRžR=((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyR$|s       c Csðt|tƒr^|jd|jd|jd|jd|jd|jd|jƒ|j |_ n|j d k rìy |j }Wnt k r–|j}nXtjd krÆ|j rÆ||j|jƒn||j|j|jƒ|jƒn|S( sˆ Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket` and establish the tunnel if proxy is used. R˜R™RšR›RRžiiiN(iii(R1Rtset_certR˜R™RšR›RRžRœR7R*t set_tunnelRLt _set_tunnelR‰t version_infoR8R!R"tconnect(R#RHR ((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyt _prepare_conns$         c CsÐ|jd7_tjd|j|jfƒ|j sE|jtkrTtdƒ‚n|j}|j}|jdk r|jj}|jj}n|jd|d|d|j j d|j |j }|j|ƒS( sB Return a fresh :class:`httplib.HTTPSConnection`. is&Starting new HTTPS connection (%d): %ssCCan't connect to HTTPS URL because the SSL module is not available.R!R"RR0N(R;RDRER!RFRR R"R7R*RRGR0R=R¤(R#t actual_hostt actual_portRH((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyRI±s     cCsUtt|ƒj|ƒt|ddƒs5|jƒn|jsQtjdt ƒndS(sU Called right before a request is made, after the socket is created. RWsÊUnverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html (This warning will only appear once by default.)N( tsuperR–RSRNR*R£t is_verifiedtwarningstwarnR(R#RH((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyRSÊs  N(R&R(R)R+RRFR*RPRR]R$R¤RIRS(((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyR–gs    ! cKsKt|ƒ\}}}|dkr4t|d||St|d||SdS(s€ 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', '/') R—R"N(RR–R-(RmtkwR+R!R"((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pytconnection_from_urlÝs (CRgtloggingR‰R©R_RRfRRdtqueueRRRt ImportErrortQueueRCt exceptionsRRRRR R R R R RRtpackages.ssl_match_hostnameRtpackagesRR|RRRRRRRR[RR‚Rtutil.connectionRt util.retryRt util.timeoutRtutil.urlRtmovesR9t getLoggerR&RDtobjectRTRtsettEAGAINt EWOULDBLOCKRhR-R–R¬(((sU/opt/freeware/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyts<       L 4  ÿÿv