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


Python http_client.HTTPResponse方法代码示例

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


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

示例1: HTMLInputStream

# 需要导入模块: from pip._vendor.six.moves import http_client [as 别名]
# 或者: from pip._vendor.six.moves.http_client import HTTPResponse [as 别名]
def HTMLInputStream(source, **kwargs):
    # Work around Python bug #20007: read(0) closes the connection.
    # http://bugs.python.org/issue20007
    if (isinstance(source, http_client.HTTPResponse) or
        # Also check for addinfourl wrapping HTTPResponse
        (isinstance(source, urllib.response.addbase) and
         isinstance(source.fp, http_client.HTTPResponse))):
        isUnicode = False
    elif hasattr(source, "read"):
        isUnicode = isinstance(source.read(0), text_type)
    else:
        isUnicode = isinstance(source, text_type)

    if isUnicode:
        encodings = [x for x in kwargs if x.endswith("_encoding")]
        if encodings:
            raise TypeError("Cannot set an encoding with a unicode input, set %r" % encodings)

        return HTMLUnicodeInputStream(source, **kwargs)
    else:
        return HTMLBinaryInputStream(source, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:_inputstream.py

示例2: HTMLInputStream

# 需要导入模块: from pip._vendor.six.moves import http_client [as 别名]
# 或者: from pip._vendor.six.moves.http_client import HTTPResponse [as 别名]
def HTMLInputStream(source, encoding=None, parseMeta=True, chardet=True):
    if isinstance(source, http_client.HTTPResponse):
        # Work around Python bug #20007: read(0) closes the connection.
        # http://bugs.python.org/issue20007
        isUnicode = False
    elif hasattr(source, "read"):
        isUnicode = isinstance(source.read(0), text_type)
    else:
        isUnicode = isinstance(source, text_type)

    if isUnicode:
        if encoding is not None:
            raise TypeError("Cannot explicitly set an encoding with a unicode string")

        return HTMLUnicodeInputStream(source)
    else:
        return HTMLBinaryInputStream(source, encoding, parseMeta, chardet) 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:inputstream.py


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