本文整理汇总了Python中swift.common.bufferedhttp.BufferedHTTPConnection._set_tunnel方法的典型用法代码示例。如果您正苦于以下问题:Python BufferedHTTPConnection._set_tunnel方法的具体用法?Python BufferedHTTPConnection._set_tunnel怎么用?Python BufferedHTTPConnection._set_tunnel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.bufferedhttp.BufferedHTTPConnection
的用法示例。
在下文中一共展示了BufferedHTTPConnection._set_tunnel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _connect
# 需要导入模块: from swift.common.bufferedhttp import BufferedHTTPConnection [as 别名]
# 或者: from swift.common.bufferedhttp.BufferedHTTPConnection import _set_tunnel [as 别名]
def _connect(self, url=None):
if not url:
if not self.storage_url:
self._auth()
url = self.storage_url
parsed = urlparse(url)
proxy_parsed = urlparse(self.proxy) if self.proxy else None
netloc = (proxy_parsed if self.proxy else parsed).netloc
if parsed.scheme == "http":
conn = HTTPConnection(netloc)
elif parsed.scheme == "https":
conn = HTTPSConnection(netloc)
else:
raise HTTPException("Cannot handle protocol scheme %s for url %s" % (parsed.scheme, repr(url)))
if self.proxy:
conn._set_tunnel(parsed.hostname, parsed.port)
return parsed, conn
示例2: http_connection
# 需要导入模块: from swift.common.bufferedhttp import BufferedHTTPConnection [as 别名]
# 或者: from swift.common.bufferedhttp.BufferedHTTPConnection import _set_tunnel [as 别名]
def http_connection(url, proxy=None):
"""
Make an HTTPConnection or HTTPSConnection
:param url: url to connect to
:param proxy: proxy to connect through, if any; None by default; str of the
format 'http://127.0.0.1:8888' to set one
:returns: tuple of (parsed url, connection object)
:raises ClientException: Unable to handle protocol scheme
"""
url = encode_utf8(url)
parsed = urlparse(url)
proxy_parsed = urlparse(proxy) if proxy else None
if parsed.scheme == 'http':
conn = HTTPConnection((proxy_parsed if proxy else parsed).netloc)
elif parsed.scheme == 'https':
conn = HTTPSConnection((proxy_parsed if proxy else parsed).netloc)
else:
raise ClientException('Cannot handle protocol scheme %s for url %s' %
(parsed.scheme, repr(url)))
def putheader_wrapper(func):
@wraps(func)
def putheader_escaped(key, value):
func(encode_utf8(key), encode_utf8(value))
return putheader_escaped
conn.putheader = putheader_wrapper(conn.putheader)
def request_wrapper(func):
@wraps(func)
def request_escaped(method, url, body=None, headers=None):
url = encode_utf8(url)
if body:
body = encode_utf8(body)
func(method, url, body=body, headers=headers or {})
return request_escaped
conn.request = request_wrapper(conn.request)
if proxy:
conn._set_tunnel(parsed.hostname, parsed.port)
return parsed, conn
示例3: http_connection
# 需要导入模块: from swift.common.bufferedhttp import BufferedHTTPConnection [as 别名]
# 或者: from swift.common.bufferedhttp.BufferedHTTPConnection import _set_tunnel [as 别名]
def http_connection(url, proxy=None):
"""
Make an HTTPConnection or HTTPSConnection
:param url: url to connect to
:param proxy: proxy to connect through, if any; None by default; str of the
format 'http://127.0.0.1:8888' to set one
:returns: tuple of (parsed url, connection object)
:raises ClientException: Unable to handle protocol scheme
"""
parsed = urlparse(url)
proxy_parsed = urlparse(proxy) if proxy else None
if parsed.scheme == "http":
conn = HTTPConnection((proxy_parsed if proxy else parsed).netloc)
elif parsed.scheme == "https":
conn = HTTPSConnection((proxy_parsed if proxy else parsed).netloc)
else:
raise ClientException("Cannot handle protocol scheme %s for url %s" % (parsed.scheme, repr(url)))
if proxy:
conn._set_tunnel(parsed.hostname, parsed.port)
return parsed, conn