Skip to content

Commit 435af2e

Browse files
committed
remove py27-isms and deprecated elements
1 parent 66381fd commit 435af2e

File tree

9 files changed

+24
-54
lines changed

9 files changed

+24
-54
lines changed

src/h2/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99

10-
class _BooleanConfigOption(object):
10+
class _BooleanConfigOption:
1111
"""
1212
Descriptor for handling a boolean config option. This will block
1313
attempts to set boolean config options to non-bools.
@@ -25,7 +25,7 @@ def __set__(self, instance, value):
2525
setattr(instance, self.attr_name, value)
2626

2727

28-
class DummyLogger(object):
28+
class DummyLogger:
2929
"""
3030
An Logger object that does not actual logging, hence a DummyLogger.
3131
@@ -49,7 +49,7 @@ def trace(self, *vargs, **kwargs):
4949
pass
5050

5151

52-
class H2Configuration(object):
52+
class H2Configuration:
5353
"""
5454
An object that controls the way a single HTTP/2 connection behaves.
5555

src/h2/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AllowedStreamIDs(IntEnum):
7272
ODD = 1
7373

7474

75-
class H2ConnectionStateMachine(object):
75+
class H2ConnectionStateMachine:
7676
"""
7777
A single HTTP/2 connection state machine.
7878
@@ -236,7 +236,7 @@ def process_input(self, input_):
236236
return []
237237

238238

239-
class H2Connection(object):
239+
class H2Connection:
240240
"""
241241
A low-level HTTP/2 connection object. This handles building and receiving
242242
frames and maintains both connection and per-stream state for all streams

src/h2/events.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .settings import ChangedSetting, _setting_code_from_int
1515

1616

17-
class Event(object):
17+
class Event:
1818
"""
1919
Base class for h2 events.
2020
"""
@@ -374,11 +374,16 @@ def __repr__(self):
374374
)
375375

376376

377-
class PingAcknowledged(Event):
377+
class PingAckReceived(Event):
378378
"""
379-
Same as PingAckReceived.
379+
The PingAckReceived event is fired whenever a PING acknowledgment is
380+
received. It contains the 'opaque data' of the PING+ACK frame, allowing the
381+
user to correlate PINGs and calculate RTT.
382+
383+
.. versionadded:: 3.1.0
380384
381-
.. deprecated:: 3.1.0
385+
.. versionchanged:: 4.0.0
386+
Removed deprecated but equivalent ``PingAcknowledged``.
382387
"""
383388
def __init__(self):
384389
#: The data included on the ping.
@@ -390,17 +395,6 @@ def __repr__(self):
390395
)
391396

392397

393-
class PingAckReceived(PingAcknowledged):
394-
"""
395-
The PingAckReceived event is fired whenever a PING acknowledgment is
396-
received. It contains the 'opaque data' of the PING+ACK frame, allowing the
397-
user to correlate PINGs and calculate RTT.
398-
399-
.. versionadded:: 3.1.0
400-
"""
401-
pass
402-
403-
404398
class StreamEnded(Event):
405399
"""
406400
The StreamEnded event is fired whenever a stream is ended by a remote
@@ -637,12 +631,4 @@ def _bytes_representation(data):
637631
if data is None:
638632
return None
639633

640-
hex = binascii.hexlify(data)
641-
642-
# This is moderately clever: on all Python versions hexlify returns a byte
643-
# string. On Python 3 we want an actual string, so we just check whether
644-
# that's what we have.
645-
if not isinstance(hex, str): # pragma: no cover
646-
hex = hex.decode('ascii')
647-
648-
return hex
634+
return binascii.hexlify(data).decode('ascii')

src/h2/frame_buffer.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
CONTINUATION_BACKLOG = 64
2727

2828

29-
class FrameBuffer(object):
29+
class FrameBuffer:
3030
"""
3131
This is a data structure that expects to act as a buffer for HTTP/2 data
3232
that allows iteraton in terms of H2 frames.
@@ -130,7 +130,7 @@ def _update_header_buffer(self, f):
130130
def __iter__(self):
131131
return self
132132

133-
def next(self): # Python 2
133+
def __next__(self):
134134
# First, check that we have enough data to successfully parse the
135135
# next frame header. If not, bail. Otherwise, parse it.
136136
if len(self.data) < 9:
@@ -169,7 +169,4 @@ def next(self): # Python 2
169169
# frame in the sequence instead. Recurse back into ourselves to do
170170
# that. This is safe because the amount of work we have to do here is
171171
# strictly bounded by the length of the buffer.
172-
return f if f is not None else self.next()
173-
174-
def __next__(self): # Python 3
175-
return self.next()
172+
return f if f is not None else self.__next__()

src/h2/settings.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88
state of the settings and the unacknowledged future values of the settings.
99
"""
1010
import collections
11+
from collections.abc import MutableMapping
1112
import enum
1213

1314
from hyperframe.frame import SettingsFrame
1415

1516
from h2.errors import ErrorCodes
1617
from h2.exceptions import InvalidSettingsValueError
1718

18-
try:
19-
from collections.abc import MutableMapping
20-
except ImportError: # pragma: no cover
21-
# Python 2.7 compatibility
22-
from collections import MutableMapping
2319

2420

2521
class SettingCodes(enum.IntEnum):

src/h2/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class StreamClosedBy(Enum):
8080
STREAM_OPEN[StreamState.HALF_CLOSED_REMOTE] = True
8181

8282

83-
class H2StreamStateMachine(object):
83+
class H2StreamStateMachine:
8484
"""
8585
A single HTTP/2 stream state machine.
8686
@@ -736,7 +736,7 @@ def send_alt_svc(self, previous_state):
736736
}
737737

738738

739-
class H2Stream(object):
739+
class H2Stream:
740740
"""
741741
A low-level HTTP/2 stream object. This handles building and receiving
742742
frames and maintains per-stream state.

src/h2/utilities.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@
6161
_CONNECT_REQUEST_ONLY_HEADERS = frozenset([b':protocol', u':protocol'])
6262

6363

64-
if sys.version_info[0] == 2: # Python 2.X
65-
_WHITESPACE = frozenset(whitespace)
66-
else: # Python 3.3+
67-
_WHITESPACE = frozenset(map(ord, whitespace))
64+
_WHITESPACE = frozenset(map(ord, whitespace))
6865

6966

7067
def _secure_headers(headers, hdr_validation_flags):

src/h2/windows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
LARGEST_FLOW_CONTROL_WINDOW = 2**31 - 1
2222

2323

24-
class WindowManager(object):
24+
class WindowManager:
2525
"""
2626
A basic HTTP/2 window manager.
2727

test/test_basic_logic.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
from hypothesis.strategies import integers
2727

2828

29-
IS_PYTHON3 = sys.version_info >= (3, 0)
30-
31-
3229
class TestBasicClient(object):
3330
"""
3431
Basic client-side tests.
@@ -500,9 +497,7 @@ def test_oversize_headers(self):
500497
Sending headers that are oversized generates a stream of CONTINUATION
501498
frames.
502499
"""
503-
all_bytes = [chr(x) for x in range(0, 256)]
504-
if IS_PYTHON3:
505-
all_bytes = [x.encode('latin1') for x in all_bytes]
500+
all_bytes = [chr(x).encode('latin1') for x in range(0, 256)]
506501

507502
large_binary_string = b''.join(
508503
random.choice(all_bytes) for _ in range(0, 256)
@@ -1362,7 +1357,6 @@ def test_receiving_ping_acknowledgement(self, frame_factory):
13621357
event = events[0]
13631358

13641359
assert isinstance(event, h2.events.PingAckReceived)
1365-
assert isinstance(event, h2.events.PingAcknowledged) # deprecated
13661360
assert event.ping_data == ping_data
13671361

13681362
def test_stream_ended_remotely(self, frame_factory):

0 commit comments

Comments
 (0)