當前位置: 首頁>>代碼示例>>Python>>正文


Python httptools.HttpRequestParser方法代碼示例

本文整理匯總了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'*'}) 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:24,代碼來源:test_parser.py

示例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) 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:18,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:26,代碼來源:test_parser.py

示例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'}) 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:24,代碼來源:test_parser.py

示例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) 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:22,代碼來源:server.py

示例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) 
開發者ID:MagicStack,項目名稱:vmbench,代碼行數:9,代碼來源:asyncio_http_server.py

示例7: connection_made

# 需要導入模塊: import httptools [as 別名]
# 或者: from httptools import HttpRequestParser [as 別名]
def connection_made(self, transport):
        self.parser = httptools.HttpRequestParser(self)
        self.transport = transport 
開發者ID:gaojiuli,項目名稱:xweb,代碼行數:5,代碼來源:xweb.py

示例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() 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:33,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:16,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:16,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:15,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:15,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:15,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:15,代碼來源:test_parser.py

示例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') 
開發者ID:MagicStack,項目名稱:httptools,代碼行數:6,代碼來源:test_parser.py


注:本文中的httptools.HttpRequestParser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。