ó i×L]c@sÂddlZddlZddlZyddlmZWn!ek r[ddlmZnXddlmZddl m Z m Z ddl m Z ddl mZmZddlmZdd lmZdd lmZd d d gZejeƒZd%Zejdd&ƒZejdejd'ƒZejdejeƒZd„Z iej!e eƒd 6ej!e eƒd!6Z"ie d 6e d!6Z#d efd"„ƒYZ$d e$fd#„ƒYZ%d$„Z&dS((iÿÿÿÿN(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 |jƒS(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|jƒtS(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|dƒq5Wn||||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_pool‡s    cCs|jjƒdS(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.pyR6˜sR&cCsz|stdƒ‚n|jjƒ}|p-d|d<|sYtj|djƒdƒ}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_host¡s  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.pyRCµs  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.pyRSãs@ $     "    N(t__name__t __module__t__doc__R>RRR,R5R;RBR6RDRCRERLtTrueRS(((s7/usr/lib/python2.7/site-packages/urllib3/poolmanager.pyR Vs      cBsGeZdZdddd„Zddd„Zdd„Zed„ZRS(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 cKs¿t|tƒr.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