<s> from . _collections import RecentlyUsedContainer <EOL> from . connectionpool import ( <EOL> HTTPConnectionPool , HTTPSConnectionPool , <EOL> get_host , connection_from_url , <EOL> ) <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> from . request import RequestMethods <EOL> from . connectionpool import HTTPConnectionPool , HTTPSConnectionPool <EOL> pool_classes_by_scheme = { <EOL> '<STR_LIT:http>' : HTTPConnectionPool , <EOL> '<STR_LIT>' : HTTPSConnectionPool , <EOL> } <EOL> port_by_scheme = { <EOL> '<STR_LIT:http>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> class PoolManager ( RequestMethods ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , num_pools = <NUM_LIT:10> , ** connection_pool_kw ) : <EOL> self . connection_pool_kw = connection_pool_kw <EOL> self . pools = RecentlyUsedContainer ( num_pools ) <EOL> def connection_from_host ( self , host , port = <NUM_LIT> , scheme = '<STR_LIT:http>' ) : <EOL> """<STR_LIT>""" <EOL> pool_key = ( scheme , host , port ) <EOL> pool = self . pools . get ( pool_key ) <EOL> if pool : <EOL> return pool <EOL> pool_cls = pool_classes_by_scheme [ scheme ] <EOL> pool = pool_cls ( host , port , ** self . connection_pool_kw ) <EOL> self . pools [ pool_key ] = pool <EOL> return pool <EOL> def connection_from_url ( self , url ) : <EOL> """<STR_LIT>""" <EOL> scheme , host , port = get_host ( url ) <EOL> port = port or port_by_scheme . get ( scheme , <NUM_LIT> ) <EOL> return self . connection_from_host ( host , port = port , scheme = scheme ) <EOL> def urlopen ( self , method , url , ** kw ) : <EOL> """<STR_LIT>""" <EOL> conn = self . connection_from_url ( url ) <EOL> return conn . urlopen ( method , url , assert_same_host = False , ** kw ) <EOL> class ProxyManager ( RequestMethods ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , proxy_pool ) : <EOL> self . proxy_pool = proxy_pool <EOL> def urlopen ( self , method , url , ** kw ) : <EOL> "<STR_LIT>" <EOL> kw [ '<STR_LIT>' ] = False <EOL> return self . proxy_pool . urlopen ( method , url , ** kw ) <EOL> def proxy_from_url ( url , ** pool_kw ) : <EOL> proxy_pool = connection_from_url ( url , ** pool_kw ) <EOL> return ProxyManager ( proxy_pool ) </s>
