当前位置: 首页>>代码示例>>Python>>正文


Python BufferedHTTPConnection.putheader方法代码示例

本文整理汇总了Python中swift.common.bufferedhttp.BufferedHTTPConnection.putheader方法的典型用法代码示例。如果您正苦于以下问题:Python BufferedHTTPConnection.putheader方法的具体用法?Python BufferedHTTPConnection.putheader怎么用?Python BufferedHTTPConnection.putheader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.common.bufferedhttp.BufferedHTTPConnection的用法示例。


在下文中一共展示了BufferedHTTPConnection.putheader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: http_connection

# 需要导入模块: from swift.common.bufferedhttp import BufferedHTTPConnection [as 别名]
# 或者: from swift.common.bufferedhttp.BufferedHTTPConnection import putheader [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
开发者ID:meitham,项目名称:python-swiftclient,代码行数:44,代码来源:client.py


注:本文中的swift.common.bufferedhttp.BufferedHTTPConnection.putheader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。