本文整理汇总了Python中urllib.proxy_bypass方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.proxy_bypass方法的具体用法?Python urllib.proxy_bypass怎么用?Python urllib.proxy_bypass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib
的用法示例。
在下文中一共展示了urllib.proxy_bypass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_proxy
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import proxy_bypass [as 别名]
def find_proxy(url):
scheme, netloc, path, pars, query, fragment = urlparse.urlparse(url)
proxies = urllib.getproxies()
proxyhost = None
if scheme in proxies:
if '@' in netloc:
sidx = netloc.find('@') + 1
else:
sidx = 0
eidx = netloc.find(':')
if eidx == -1:
eidx = len(netloc)
host = netloc[sidx:eidx]
if not (host == '127.0.0.1' or urllib.proxy_bypass(host)):
proxyurl = proxies[scheme]
proxyelems = urlparse.urlparse(proxyurl)
proxyhost = proxyelems[1]
if DEBUG:
print >> sys.stderr, 'find_proxy: Got proxies', proxies, 'selected', proxyhost, 'URL was', url
return proxyhost
示例2: proxy_open
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import proxy_bypass [as 别名]
def proxy_open(self, req, proxy, type):
orig_type = req.get_type()
proxy_type, user, password, hostport = _parse_proxy(proxy)
if proxy_type is None:
proxy_type = orig_type
if req.host and proxy_bypass(req.host):
return None
if user and password:
user_pass = '%s:%s' % (unquote(user), unquote(password))
creds = base64.b64encode(user_pass).strip()
req.add_header('Proxy-authorization', 'Basic ' + creds)
hostport = unquote(hostport)
req.set_proxy(hostport, proxy_type)
if orig_type == proxy_type or orig_type == 'https':
# let other handlers take care of it
return None
else:
# need to start over, because the other handlers don't
# grok the proxy's URL type
# e.g. if we have a constructor arg proxies like so:
# {'http': 'ftp://proxy.example.com'}, we may end up turning
# a request for http://acme.example.com/a into one for
# ftp://proxy.example.com/a
return self.parent.open(req, timeout=req.timeout)
示例3: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import proxy_bypass [as 别名]
def __init__(self, proxies=None, proxy_bypass=None):
if proxies is None:
proxies = getproxies()
assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
self.proxies = proxies
for type, url in proxies.items():
setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: \
meth(r, proxy, type))
if proxy_bypass is None:
proxy_bypass = urllib.proxy_bypass
self._proxy_bypass = proxy_bypass
示例4: proxied
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import proxy_bypass [as 别名]
def proxied(value):
netloc = urlparse(value).netloc
proxied = bool(getproxies_environment()) and not proxy_bypass(netloc)
return(proxied)