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


Python httplib.HTTPResponse方法代码示例

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


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

示例1: __init__

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def __init__(self, info):
        # info is either an email.Message or
        # an httplib.HTTPResponse object.
        if isinstance(info, httplib.HTTPResponse):
            for key, value in info.getheaders():
                self[key.lower()] = value
            self.status = info.status
            self["status"] = str(self.status)
            self.reason = info.reason
            self.version = info.version
        elif isinstance(info, email.Message.Message):
            for key, value in info.items():
                self[key.lower()] = value
            self.status = int(self["status"])
        else:
            for key, value in info.iteritems():
                self[key.lower()] = value
            self.status = int(self.get("status", self.status))
            self.reason = self.get("reason", self.reason) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def __init__(self, info):
        # info is either an email.Message or
        # an httplib.HTTPResponse object.
        if isinstance(info, httplib.HTTPResponse):
            for key, value in info.getheaders():
                self[key.lower()] = value
            self.status = info.status
            self['status'] = str(self.status)
            self.reason = info.reason
            self.version = info.version
        elif isinstance(info, email.Message.Message):
            for key, value in info.items():
                self[key.lower()] = value
            self.status = int(self['status'])
        else:
            for key, value in info.iteritems():
                self[key.lower()] = value
            self.status = int(self.get('status', self.status))
            self.reason = self.get('reason', self.reason) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:21,代码来源:__init__.py

示例3: test_close

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_close(self):
        import httplib

        # calling .close() on urllib2's response objects should close the
        # underlying socket

        # delve deep into response to fetch socket._socketobject
        response = _urlopen_with_retry(test_support.TEST_HTTP_URL)
        abused_fileobject = response.fp
        self.assertIs(abused_fileobject.__class__, socket._fileobject)
        httpresponse = abused_fileobject._sock
        self.assertIs(httpresponse.__class__, httplib.HTTPResponse)
        fileobject = httpresponse.fp
        self.assertIs(fileobject.__class__, socket._fileobject)

        self.assertTrue(not fileobject.closed)
        response.close()
        self.assertTrue(fileobject.closed) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_urllib2net.py

示例4: test_malformed_truncation

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_malformed_truncation(self):
        # Other malformed header lines, especially without colons, used to
        # cause the rest of the header section to be truncated
        resp = (
            b'HTTP/1.1 200 OK\r\n'
            b'Public-Key-Pins: \n'
            b'pin-sha256="xxx=";\n'
            b'report-uri="https://..."\r\n'
            b'Transfer-Encoding: chunked\r\n'
            b'\r\n'
            b'4\r\nbody\r\n0\r\n\r\n'
        )
        resp = httplib.HTTPResponse(FakeSocket(resp))
        resp.begin()
        self.assertIsNotNone(resp.getheader('Public-Key-Pins'))
        self.assertEqual(resp.getheader('Transfer-Encoding'), 'chunked')
        self.assertEqual(resp.read(), b'body') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_httplib.py

示例5: test_parse_all_octets

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_parse_all_octets(self):
        # Ensure no valid header field octet breaks the parser
        body = (
            b'HTTP/1.1 200 OK\r\n'
            b"!#$%&'*+-.^_`|~: value\r\n"  # Special token characters
            b'VCHAR: ' + bytearray(range(0x21, 0x7E + 1)) + b'\r\n'
            b'obs-text: ' + bytearray(range(0x80, 0xFF + 1)) + b'\r\n'
            b'obs-fold: text\r\n'
            b' folded with space\r\n'
            b'\tfolded with tab\r\n'
            b'Content-Length: 0\r\n'
            b'\r\n'
        )
        sock = FakeSocket(body)
        resp = httplib.HTTPResponse(sock)
        resp.begin()
        self.assertEqual(resp.getheader('Content-Length'), '0')
        self.assertEqual(resp.getheader("!#$%&'*+-.^_`|~"), 'value')
        vchar = ''.join(map(chr, range(0x21, 0x7E + 1)))
        self.assertEqual(resp.getheader('VCHAR'), vchar)
        self.assertIsNotNone(resp.getheader('obs-text'))
        folded = resp.getheader('obs-fold')
        self.assertTrue(folded.startswith('text'))
        self.assertIn(' folded with space', folded)
        self.assertTrue(folded.endswith('folded with tab')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_httplib.py

示例6: test_status_lines

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_status_lines(self):
        # Test HTTP status lines

        body = "HTTP/1.1 200 Ok\r\n\r\nText"
        sock = FakeSocket(body)
        resp = httplib.HTTPResponse(sock)
        resp.begin()
        self.assertEqual(resp.read(0), '')  # Issue #20007
        self.assertFalse(resp.isclosed())
        self.assertEqual(resp.read(), 'Text')
        self.assertTrue(resp.isclosed())

        body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
        sock = FakeSocket(body)
        resp = httplib.HTTPResponse(sock)
        self.assertRaises(httplib.BadStatusLine, resp.begin) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_httplib.py

示例7: test_chunked_head

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_chunked_head(self):
        chunked_start = (
            'HTTP/1.1 200 OK\r\n'
            'Transfer-Encoding: chunked\r\n\r\n'
            'a\r\n'
            'hello world\r\n'
            '1\r\n'
            'd\r\n'
        )
        sock = FakeSocket(chunked_start + '0\r\n')
        resp = httplib.HTTPResponse(sock, method="HEAD")
        resp.begin()
        self.assertEqual(resp.read(), '')
        self.assertEqual(resp.status, 200)
        self.assertEqual(resp.reason, 'OK')
        self.assertTrue(resp.isclosed()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_httplib.py

示例8: test_close

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_close(self):
        import httplib

        # calling .close() on urllib2's response objects should close the
        # underlying socket

        # delve deep into response to fetch socket._socketobject
        response = _urlopen_with_retry("http://www.python.org/")
        abused_fileobject = response.fp
        self.assertTrue(abused_fileobject.__class__ is socket._fileobject)
        httpresponse = abused_fileobject._sock
        self.assertTrue(httpresponse.__class__ is httplib.HTTPResponse)
        fileobject = httpresponse.fp
        self.assertTrue(fileobject.__class__ is socket._fileobject)

        self.assertTrue(not fileobject.closed)
        response.close()
        self.assertTrue(fileobject.closed) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:20,代码来源:test_urllib2net.py

示例9: test_response_headers

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_response_headers(self):
        # test response with multiple message headers with the same field name.
        text = ('HTTP/1.1 200 OK\r\n'
                'Set-Cookie: Customer="WILE_E_COYOTE";'
                ' Version="1"; Path="/acme"\r\n'
                'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";'
                ' Path="/acme"\r\n'
                '\r\n'
                'No body\r\n')
        hdr = ('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
               ', '
               'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"')
        s = FakeSocket(text)
        r = httplib.HTTPResponse(s)
        r.begin()
        cookies = r.getheader("Set-Cookie")
        if cookies != hdr:
            self.fail("multiple headers not combined properly") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:20,代码来源:test_httplib.py

示例10: test_close

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_close(self):
        import httplib

        # calling .close() on urllib2's response objects should close the
        # underlying socket

        # delve deep into response to fetch socket._socketobject
        response = _urlopen_with_retry("http://www.example.com/")
        abused_fileobject = response.fp
        self.assertIs(abused_fileobject.__class__, socket._fileobject)
        httpresponse = abused_fileobject._sock
        self.assertIs(httpresponse.__class__, httplib.HTTPResponse)
        fileobject = httpresponse.fp
        self.assertIs(fileobject.__class__, socket._fileobject)

        self.assertTrue(not fileobject.closed)
        response.close()
        self.assertTrue(fileobject.closed) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:test_urllib2net.py

示例11: tell

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def tell(self):
        """
        Obtain the number of bytes pulled over the wire so far. May differ from
        the amount of content returned by :meth:``HTTPResponse.read`` if bytes
        are encoded on the wire (e.g, compressed).
        """
        return self._fp_bytes_read 
开发者ID:war-and-code,项目名称:jawfish,代码行数:9,代码来源:response.py

示例12: from_httplib

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def from_httplib(ResponseCls, r, **response_kw):
        """
        Given an :class:`httplib.HTTPResponse` instance ``r``, return a
        corresponding :class:`urllib3.response.HTTPResponse` object.

        Remaining parameters are passed to the HTTPResponse constructor, along
        with ``original_response=r``.
        """
        headers = r.msg
        if not isinstance(headers, HTTPHeaderDict):
            if PY3: # Python 3
                headers = HTTPHeaderDict(headers.items())
            else: # Python 2
                headers = HTTPHeaderDict.from_httplib(headers)

        # HTTPResponse objects in Python 3 don't have a .strict attribute
        strict = getattr(r, 'strict', 0)
        resp = ResponseCls(body=r,
                           headers=headers,
                           status=r.status,
                           version=r.version,
                           reason=r.reason,
                           strict=strict,
                           original_response=r,
                           **response_kw)
        return resp

    # Backwards-compatibility methods for httplib.HTTPResponse 
开发者ID:war-and-code,项目名称:jawfish,代码行数:30,代码来源:response.py

示例13: fileno

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def fileno(self):
        if self._fp is None:
            raise IOError("HTTPResponse has no file to get a fileno from")
        elif hasattr(self._fp, "fileno"):
            return self._fp.fileno()
        else:
            raise IOError("The file-like object this HTTPResponse is wrapped "
                          "around has no file descriptor") 
开发者ID:war-and-code,项目名称:jawfish,代码行数:10,代码来源:response.py

示例14: test_static_existing_file

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_static_existing_file(self):
    relative_url = '/_ah/api/static/proxy.html'

    # Set up mocks for the call to DiscoveryApiProxy.get_static_file.
    discovery_api = self.mox.CreateMock(
        discovery_api_proxy.DiscoveryApiProxy)
    self.mox.StubOutWithMock(discovery_api_proxy, 'DiscoveryApiProxy')
    discovery_api_proxy.DiscoveryApiProxy().AndReturn(discovery_api)
    static_response = self.mox.CreateMock(httplib.HTTPResponse)
    static_response.status = 200
    static_response.reason = 'OK'
    static_response.getheader('Content-Type').AndReturn('test/type')
    test_body = 'test body'
    discovery_api.get_static_file(relative_url).AndReturn(
        (static_response, test_body))

    # Make sure the dispatch works as expected.
    request = test_utils.build_request(relative_url)
    self.mox.ReplayAll()
    response = self.server.dispatch(request, self.start_response)
    self.mox.VerifyAll()

    response = ''.join(response)
    self.assert_http_match(response, '200 OK',
                           [('Content-Length', '%d' % len(test_body)),
                            ('Content-Type', 'test/type')],
                           test_body) 
开发者ID:elsigh,项目名称:browserscope,代码行数:29,代码来源:endpoints_server_test.py

示例15: test_static_non_existing_file

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPResponse [as 别名]
def test_static_non_existing_file(self):
    relative_url = '/_ah/api/static/blah.html'

    # Set up mocks for the call to DiscoveryApiProxy.get_static_file.
    discovery_api = self.mox.CreateMock(
        discovery_api_proxy.DiscoveryApiProxy)
    self.mox.StubOutWithMock(discovery_api_proxy, 'DiscoveryApiProxy')
    discovery_api_proxy.DiscoveryApiProxy().AndReturn(discovery_api)
    static_response = self.mox.CreateMock(httplib.HTTPResponse)
    static_response.status = 404
    static_response.reason = 'Not Found'
    static_response.getheaders().AndReturn([('Content-Type', 'test/type')])
    test_body = 'No Body'
    discovery_api.get_static_file(relative_url).AndReturn(
        (static_response, test_body))

    # Make sure the dispatch works as expected.
    request = test_utils.build_request(relative_url)
    self.mox.ReplayAll()
    response = self.server.dispatch(request, self.start_response)
    self.mox.VerifyAll()

    response = ''.join(response)
    self.assert_http_match(response, '404 Not Found',
                           [('Content-Length', '%d' % len(test_body)),
                            ('Content-Type', 'test/type')],
                           test_body) 
开发者ID:elsigh,项目名称:browserscope,代码行数:29,代码来源:endpoints_server_test.py


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