本文整理汇总了Python中http.client.HTTPMessage方法的典型用法代码示例。如果您正苦于以下问题:Python client.HTTPMessage方法的具体用法?Python client.HTTPMessage怎么用?Python client.HTTPMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.client
的用法示例。
在下文中一共展示了client.HTTPMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_headers
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTPMessage [as 别名]
def parse_headers(fp, _class=HTTPMessage):
headers = []
while True:
line = await fp.readline()
headers.append(line)
if line in (b'\r\n', b'\n', b''):
break
hstring = b''.join(headers).decode('iso-8859-1')
return email.parser.Parser(_class=_class).parsestr(hstring)
示例2: _create_mock_request
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTPMessage [as 别名]
def _create_mock_request(self, path='http://www.example.com/test/path/'):
mock_request = Mock()
mock_request.path = path
mock_request.command = 'GET'
headers = HTTPMessage()
headers.add_header('Host', 'www.example.com')
headers.add_header('Accept', '*/*')
mock_request.headers = headers
return mock_request
示例3: _create_mock_resonse
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTPMessage [as 别名]
def _create_mock_resonse(self):
mock_response = Mock()
mock_response.status = 200
mock_response.reason = 'OK'
headers = HTTPMessage()
headers.add_header('Content-Type', 'application/json')
headers.add_header('Content-Length', '500')
mock_response.headers = headers
return mock_response
示例4: _make_response
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTPMessage [as 别名]
def _make_response(self, result, url):
data = "\r\n".join(["%s: %s" % (k, v) for k, v in result.header_items])
if PY2:
headers = HTTPMessage(BytesIO(data))
else:
import email
headers = email.message_from_string(data)
response = addinfourl(BytesIO(result.data), headers, url)
code, msg = result.status.split(None, 1)
response.code, response.msg = int(code), msg
return response
示例5: __init__
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTPMessage [as 别名]
def __init__(self, status):
super(MockHttpResponse, self).__init__()
self.status = status
self.strict = 0
self.version = 0
self.reason = None
self.msg = HTTPMessage(io.BytesIO())
self.closed = True
示例6: _parse_headers
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTPMessage [as 别名]
def _parse_headers(fp):
"""This is a modification of the python3 http.clint.parse_headers function."""
headers = []
while True:
line = fp.readline(65536)
headers.append(line)
if line in (b'\r\n', b'\n', b''):
break
hstring = b''.join(headers)
return email.parser.Parser(_class=HTTPMessage).parsestr(hstring.decode('iso-8859-1')), hstring