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


Python Decoder.decode方法代码示例

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


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

示例1: test_invalid_indexed_literal

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_invalid_indexed_literal(self):
        d = Decoder()

        # Refer to an index that is too large.
        data = b'\x82\x86\x84\x7f\x0a\x0fwww.example.com'
        with pytest.raises(InvalidTableIndex):
            d.decode(data)
开发者ID:Stranger6667,项目名称:hpack,代码行数:9,代码来源:test_hpack.py

示例2: test_invalid_indexed_header

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_invalid_indexed_header(self):
        d = Decoder()

        # Refer to an indexed header that is too large.
        data = b'\xBE\x86\x84\x01\x0fwww.example.com'
        with pytest.raises(InvalidTableIndex):
            d.decode(data)
开发者ID:Stranger6667,项目名称:hpack,代码行数:9,代码来源:test_hpack.py

示例3: test_utf8_errors_raise_hpack_decoding_error

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_utf8_errors_raise_hpack_decoding_error(self):
        d = Decoder()

        # Invalid UTF-8 data.
        data = b'\x82\x86\x84\x01\x10www.\x07\xaa\xd7\x95\xd7\xa8\xd7\x94.com'

        with pytest.raises(HPACKDecodingError):
            d.decode(data)
开发者ID:Stranger6667,项目名称:hpack,代码行数:10,代码来源:test_hpack.py

示例4: test_table_size_middle_rejected

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_table_size_middle_rejected(self):
        """
        If a header table size change comes anywhere but first in the header
        block, it is forbidden.
        """
        d = Decoder()
        data = b'\x82?a\x87\x84A\x8a\x08\x9d\\\x0b\x81p\xdcy\xa6\x99'

        with pytest.raises(HPACKDecodingError):
            d.decode(data)
开发者ID:Coder206,项目名称:servo,代码行数:12,代码来源:test_hpack.py

示例5: test_max_header_list_size

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_max_header_list_size(self):
        """
        If the header block is larger than the max_header_list_size, the HPACK
        decoder throws an OversizedHeaderListError.
        """
        d = Decoder(max_header_list_size=44)
        data = b'\x14\x0c/sample/path'

        with pytest.raises(OversizedHeaderListError):
            d.decode(data)
开发者ID:Coder206,项目名称:servo,代码行数:12,代码来源:test_hpack.py

示例6: test_table_size_not_adjusting

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_table_size_not_adjusting(self):
        """
        If the header table size is shrunk, and then the remote peer doesn't
        join in the shrinking, then an error is raised.
        """
        d = Decoder()
        d.max_allowed_table_size = 128
        data = b'\x82\x87\x84A\x8a\x08\x9d\\\x0b\x81p\xdcy\xa6\x99'

        with pytest.raises(InvalidTableSizeError):
            d.decode(data)
开发者ID:Coder206,项目名称:servo,代码行数:13,代码来源:test_hpack.py

示例7: test_header_table_size_change_above_maximum

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_header_table_size_change_above_maximum(self):
        """
        If a header table size change is received that exceeds the maximum
        allowed table size, it is rejected.
        """
        d = Decoder()
        d.max_allowed_table_size = 127
        data = b'?a\x82\x87\x84A\x8a\x08\x9d\\\x0b\x81p\xdcy\xa6\x99'

        with pytest.raises(InvalidTableSizeError):
            d.decode(data)
开发者ID:Coder206,项目名称:servo,代码行数:13,代码来源:test_hpack.py

示例8: test_request_examples_with_huffman

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_request_examples_with_huffman(self):
        """
        This section shows the same examples as the previous section, but
        using Huffman encoding for the literal values.
        """
        d = Decoder()

        first_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com'),
        ]
        first_header_table = first_header_set[::-1]
        first_data = (
            b'\x82\x86\x84\x01\x8c\xf1\xe3\xc2\xe5\xf2:k\xa0\xab\x90\xf4\xff'
        )

        assert d.decode(first_data) == first_header_set
        assert list(d.header_table.dynamic_entries) == []

        second_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com',),
            ('cache-control', 'no-cache'),
        ]
        second_data = (
            b'\x82\x86\x84\x01\x8c\xf1\xe3\xc2\xe5\xf2:k\xa0\xab\x90\xf4\xff'
            b'\x0f\t\x86\xa8\xeb\x10d\x9c\xbf'
        )

        assert d.decode(second_data) == second_header_set
        assert list(d.header_table.dynamic_entries) == []

        third_header_set = [
            (':method', 'GET',),
            (':scheme', 'https',),
            (':path', '/index.html',),
            (':authority', 'www.example.com',),
            ('custom-key', 'custom-value'),
        ]
        third_data = (
            b'\x82\x87\x85\x01\x8c\xf1\xe3\xc2\xe5\xf2:k\xa0\xab\x90\xf4\[email protected]'
            b'\x88%\xa8I\xe9[\xa9}\x7f\x89%\xa8I\xe9[\xb8\xe8\xb4\xbf'
        )

        assert d.decode(third_data) == third_header_set
        assert len(d.header_table.dynamic_entries) == 1
开发者ID:Stranger6667,项目名称:hpack,代码行数:52,代码来源:test_hpack.py

示例9: test_request_examples_without_huffman

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_request_examples_without_huffman(self):
        """
        This section shows several consecutive header sets, corresponding to
        HTTP requests, on the same connection.
        """
        d = Decoder()
        first_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com'),
        ]
        # The first_header_table doesn't contain 'authority'
        first_data = b'\x82\x86\x84\x01\x0fwww.example.com'

        assert d.decode(first_data) == first_header_set
        assert list(d.header_table.dynamic_entries) == []

        # This request takes advantage of the differential encoding of header
        # sets.
        second_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com',),
            ('cache-control', 'no-cache'),
        ]
        second_data = (
            b'\x82\x86\x84\x01\x0fwww.example.com\x0f\t\x08no-cache'
        )

        assert d.decode(second_data) == second_header_set
        assert list(d.header_table.dynamic_entries) == []

        third_header_set = [
            (':method', 'GET',),
            (':scheme', 'https',),
            (':path', '/index.html',),
            (':authority', 'www.example.com',),
            ('custom-key', 'custom-value'),
        ]
        third_data = (
            b'\x82\x87\x85\x01\[email protected]\ncustom-key\x0ccustom-value'
        )

        assert d.decode(third_data) == third_header_set
        # Don't check the header table here, it's just too complex to be
        # reliable. Check its length though.
        assert len(d.header_table.dynamic_entries) == 1
开发者ID:Stranger6667,项目名称:hpack,代码行数:51,代码来源:test_hpack.py

示例10: test_can_decode_a_story

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_can_decode_a_story(self, story):
        d = Decoder()

        # We test against draft 9 of the HPACK spec.
        if story['draft'] != 9:
            skip("We test against draft 9, not draft %d" % story['draft'])

        for case in story['cases']:
            try:
                d.header_table_size = case['header_table_size']
            except KeyError:
                pass
            decoded_headers = d.decode(unhexlify(case['wire']))

            # The correct headers are a list of dicts, which is annoying.
            correct_headers = [
                (item[0], item[1])
                for header in case['headers']
                for item in header.items()
            ]
            correct_headers = correct_headers
            assert correct_headers == decoded_headers
            assert all(
                isinstance(header, HeaderTuple) for header in decoded_headers
            )
开发者ID:Coder206,项目名称:servo,代码行数:27,代码来源:test_hpack_integration.py

示例11: test_truncated_header_name

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_truncated_header_name(self):
        """
        If a header name is truncated an error is raised.
        """
        d = Decoder()
        # This is a simple header block that has a bad ending. The interesting
        # part begins on the second line. This indicates a string that has
        # literal name and value. The name is a 5 character huffman-encoded
        # string that is only three bytes long.
        data = (
            b'\x82\x87\x84A\x8a\x08\x9d\\\x0b\x81p\xdcy\xa6\x99'
            b'\x00\x85\xf2\xb2J'
        )

        with pytest.raises(HPACKDecodingError):
            d.decode(data)
开发者ID:Coder206,项目名称:servo,代码行数:18,代码来源:test_hpack.py

示例12: test_truncated_header_value

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_truncated_header_value(self):
        """
        If a header value is truncated an error is raised.
        """
        d = Decoder()
        # This is a simple header block that has a bad ending. The interesting
        # part begins on the second line. This indicates a string that has
        # literal name and value. The name is a 5 character huffman-encoded
        # string, but the entire EOS character has been written over the end.
        # This causes hpack to see the header value as being supposed to be
        # 622462 bytes long, which it clearly is not, and so this must fail.
        data = (
            b'\x82\x87\x84A\x8a\x08\x9d\\\x0b\x81p\xdcy\xa6\x99'
            b'\x00\x85\xf2\xb2J\x87\xff\xff\xff\xfd%B\x7f'
        )

        with pytest.raises(HPACKDecodingError):
            d.decode(data)
开发者ID:Coder206,项目名称:servo,代码行数:20,代码来源:test_hpack.py

示例13: test_raw_decoding

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_raw_decoding(self):
        """
        The header field representation is decoded as a raw byte string instead
        of UTF-8
        """
        d = Decoder()
        header_set = [(b'\x00\x01\x99\x30\x11\x22\x55\x21\x89\x14', b'custom-header')]
        data = b'\x40\x0a\x00\x01\x99\x30\x11\x22\x55\x21\x89\x14\x0dcustom-header'

        assert d.decode(data, raw=True) == header_set
开发者ID:Stranger6667,项目名称:hpack,代码行数:12,代码来源:test_hpack.py

示例14: test_literal_header_field_without_indexing

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_literal_header_field_without_indexing(self):
        """
        The header field representation uses an indexed name and a literal
        value.
        """
        d = Decoder()
        header_set = [(':path', '/sample/path')]
        data = b'\x04\x0c/sample/path'

        assert d.decode(data) == header_set
        assert list(d.header_table.dynamic_entries) == []
开发者ID:Stranger6667,项目名称:hpack,代码行数:13,代码来源:test_hpack.py

示例15: test_indexed_header_field

# 需要导入模块: from hpack.hpack import Decoder [as 别名]
# 或者: from hpack.hpack.Decoder import decode [as 别名]
    def test_indexed_header_field(self):
        """
        The header field representation uses an indexed header field, from
        the static table.
        """
        d = Decoder()
        header_set = [(':method', 'GET')]
        data = b'\x82'

        assert d.decode(data) == header_set
        assert list(d.header_table.dynamic_entries) == []
开发者ID:Stranger6667,项目名称:hpack,代码行数:13,代码来源:test_hpack.py


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