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


Python Encoder.encode方法代码示例

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


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

示例1: test_resizing_header_table

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_resizing_header_table(self):
        # We need to encode a substantial number of headers, to populate the
        # header table.
        e = Encoder()
        header_set = [
            (':method', 'GET'),
            (':scheme', 'https'),
            (':path', '/some/path'),
            (':authority', 'www.example.com'),
            ('custom-key', 'custom-value'),
            (
                "user-agent",
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) "
                "Gecko/20100101 Firefox/16.0",
            ),
            (
                "accept",
                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;"
                "q=0.8",
            ),
            ('X-Lukasa-Test', '88989'),
        ]
        e.encode(header_set, huffman=True)

        # Resize the header table to a size so small that nothing can be in it.
        e.header_table_size = 40
        assert len(e.header_table.dynamic_entries) == 0
开发者ID:Coder206,项目名称:servo,代码行数:29,代码来源:test_hpack.py

示例2: test_evicting_header_table_objects

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_evicting_header_table_objects(self):
        e = Encoder()

        # Set the header table size large enough to include one header.
        e.header_table_size = 66
        header_set = [('a', 'b'), ('long-custom-header', 'longish value')]
        e.encode(header_set)

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

示例3: test_request_examples_with_huffman

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [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.
        """
        e = Encoder()
        first_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com'),
        ]
        first_header_table = [(':authority', 'www.example.com')]
        first_result = (
            b'\x82\x86\x84\x41\x8c\xf1\xe3\xc2\xe5\xf2:k\xa0\xab\x90\xf4\xff'
        )

        assert e.encode(first_header_set, huffman=True) == first_result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8'))
            for n, v in first_header_table
        ]

        second_header_table = [
            ('cache-control', 'no-cache'),
            (':authority', 'www.example.com')
        ]
        second_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com',),
            ('cache-control', 'no-cache'),
        ]
        second_result = b'\x82\x86\x84\xbeX\x86\xa8\xeb\x10d\x9c\xbf'

        assert e.encode(second_header_set, huffman=True) == second_result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8'))
            for n, v in second_header_table
        ]

        third_header_set = [
            (':method', 'GET',),
            (':scheme', 'https',),
            (':path', '/index.html',),
            (':authority', 'www.example.com',),
            ('custom-key', 'custom-value'),
        ]
        third_result = (
            b'\x82\x87\x85\xbf'
            b'@\x88%\xa8I\xe9[\xa9}\x7f\x89%\xa8I\xe9[\xb8\xe8\xb4\xbf'
        )

        assert e.encode(third_header_set, huffman=True) == third_result
        assert len(e.header_table.dynamic_entries) == 3
开发者ID:Coder206,项目名称:servo,代码行数:58,代码来源:test_hpack.py

示例4: test_request_examples_without_huffman

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_request_examples_without_huffman(self):
        """
        This section shows several consecutive header sets, corresponding to
        HTTP requests, on the same connection.
        """
        e = Encoder()
        first_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com'),
        ]
        # We should have :authority in first_header_table since we index it
        first_header_table = [(':authority', 'www.example.com')]
        first_result = b'\x82\x86\x84\x41\x0fwww.example.com'

        assert e.encode(first_header_set, huffman=False) == first_result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8'))
            for n, v in first_header_table
        ]

        second_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com',),
            ('cache-control', 'no-cache'),
        ]
        second_header_table = [
            ('cache-control', 'no-cache'),
            (':authority', 'www.example.com')
        ]
        second_result = b'\x82\x86\x84\xbeX\x08no-cache'

        assert e.encode(second_header_set, huffman=False) == second_result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8'))
            for n, v in second_header_table
        ]

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

        assert e.encode(third_header_set, huffman=False) == third_result
        # Don't check the header table here, it's just too complex to be
        # reliable. Check its length though.
        assert len(e.header_table.dynamic_entries) == 3
开发者ID:Coder206,项目名称:servo,代码行数:58,代码来源:test_hpack.py

示例5: get_frame_bin

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def get_frame_bin(self):

        # Encode header

        encoder = Encoder()

        headers_frame_field = bytearray()

        if self._data is None:  # if user didn't touch data
            self._data = encoder.encode(self._header_list)  # encode header list

        self._flag = self.flag  # get flag by method

        if self._is_padded:

            headers_frame_field.append(self._pad_len)  # append pad length

            self._data += bytearray(self._pad_len)  # append pad byte in pad length

        if self._is_priority:
            headers_frame_field += int_to_bytes(self._dependency_id, 4)  # append dependency stream id
            headers_frame_field.append(self._weight)

        self._data = headers_frame_field + self._data  # append HEADERS field

        return Frame.get_frame_bin(self)
开发者ID:SomaSoma,项目名称:dogu,代码行数:28,代码来源:header_frame.py

示例6: build_headers_frame

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
def build_headers_frame(headers, encoder=None):
    f = HeadersFrame(1)
    e = encoder
    if e is None:
        e = Encoder()
        e.huffman_coder = HuffmanEncoder(REQUEST_CODES, REQUEST_CODES_LENGTH)
    f.data = e.encode(headers)
    f.flags.add('END_HEADERS')
    return f
开发者ID:JasonGowthorpe,项目名称:hyper,代码行数:11,代码来源:test_integration.py

示例7: test_resizing_header_table_sends_multiple_updates

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_resizing_header_table_sends_multiple_updates(self):
        e = Encoder()

        e.header_table_size = 40
        e.header_table_size = 100
        e.header_table_size = 40

        header_set = [(':method', 'GET')]
        out = e.encode(header_set, huffman=True)
        assert out == b'\x3F\x09\x3F\x45\x3F\x09\x82'
开发者ID:Stranger6667,项目名称:hpack,代码行数:12,代码来源:test_hpack.py

示例8: test_literal_header_field_without_indexing

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

        assert e.encode(header_set, huffman=False) == result
        assert list(e.header_table) == []
开发者ID:tatsuhiro-t,项目名称:hpack-1,代码行数:13,代码来源:test_hyper.py

示例9: test_indexed_header_field_from_static_table

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_indexed_header_field_from_static_table(self):
        e = Encoder()
        e.header_table_size = 0
        header_set = {':method': 'GET'}
        result = b'\x82'

        # Make sure we don't emit an encoding context update.
        e.header_table.resized = False

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

示例10: test_indexed_header_field

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

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

示例11: test_can_encode_a_story_with_huffman

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_can_encode_a_story_with_huffman(self, raw_story):
        d = Decoder()
        e = Encoder()

        for case in raw_story['cases']:
            # The input headers are a list of dicts, which is annoying.
            input_headers = [(item[0], item[1]) for header in case['headers'] for item in header.items()]

            encoded = e.encode(input_headers, huffman=True)
            decoded_headers = d.decode(encoded)

            assert input_headers == decoded_headers
开发者ID:Stranger6667,项目名称:hpack,代码行数:14,代码来源:test_hpack_integration.py

示例12: test_resizing_header_table_sends_context_update

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_resizing_header_table_sends_context_update(self):
        e = Encoder()

        # Resize the header table to a size so small that nothing can be in it.
        e.header_table_size = 40

        # Now, encode a header set. Just a small one, with a well-defined
        # output.
        header_set = [(':method', 'GET')]
        out = e.encode(header_set, huffman=True)

        assert out == b'?\t\x82'
开发者ID:Stranger6667,项目名称:hpack,代码行数:14,代码来源:test_hpack.py

示例13: test_setting_table_size_to_the_same_does_nothing

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_setting_table_size_to_the_same_does_nothing(self):
        e = Encoder()

        # Set the header table size to the default.
        e.header_table_size = 4096

        # Now encode a header set. Just a small one, with a well-defined
        # output.
        header_set = [(':method', 'GET')]
        out = e.encode(header_set, huffman=True)

        assert out == b'\x82'
开发者ID:Stranger6667,项目名称:hpack,代码行数:14,代码来源:test_hpack.py

示例14: test_indexed_literal_header_field_with_indexing

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_indexed_literal_header_field_with_indexing(self):
        """
        The header field representation uses an indexed name and a literal
        value and performs incremental indexing.
        """
        e = Encoder()
        header_set = {':path': '/sample/path'}
        result = b'\x44\x0c/sample/path'

        assert e.encode(header_set, huffman=False) == result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8')) for n, v in header_set.items()
        ]
开发者ID:Stranger6667,项目名称:hpack,代码行数:15,代码来源:test_hpack.py

示例15: test_literal_header_field_with_indexing

# 需要导入模块: from hpack.hpack import Encoder [as 别名]
# 或者: from hpack.hpack.Encoder import encode [as 别名]
    def test_literal_header_field_with_indexing(self):
        """
        The header field representation uses a literal name and a literal
        value.
        """
        e = Encoder()
        header_set = {'custom-key': 'custom-header'}
        result = b'\x40\x0acustom-key\x0dcustom-header'

        assert e.encode(header_set, huffman=False) == result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8')) for n, v in header_set.items()
        ]
开发者ID:Stranger6667,项目名称:hpack,代码行数:15,代码来源:test_hpack.py


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