summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2020-08-01 13:00:28 +0200
committerThomas Kriechbaumer <Kriechi@users.noreply.github.com>2020-08-02 13:34:58 +0200
commit435af2ee322bdde60a5829dfd67b9385e830cc22 (patch)
treebb5a0b91922e0fde9739cc6c0309335fb326b69d /src
parent66381fd4b45466d5e8eef1daf7cefa3a4d2fd476 (diff)
remove py27-isms and deprecated elements
Diffstat (limited to 'src')
-rw-r--r--src/h2/config.py6
-rw-r--r--src/h2/connection.py4
-rw-r--r--src/h2/events.py34
-rw-r--r--src/h2/frame_buffer.py9
-rw-r--r--src/h2/settings.py6
-rw-r--r--src/h2/stream.py4
-rw-r--r--src/h2/utilities.py5
-rw-r--r--src/h2/windows.py2
8 files changed, 23 insertions, 47 deletions
diff --git a/src/h2/config.py b/src/h2/config.py
index 1c437ee..730b611 100644
--- a/src/h2/config.py
+++ b/src/h2/config.py
@@ -7,7 +7,7 @@ Objects for controlling the configuration of the HTTP/2 stack.
"""
-class _BooleanConfigOption(object):
+class _BooleanConfigOption:
"""
Descriptor for handling a boolean config option. This will block
attempts to set boolean config options to non-bools.
@@ -25,7 +25,7 @@ class _BooleanConfigOption(object):
setattr(instance, self.attr_name, value)
-class DummyLogger(object):
+class DummyLogger:
"""
An Logger object that does not actual logging, hence a DummyLogger.
@@ -49,7 +49,7 @@ class DummyLogger(object):
pass
-class H2Configuration(object):
+class H2Configuration:
"""
An object that controls the way a single HTTP/2 connection behaves.
diff --git a/src/h2/connection.py b/src/h2/connection.py
index 881304b..7cf451a 100644
--- a/src/h2/connection.py
+++ b/src/h2/connection.py
@@ -72,7 +72,7 @@ class AllowedStreamIDs(IntEnum):
ODD = 1
-class H2ConnectionStateMachine(object):
+class H2ConnectionStateMachine:
"""
A single HTTP/2 connection state machine.
@@ -236,7 +236,7 @@ class H2ConnectionStateMachine(object):
return []
-class H2Connection(object):
+class H2Connection:
"""
A low-level HTTP/2 connection object. This handles building and receiving
frames and maintains both connection and per-stream state for all streams
diff --git a/src/h2/events.py b/src/h2/events.py
index a06c990..08b3186 100644
--- a/src/h2/events.py
+++ b/src/h2/events.py
@@ -14,7 +14,7 @@ import binascii
from .settings import ChangedSetting, _setting_code_from_int
-class Event(object):
+class Event:
"""
Base class for h2 events.
"""
@@ -374,11 +374,16 @@ class PingReceived(Event):
)
-class PingAcknowledged(Event):
+class PingAckReceived(Event):
"""
- Same as PingAckReceived.
+ The PingAckReceived event is fired whenever a PING acknowledgment is
+ received. It contains the 'opaque data' of the PING+ACK frame, allowing the
+ user to correlate PINGs and calculate RTT.
+
+ .. versionadded:: 3.1.0
- .. deprecated:: 3.1.0
+ .. versionchanged:: 4.0.0
+ Removed deprecated but equivalent ``PingAcknowledged``.
"""
def __init__(self):
#: The data included on the ping.
@@ -390,17 +395,6 @@ class PingAcknowledged(Event):
)
-class PingAckReceived(PingAcknowledged):
- """
- The PingAckReceived event is fired whenever a PING acknowledgment is
- received. It contains the 'opaque data' of the PING+ACK frame, allowing the
- user to correlate PINGs and calculate RTT.
-
- .. versionadded:: 3.1.0
- """
- pass
-
-
class StreamEnded(Event):
"""
The StreamEnded event is fired whenever a stream is ended by a remote
@@ -637,12 +631,4 @@ def _bytes_representation(data):
if data is None:
return None
- hex = binascii.hexlify(data)
-
- # This is moderately clever: on all Python versions hexlify returns a byte
- # string. On Python 3 we want an actual string, so we just check whether
- # that's what we have.
- if not isinstance(hex, str): # pragma: no cover
- hex = hex.decode('ascii')
-
- return hex
+ return binascii.hexlify(data).decode('ascii')
diff --git a/src/h2/frame_buffer.py b/src/h2/frame_buffer.py
index e79f6ec..a3d2293 100644
--- a/src/h2/frame_buffer.py
+++ b/src/h2/frame_buffer.py
@@ -26,7 +26,7 @@ from .exceptions import (
CONTINUATION_BACKLOG = 64
-class FrameBuffer(object):
+class FrameBuffer:
"""
This is a data structure that expects to act as a buffer for HTTP/2 data
that allows iteraton in terms of H2 frames.
@@ -130,7 +130,7 @@ class FrameBuffer(object):
def __iter__(self):
return self
- def next(self): # Python 2
+ def __next__(self):
# First, check that we have enough data to successfully parse the
# next frame header. If not, bail. Otherwise, parse it.
if len(self.data) < 9:
@@ -169,7 +169,4 @@ class FrameBuffer(object):
# frame in the sequence instead. Recurse back into ourselves to do
# that. This is safe because the amount of work we have to do here is
# strictly bounded by the length of the buffer.
- return f if f is not None else self.next()
-
- def __next__(self): # Python 3
- return self.next()
+ return f if f is not None else self.__next__()
diff --git a/src/h2/settings.py b/src/h2/settings.py
index bf87c94..e918ac5 100644
--- a/src/h2/settings.py
+++ b/src/h2/settings.py
@@ -8,6 +8,7 @@ API for manipulating HTTP/2 settings, keeping track of both the current active
state of the settings and the unacknowledged future values of the settings.
"""
import collections
+from collections.abc import MutableMapping
import enum
from hyperframe.frame import SettingsFrame
@@ -15,11 +16,6 @@ from hyperframe.frame import SettingsFrame
from h2.errors import ErrorCodes
from h2.exceptions import InvalidSettingsValueError
-try:
- from collections.abc import MutableMapping
-except ImportError: # pragma: no cover
- # Python 2.7 compatibility
- from collections import MutableMapping
class SettingCodes(enum.IntEnum):
diff --git a/src/h2/stream.py b/src/h2/stream.py
index af3d1cc..3c29b24 100644
--- a/src/h2/stream.py
+++ b/src/h2/stream.py
@@ -80,7 +80,7 @@ STREAM_OPEN[StreamState.HALF_CLOSED_LOCAL] = True
STREAM_OPEN[StreamState.HALF_CLOSED_REMOTE] = True
-class H2StreamStateMachine(object):
+class H2StreamStateMachine:
"""
A single HTTP/2 stream state machine.
@@ -736,7 +736,7 @@ _transitions = {
}
-class H2Stream(object):
+class H2Stream:
"""
A low-level HTTP/2 stream object. This handles building and receiving
frames and maintains per-stream state.
diff --git a/src/h2/utilities.py b/src/h2/utilities.py
index 06c916e..16d17de 100644
--- a/src/h2/utilities.py
+++ b/src/h2/utilities.py
@@ -61,10 +61,7 @@ _RESPONSE_ONLY_HEADERS = frozenset([b':status', u':status'])
_CONNECT_REQUEST_ONLY_HEADERS = frozenset([b':protocol', u':protocol'])
-if sys.version_info[0] == 2: # Python 2.X
- _WHITESPACE = frozenset(whitespace)
-else: # Python 3.3+
- _WHITESPACE = frozenset(map(ord, whitespace))
+_WHITESPACE = frozenset(map(ord, whitespace))
def _secure_headers(headers, hdr_validation_flags):
diff --git a/src/h2/windows.py b/src/h2/windows.py
index 6656975..be4eb43 100644
--- a/src/h2/windows.py
+++ b/src/h2/windows.py
@@ -21,7 +21,7 @@ from .exceptions import FlowControlError
LARGEST_FLOW_CONTROL_WINDOW = 2**31 - 1
-class WindowManager(object):
+class WindowManager:
"""
A basic HTTP/2 window manager.