Skip to content

Commit 345c0d3

Browse files
committed
add changelog, update tests
1 parent 46d91d5 commit 345c0d3

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ dev
1515
**API Changes (Backward Compatible)**
1616

1717
- Support for Python 3.14 has been added.
18+
- ``H2Connection.receive_data`` now accepts any byte-like object that
19+
implements the buffer protocol, such as ``bytes``, ``bytearray``, and
20+
``memoryview``. Existing ``bytes`` callers are unaffected.
1821
- Align CONNECT pseudo-header validation with RFC 9113 s8.3 and RFC 8441 s4.
1922
Ordinary CONNECT now requires ``:method=CONNECT`` and ``:authority``, and
2023
forbids ``:scheme``/``:path``. Extended CONNECT (e.g., WebSocket) requires

docs/source/basic-usage.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ socket, in a loop. We then passed that data to the connection object, which
311311
returned us a single event object:
312312
:class:`RemoteSettingsChanged <h2.events.RemoteSettingsChanged>`.
313313

314+
``receive_data`` accepts the ``bytes`` returned by ``recv`` as well as other
315+
byte-like objects that implement the buffer protocol, such as ``bytearray`` and
316+
``memoryview``.
317+
314318
But what we didn't see was anything else. So it seems like all ``curl`` did
315319
was change its settings, but nothing else. If you look at the other ``curl``
316320
window, you'll notice that it hangs for a while and then eventually fails with
@@ -750,4 +754,4 @@ it, there are a few directions you could investigate:
750754
.. _PyOpenSSL: http://pyopenssl.readthedocs.org/
751755
.. _Eventlet example: https://github.com/python-hyper/h2/blob/master/examples/eventlet/eventlet-server.py
752756
.. _curl: https://curl.se/docs/http2.html
753-
.. _httpx: https://www.python-httpx.org/
757+
.. _httpx: https://www.python-httpx.org/

tests/test_basic_logic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,22 @@ def test_ignores_preamble(self) -> None:
10031003
assert not events
10041004
assert not c.data_to_send()
10051005

1006+
@pytest.mark.parametrize("data_wrapper", [bytearray, memoryview])
1007+
def test_receive_data_accepts_buffer_types(
1008+
self,
1009+
data_wrapper,
1010+
frame_factory,
1011+
) -> None:
1012+
"""
1013+
``receive_data`` accepts byte-like buffers and handles their contents.
1014+
"""
1015+
c = h2.connection.H2Connection(config=self.server_config)
1016+
1017+
events = c.receive_data(data_wrapper(frame_factory.preamble()))
1018+
1019+
assert not events
1020+
assert not c.data_to_send()
1021+
10061022
@pytest.mark.parametrize("chunk_size", range(1, 24))
10071023
def test_drip_feed_preamble(self, chunk_size) -> None:
10081024
"""

tests/typing/strict_bytes.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
from __future__ import annotations
22

3+
from hyperframe.frame import Frame
4+
from typing_extensions import assert_type
5+
36
from h2.connection import H2Connection
7+
from h2.events import Event
48
from h2.frame_buffer import FrameBuffer
59

610

7-
def receive_data_accepts_buffer_types(
8-
connection: H2Connection,
9-
frame_buffer: FrameBuffer,
10-
) -> None:
11+
def receive_data_accepts_buffer_types() -> None:
12+
connection = H2Connection()
13+
frame_buffer = FrameBuffer()
1114
bytearray_data = bytearray(b"")
1215
memoryview_data = memoryview(b"")
1316

14-
connection.receive_data(bytearray_data)
15-
connection.receive_data(memoryview_data)
17+
bytearray_events = connection.receive_data(bytearray_data)
18+
memoryview_events = connection.receive_data(memoryview_data)
1619
frame_buffer.add_data(bytearray_data)
1720
frame_buffer.add_data(memoryview_data)
21+
buffered_frames = list(frame_buffer)
22+
23+
assert_type(bytearray_events, list[Event])
24+
assert_type(memoryview_events, list[Event])
25+
assert_type(buffered_frames, list[Frame])
26+
assert bytearray_events == []
27+
assert memoryview_events == []
28+
assert buffered_frames == []

0 commit comments

Comments
 (0)