本文整理匯總了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