!gc@sddlZddlZddlZyddlmZWn!ek r[ddlmZnXddlmZddl m Z m Z ddl m Z ddl mZmZddlmZdd lmZdd lmZd d d gZejeZd%Zejdd&Zejdejd'ZejdejeZdZ iej!e ed 6ej!e ed!6Z"ie d 6e d!6Z#d efd"YZ$d e$fd#YZ%d$Z&dS((iN(turljoini(tRecentlyUsedContainer(tHTTPConnectionPooltHTTPSConnectionPool(tport_by_scheme(tLocationValueErrort MaxRetryError(tRequestMethods(t parse_url(tRetryt PoolManagert ProxyManagertproxy_from_urltkey_filet cert_filet cert_reqstca_certst ssl_versiont ca_cert_dirt BasePoolKeytschemethosttportt HTTPPoolKeyttimeouttretrieststricttblocktsource_addresst HTTPSPoolKeycCs_i}x$|jD]}|j|||>> manager = PoolManager(num_pools=2) >>> r = manager.request('GET', 'http://google.com/') >>> r = manager.request('GET', 'http://google.com/mail') >>> r = manager.request('GET', 'http://yahoo.com/') >>> len(manager.pools) 2 i cKsMtj||||_t|dd|_t|_tj|_dS(Nt dispose_funccSs |jS(N(tclose(tp((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pytxs(Rt__init__tconnection_pool_kwRtpoolstpool_classes_by_schemetkey_fn_by_schemetcopy(tselft num_poolstheadersR-((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR,ts    cCs|S(N((R2((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt __enter__scCs|jtS(N(tcleartFalse(R2texc_typetexc_valtexc_tb((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt__exit__s cCsbt|}|j}|dkrR|jj}x!tD]}|j|dq5Wn||||S(s Create a new :class:`ConnectionPool` based on host, port and scheme. This method is used to actually create the connection pools handed out by :meth:`connection_from_url` and companion methods. It is intended to be overridden for customization. R&N(R/R-R1t SSL_KEYWORDStpoptNone(R2RRRtpool_clstkwargstkw((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyt _new_pools    cCs|jjdS(s Empty our store of pools and direct them all to close. This will not affect in-flight connections, but they will not be re-used after completion. N(R.R6(R2((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR6sR&cCsz|stdn|jj}|p-d|d<|sYtj|djd}n||d<||d<|j|S(s Get a :class:`ConnectionPool` based on the host, port, and scheme. If ``port`` isn't given, it will be derived from the ``scheme`` using ``urllib3.connectionpool.port_by_scheme``. sNo host specified.R&RiPRR(RR-R1RRR tconnection_from_context(R2RRRR"((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pytconnection_from_hosts  cCs6|dj}|j|}||}|j|S(s Get a :class:`ConnectionPool` based on the request context. ``request_context`` must at least contain the ``scheme`` key and its value must be a key in ``key_fn_by_scheme`` instance variable. R(R R0tconnection_from_pool_key(R2R"Rtpool_key_constructortpool_key((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRCs  cCs^|jjL|jj|}|r)|S|j|j|j|j}||j| %sN(RRDRRRR7R4R1tproxyR>turlopent request_uritget_redirect_locationRtstatusRt isinstanceR tfrom_inttremove_headers_on_redirectt is_same_hostR=t incrementRtraise_on_redirecttlogtinfo( R2tmethodRJRNRARKtconnRPtredirect_locationRtheader((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyRSs@ $     "    N(t__name__t __module__t__doc__R>RRR,R5R;RBR6RDRCRERLtTrueRS(((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR Vs      cBsGeZdZddddZdddZddZedZRS(sw Behaves just like :class:`PoolManager`, but sends all requests through the defined proxy, using the CONNECT method for HTTPS URLs. :param proxy_url: The URL of the proxy to be used. :param proxy_headers: A dictionary contaning headers that will be sent to the proxy. In case of HTTP they are being sent with each request, while in the HTTPS/CONNECT case they are sent only once. Could be used for proxy authentication. Example: >>> proxy = urllib3.ProxyManager('http://localhost:3128/') >>> r1 = proxy.request('GET', 'http://google.com/') >>> r2 = proxy.request('GET', 'http://httpbin.org/') >>> len(proxy.pools) 1 >>> r3 = proxy.request('GET', 'https://httpbin.org/') >>> r4 = proxy.request('GET', 'https://twitter.com/') >>> len(proxy.pools) 3 i cKst|tr.d|j|j|jf}nt|}|jsmtj|jd}|jd|}n||_ |pi|_ |j |d<|j |dR,RDRrRfRS(((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR s   cKstd||S(NRl(R (RJRA((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR vs(R RRRRR(sschemeshostsport(RsretriessstrictsblockR('t collectionst functoolstloggingt urllib.parseRt ImportErrorturlparset _collectionsRtconnectionpoolRRRt exceptionsRRtrequestRtutil.urlRt util.retryR t__all__t getLoggerRcR]R<t namedtupleRRRRR%tpartialR0R/R R R (((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pytsB        W