本文整理匯總了Python中httplib2.ProxyInfo方法的典型用法代碼示例。如果您正苦於以下問題:Python httplib2.ProxyInfo方法的具體用法?Python httplib2.ProxyInfo怎麽用?Python httplib2.ProxyInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類httplib2
的用法示例。
在下文中一共展示了httplib2.ProxyInfo方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def __init__(self, config=None, proxy_config=None):
self.config = config
self.client = None
if proxy_config and 'host' in proxy_config and 'port' in proxy_config:
proxy_info = ProxyInfo(socks.PROXY_TYPE_HTTP_NO_TUNNEL,
proxy_config['host'], proxy_config['port'])
else:
proxy_info = None
self.http = Http(proxy_info=proxy_info)
self.var_dir = self.config['var_dir']
if not exists(self.var_dir):
makedirs(self.var_dir)
self.history_id_f = join(self.var_dir, 'gmail_last_history_id')
if exists(self.history_id_f):
with open(self.history_id_f) as fh:
logger.info('Loaded last gmail history id %d', int(fh.read()))
else:
# store an invalid id, which will get renewed on next push event
self.save_last_history_id('1')
示例2: _prepare_proxy_info
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def _prepare_proxy_info(self, proxy):
if not proxy or not proxy.enabled:
_logger.debug('Proxy is not enabled')
return None
username = proxy.username \
if 'username' in proxy and proxy.username else None
password = proxy.password \
if 'password' in proxy and proxy.password else None
proxy_type = self._PROXY_TYPE.get(proxy.type) or self._PROXY_TYPE['http']
return ProxyInfo(proxy_host=proxy.host,
proxy_port=int(proxy.port),
proxy_type=proxy_type,
proxy_user=username,
proxy_pass=password,
proxy_rdns=proxy.rdns)
示例3: __init__
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def __init__(self, cache_key_base, access_token_cache=None,
datetime_strategy=datetime.datetime, auth_uri=None,
token_uri=None, disable_ssl_certificate_validation=False,
proxy_host=None, proxy_port=None, proxy_user=None,
proxy_pass=None, ca_certs_file=None):
# datetime_strategy is used to invoke utcnow() on; it is injected into the
# constructor for unit testing purposes.
self.auth_uri = auth_uri
self.token_uri = token_uri
self.cache_key_base = cache_key_base
self.datetime_strategy = datetime_strategy
self.access_token_cache = access_token_cache or InMemoryTokenCache()
self.disable_ssl_certificate_validation = disable_ssl_certificate_validation
self.ca_certs_file = ca_certs_file
if proxy_host and proxy_port:
self._proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP,
proxy_host,
proxy_port,
proxy_user=proxy_user,
proxy_pass=proxy_pass,
proxy_rdns=True)
else:
self._proxy_info = None
示例4: testSimpleProxy
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def testSimpleProxy(self):
proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP,
'localhost', self.proxyport)
client = httplib2.Http(proxy_info=proxy_info)
src = 'miniserver.py'
response, body = client.request('http://localhost:%d/%s' %
(self.port, src))
self.assertEqual(response.status, 200)
self.assertEqual(body, open(os.path.join(miniserver.HERE, src)).read())
lf = open(self.logfile).read()
expect = ('Established connection to host "127.0.0.1" '
'using file descriptor')
self.assertTrue(expect in lf,
'tinyproxy did not proxy a request for miniserver')
示例5: testProxyDisabled
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def testProxyDisabled(self):
proxy_info = httplib2.ProxyInfo('blah',
'localhost', 0)
client = httplib2.Http(proxy_info=proxy_info)
self.assertRaises(httplib2.ProxiesUnavailableError,
client.request, 'http://localhost:-1/')
示例6: get_http_client_with_proxy
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def get_http_client_with_proxy(proxy, insecure):
"""
Create an http client with proxy with whom to use when using a proxy.
:param proxy: Whether to use a proxy.
:param insecure: Whether to disable ssl and use an insecure connection.
:return:
"""
if proxy:
proxies = handle_proxy()
https_proxy = proxies.get('https')
http_proxy = proxies.get('http')
proxy_conf = https_proxy if https_proxy else http_proxy
# if no proxy_conf - ignore proxy
if proxy_conf:
if not proxy_conf.startswith('https') and not proxy_conf.startswith('http'):
proxy_conf = 'https://' + proxy_conf
parsed_proxy = urllib.parse.urlparse(proxy_conf)
proxy_info = httplib2.ProxyInfo(
proxy_type=httplib2.socks.PROXY_TYPE_HTTP,
proxy_host=parsed_proxy.hostname,
proxy_port=parsed_proxy.port,
proxy_user=parsed_proxy.username,
proxy_pass=parsed_proxy.password)
return httplib2.Http(proxy_info=proxy_info, disable_ssl_certificate_validation=insecure)
return httplib2.Http(disable_ssl_certificate_validation=insecure)
# disable-secrets-detection-end
示例7: __init__
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def __init__(self, config, proxy_cfg=None):
self.config = config
if proxy_cfg:
proxy_info = ProxyInfo(
socks.PROXY_TYPE_HTTP_NO_TUNNEL,
proxy_cfg['host'],
proxy_cfg['port']
)
else:
proxy_info = None
self.http = Http(proxy_info=proxy_info)
self.client = None
示例8: testSimpleProxy
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def testSimpleProxy(self):
proxy_info = httplib2.ProxyInfo(
socks.PROXY_TYPE_HTTP, "localhost", self.proxyport
)
client = httplib2.Http(proxy_info=proxy_info)
src = "miniserver.py"
response, body = client.request("http://localhost:%d/%s" % (self.port, src))
self.assertEqual(response.status, 200)
self.assertEqual(body, open(os.path.join(miniserver.HERE, src)).read())
lf = open(self.logfile).read()
expect = 'Established connection to host "127.0.0.1" ' "using file descriptor"
self.assertTrue(
expect in lf, "tinyproxy did not proxy a request for miniserver"
)
示例9: testProxyDisabled
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def testProxyDisabled(self):
proxy_info = httplib2.ProxyInfo("blah", "localhost", 0)
client = httplib2.Http(proxy_info=proxy_info)
self.assertRaises(
httplib2.ProxiesUnavailableError, client.request, "http://localhost:-1/"
)
示例10: __init__
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def __init__(self, consumer_key, consumer_secret, token_key, token_secret):
consumer = Consumer(key=consumer_key, secret=consumer_secret)
token = Token(key=token_key, secret=token_secret)
proxy_info = None
if hasattr(settings, 'PROXY_HOST') and \
hasattr(settings, 'PROXY_PORT'):
proxy_info = ProxyInfo(
proxy_type=PROXY_TYPE_HTTP,
proxy_host=settings.PROXY_HOST,
proxy_port=settings.PROXY_PORT)
self.client = Client(
consumer=consumer,
token=token,
proxy_info=proxy_info)
示例11: __init__
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def __init__(self, timeout, proxy=None, cacert=None, sessions=False):
##httplib2.debuglevel=4
kwargs = {}
if proxy:
import socks
kwargs['proxy_info'] = httplib2.ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP, **proxy)
print "using proxy", proxy
# set optional parameters according supported httplib2 version
if httplib2.__version__ >= '0.3.0':
kwargs['timeout'] = timeout
if httplib2.__version__ >= '0.7.0':
kwargs['disable_ssl_certificate_validation'] = cacert is None
kwargs['ca_certs'] = cacert
httplib2.Http.__init__(self, **kwargs)
示例12: get_proxy_info
# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import ProxyInfo [as 別名]
def get_proxy_info(proxy_config):
if not proxy_config or not is_true(proxy_config.get('proxy_enabled')):
_logger.info('Proxy is not enabled')
return None
url = proxy_config.get('proxy_url')
port = proxy_config.get('proxy_port')
if url or port:
if not url:
raise ValueError('Proxy "url" must not be empty')
if not util.is_valid_port(port):
raise ValueError(
'Proxy "port" must be in range [1,65535]: %s' % port
)
user = proxy_config.get('proxy_username')
password = proxy_config.get('proxy_password')
if not all((user, password)):
_logger.info('Proxy has no credentials found')
user, password = None, None
proxy_type = proxy_config.get('proxy_type')
proxy_type = proxy_type.lower() if proxy_type else 'http'
if proxy_type in _PROXY_TYPE_MAP:
ptv = _PROXY_TYPE_MAP[proxy_type]
elif proxy_type in list(_PROXY_TYPE_MAP.values()):
ptv = proxy_type
else:
ptv = socks.PROXY_TYPE_HTTP
_logger.info('Proxy type not found, set to "HTTP"')
rdns = is_true(proxy_config.get('proxy_rdns'))
proxy_info = ProxyInfo(
proxy_host=url,
proxy_port=int(port),
proxy_type=ptv,
proxy_user=user,
proxy_pass=password,
proxy_rdns=rdns
)
return proxy_info