Skip to content

Commit 52e2d6f

Browse files
committed
remove py27 compat layer
1 parent 6299a8a commit 52e2d6f

File tree

5 files changed

+16
-69
lines changed

5 files changed

+16
-69
lines changed

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ fail_under = 100
1313
show_missing = True
1414
exclude_lines =
1515
pragma: no cover
16-
omit =
17-
src/hpack/compat.py
18-
src/hpack/hpack_compat.py
1916

2017
[coverage:paths]
2118
source =

src/hpack/compat.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/hpack/hpack.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import logging
99

1010
from .table import HeaderTable, table_entry_size
11-
from .compat import to_byte, to_bytes
1211
from .exceptions import (
1312
HPACKDecodingError, OversizedHeaderListError, InvalidTableSizeError
1413
)
@@ -46,8 +45,8 @@ def _unicode_if_needed(header, raw):
4645
Provides a header as a unicode string if raw is False, otherwise returns
4746
it as a bytestring.
4847
"""
49-
name = to_bytes(header[0])
50-
value = to_bytes(header[1])
48+
name = bytes(header[0])
49+
value = bytes(header[1])
5150
if not raw:
5251
name = name.decode('utf-8')
5352
value = value.decode('utf-8')
@@ -106,10 +105,10 @@ def decode_integer(data, prefix_bits):
106105
mask = (0xFF >> (8 - prefix_bits))
107106

108107
try:
109-
number = to_byte(data[0]) & mask
108+
number = data[0] & mask
110109
if number == max_number:
111110
while True:
112-
next_byte = to_byte(data[index])
111+
next_byte = data[index]
113112
index += 1
114113

115114
if next_byte >= 128:
@@ -457,7 +456,7 @@ def decode(self, data, raw=False):
457456
while current_index < data_len:
458457
# Work out what kind of header we're decoding.
459458
# If the high bit is 1, it's an indexed field.
460-
current = to_byte(data[current_index])
459+
current = data[current_index]
461460
indexed = True if current & 0x80 else False
462461

463462
# Otherwise, if the second-highest bit is 1 it's a field that does
@@ -565,11 +564,11 @@ def _decode_literal(self, data, should_index):
565564
# When should_index is false, if the low four bits of the first byte
566565
# are nonzero the header name is indexed.
567566
if should_index:
568-
indexed_name = to_byte(data[0]) & 0x3F
567+
indexed_name = data[0] & 0x3F
569568
name_len = 6
570569
not_indexable = False
571570
else:
572-
high_byte = to_byte(data[0])
571+
high_byte = data[0]
573572
indexed_name = high_byte & 0x0F
574573
name_len = 4
575574
not_indexable = high_byte & 0x10
@@ -591,7 +590,7 @@ def _decode_literal(self, data, should_index):
591590
if len(name) != length:
592591
raise HPACKDecodingError("Truncated header block")
593592

594-
if to_byte(data[0]) & 0x80:
593+
if data[0] & 0x80:
595594
name = decode_huffman(name)
596595
total_consumed = consumed + length + 1 # Since we moved forward 1.
597596

@@ -603,7 +602,7 @@ def _decode_literal(self, data, should_index):
603602
if len(value) != length:
604603
raise HPACKDecodingError("Truncated header block")
605604

606-
if to_byte(data[0]) & 0x80:
605+
if data[0] & 0x80:
607606
value = decode_huffman(value)
608607

609608
# Updated the total consumed length.

src/hpack/huffman.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
An implementation of a bitwise prefix tree specially built for decoding
77
Huffman-coded content where we already know the Huffman table.
88
"""
9-
from .compat import to_byte, decode_hex
109

1110

1211
class HuffmanEncoder:
@@ -33,8 +32,7 @@ def encode(self, bytes_to_encode):
3332
# Turn each byte into its huffman code. These codes aren't necessarily
3433
# octet aligned, so keep track of how far through an octet we are. To
3534
# handle this cleanly, just use a single giant integer.
36-
for char in bytes_to_encode:
37-
byte = to_byte(char)
35+
for byte in bytes_to_encode:
3836
bin_int_len = self.huffman_code_list_lengths[byte]
3937
bin_int = self.huffman_code_list[byte] & (
4038
2 ** (bin_int_len + 1) - 1
@@ -65,4 +63,4 @@ def encode(self, bytes_to_encode):
6563
missing_digits = expected_digits - len(final_num)
6664
final_num = ('0' * missing_digits) + final_num
6765

68-
return decode_hex(final_num)
66+
return bytes.fromhex(final_num)

test/test_hpack.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
)
1818
from hpack.hpack import _dict_to_iterable, _to_bytes
1919

20-
try:
21-
unicode = unicode
22-
except NameError:
23-
unicode = str
24-
2520

2621
class TestHPACKEncoder:
2722
# These tests are stolen entirely from the IETF specification examples.
@@ -751,7 +746,7 @@ class TestDictToIterable:
751746
As much as possible this tries to be exhaustive.
752747
"""
753748
keys = one_of(
754-
text().filter(lambda k: k and not k.startswith(u':')),
749+
text().filter(lambda k: k and not k.startswith(':')),
755750
binary().filter(lambda k: k and not k.startswith(b':'))
756751
)
757752

@@ -765,8 +760,8 @@ def test_ordering(self, special_keys, boring_keys):
765760
with a colon are emitted first.
766761
"""
767762
def _prepend_colon(k):
768-
if isinstance(k, unicode):
769-
return u':' + k
763+
if isinstance(k, str):
764+
return ':' + k
770765
else:
771766
return b':' + k
772767

@@ -801,8 +796,8 @@ def test_ordering_applies_to_encoding(self, special_keys, boring_keys):
801796
When encoding a dictionary the special keys all appear first.
802797
"""
803798
def _prepend_colon(k):
804-
if isinstance(k, unicode):
805-
return u':' + k
799+
if isinstance(k, str):
800+
return ':' + k
806801
else:
807802
return b':' + k
808803

0 commit comments

Comments
 (0)