本文整理汇总了Python中httptools.HttpRequestParser方法的典型用法代码示例。如果您正苦于以下问题:Python httptools.HttpRequestParser方法的具体用法?Python httptools.HttpRequestParser怎么用?Python httptools.HttpRequestParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httptools
的用法示例。
在下文中一共展示了httptools.HttpRequestParser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parser_request_chunked_2
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_chunked_2(self):
m = mock.Mock()
headers = {}
m.on_header.side_effect = headers.__setitem__
m.on_url = None
m.on_body = None
m.on_headers_complete = None
m.on_chunk_header = None
m.on_chunk_complete = None
p = httptools.HttpRequestParser(m)
p.feed_data(CHUNKED_REQUEST1_1)
p.feed_data(CHUNKED_REQUEST1_2)
self.assertEqual(
headers,
{b'User-Agent': b'spam',
b'Transfer-Encoding': b'chunked',
b'Host': b'bar',
b'Vary': b'*'})
示例2: test_parser_request_chunked_3
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_chunked_3(self):
m = mock.Mock()
p = httptools.HttpRequestParser(m)
p.feed_data(CHUNKED_REQUEST1_3)
self.assertEqual(p.get_method(), b'POST')
m.on_url.assert_called_once_with(b'/test.php?a=b+c')
self.assertEqual(p.get_http_version(), '1.2')
m.on_header.assert_called_with(b'Transfer-Encoding', b'chunked')
m.on_chunk_header.assert_called_with()
m.on_chunk_complete.assert_called_with()
self.assertTrue(m.on_message_complete.called)
示例3: test_parser_request_upgrade_flag
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_upgrade_flag(self):
class Protocol:
def __init__(self):
self.parser = httptools.HttpRequestParser(self)
def on_url(self, url):
assert self.parser.should_upgrade() is False
def on_headers_complete(self):
assert self.parser.should_upgrade() is True
def on_message_complete(self):
assert self.parser.should_upgrade() is True
protocol = Protocol()
try:
protocol.parser.feed_data(UPGRADE_REQUEST1)
except httptools.HttpParserUpgrade:
# Raise as usual.
pass
else:
self.fail('HttpParserUpgrade was not raised')
示例4: test_parser_request_fragmented_header
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_fragmented_header(self):
m = mock.Mock()
headers = {}
m.on_header.side_effect = headers.__setitem__
p = httptools.HttpRequestParser(m)
REQUEST = (
b'PUT / HTTP/1.1\r\nHost: localhost:1234\r\nContent-',
b'Type: text/plain; charset=utf-8\r\n\r\n',
)
p.feed_data(REQUEST[0])
m.on_message_begin.assert_called_once_with()
m.on_url.assert_called_once_with(b'/')
self.assertEqual(headers, {b'Host': b'localhost:1234'})
p.feed_data(REQUEST[1])
self.assertEqual(
headers,
{b'Host': b'localhost:1234',
b'Content-Type': b'text/plain; charset=utf-8'})
示例5: data_received
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def data_received(self, data):
# Check for the request itself getting too large and exceeding
# memory limits
self._total_request_size += len(data)
if self._total_request_size > self.request_max_size:
exception = PayloadTooLarge('Payload Too Large')
self.write_error(exception)
# Create parser if this is the first time we're receiving data
if self.parser is None:
assert self.request is None
self.headers = []
self.parser = HttpRequestParser(self)
# Parse request chunk or close connection
try:
self.parser.feed_data(data)
except HttpParserError:
exception = InvalidUsage('Bad Request')
self.write_error(exception)
示例6: data_received
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def data_received(self, data):
if self._current_parser is None:
assert self._current_request is None
self._current_headers = []
self._current_parser = httptools.HttpRequestParser(self)
self._current_parser.feed_data(data)
示例7: connection_made
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def connection_made(self, transport):
self.parser = httptools.HttpRequestParser(self)
self.transport = transport
示例8: test_parser_request_chunked_1
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_chunked_1(self):
m = mock.Mock()
p = httptools.HttpRequestParser(m)
p.feed_data(CHUNKED_REQUEST1_1)
self.assertEqual(p.get_method(), b'POST')
m.on_message_begin.assert_called_once_with()
m.on_url.assert_called_once_with(b'/test.php?a=b+c')
self.assertEqual(p.get_http_version(), '1.2')
m.on_header.assert_called_with(b'Transfer-Encoding', b'chunked')
m.on_chunk_header.assert_called_with()
m.on_chunk_complete.assert_called_with()
self.assertFalse(m.on_message_complete.called)
m.on_message_begin.assert_called_once_with()
m.reset_mock()
p.feed_data(CHUNKED_REQUEST1_2)
m.on_chunk_header.assert_called_with()
m.on_chunk_complete.assert_called_with()
m.on_header.assert_called_with(b'User-Agent', b'spam')
self.assertEqual(m.on_header.call_count, 2)
self.assertFalse(m.on_message_begin.called)
m.on_message_complete.assert_called_once_with()
示例9: test_parser_request_chunked_cb_error_1
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_chunked_cb_error_1(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_chunk_header.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(CHUNKED_REQUEST1_1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
示例10: test_parser_request_chunked_cb_error_2
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_chunked_cb_error_2(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_chunk_complete.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(CHUNKED_REQUEST1_1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
示例11: test_parser_request_error_in_on_header
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_error_in_on_header(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_header.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(UPGRADE_REQUEST1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
示例12: test_parser_request_error_in_on_message_begin
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_error_in_on_message_begin(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_message_begin.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(UPGRADE_REQUEST1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
示例13: test_parser_request_error_in_cb_on_url
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_error_in_cb_on_url(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_url.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(UPGRADE_REQUEST1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
示例14: test_parser_request_error_in_cb_on_headers_complete
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_error_in_cb_on_headers_complete(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_headers_complete.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(UPGRADE_REQUEST1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
示例15: test_parser_request_3
# 需要导入模块: import httptools [as 别名]
# 或者: from httptools import HttpRequestParser [as 别名]
def test_parser_request_3(self):
p = httptools.HttpRequestParser(None)
with self.assertRaises(httptools.HttpParserInvalidURLError):
p.feed_data(b'POST HTTP/1.2')