Skip to content

Commit f4a5ee7

Browse files
committed
typing++
1 parent b63da7b commit f4a5ee7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/hpack/hpack.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def encode_integer(integer: int, prefix_bits: int) -> bytearray:
7676
return bytearray(elements)
7777

7878

79-
def decode_integer(data: bytes, prefix_bits: int) -> tuple[int, int]:
79+
def decode_integer(data: bytes | memoryview, prefix_bits: int) -> tuple[int, int]:
8080
"""
8181
Decodes an integer according to the wacky integer encoding rules
8282
defined in the HPACK spec. Returns a tuple of the decoded integer and the
@@ -548,7 +548,7 @@ def _assert_valid_table_size(self) -> None:
548548
msg = "Encoder did not shrink table size to within the max"
549549
raise InvalidTableSizeError(msg)
550550

551-
def _update_encoding_context(self, data: bytes) -> int:
551+
def _update_encoding_context(self, data: bytes | memoryview) -> int:
552552
"""
553553
Handles a byte that updates the encoding context.
554554
"""
@@ -560,7 +560,7 @@ def _update_encoding_context(self, data: bytes) -> int:
560560
self.header_table_size = new_size
561561
return consumed
562562

563-
def _decode_indexed(self, data: bytes) -> tuple[HeaderTuple, int]:
563+
def _decode_indexed(self, data: bytes | memoryview) -> tuple[HeaderTuple, int]:
564564
"""
565565
Decodes a header represented using the indexed representation.
566566
"""
@@ -569,16 +569,19 @@ def _decode_indexed(self, data: bytes) -> tuple[HeaderTuple, int]:
569569
log.debug("Decoded %s, consumed %d", header, consumed)
570570
return header, consumed
571571

572-
def _decode_literal_no_index(self, data: bytes) -> tuple[HeaderTuple, int]:
572+
def _decode_literal_no_index(self, data: bytes | memoryview) -> tuple[HeaderTuple, int]:
573573
return self._decode_literal(data, should_index=False)
574574

575-
def _decode_literal_index(self, data: bytes) -> tuple[HeaderTuple, int]:
575+
def _decode_literal_index(self, data: bytes | memoryview) -> tuple[HeaderTuple, int]:
576576
return self._decode_literal(data, should_index=True)
577577

578-
def _decode_literal(self, data: bytes, should_index: bool) -> tuple[HeaderTuple, int]:
578+
def _decode_literal(self, data: bytes | memoryview, should_index: bool) -> tuple[HeaderTuple, int]:
579579
"""
580580
Decodes a header represented with a literal.
581581
"""
582+
if isinstance(data, memoryview):
583+
data = data.tobytes() # pragma: no cover
584+
582585
total_consumed = 0
583586

584587
# When should_index is true, if the low six bits of the first byte are

src/hpack/huffman_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
# This defines the state machine "class" at the top of the file. The reason we
7676
# do this is to keep the terrifing monster state table at the *bottom* of the
7777
# file so you don't have to actually *look* at the damn thing.
78-
def decode_huffman(huffman_string: bytes | bytearray | None) -> bytes:
78+
def decode_huffman(huffman_string: bytes | bytearray | memoryview | None) -> bytes:
7979
"""
8080
Given a bytestring of Huffman-encoded data for HPACK, returns a bytestring
8181
of the decompressed data.

0 commit comments

Comments
 (0)