-
Notifications
You must be signed in to change notification settings - Fork 92
Broaden receive data buffer types #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,9 @@ def __init__(self) -> None: | |
| self._next_line_search = 0 | ||
| self._multiple_lines_search = 0 | ||
|
|
||
| def __iadd__(self, byteslike: Union[bytes, bytearray]) -> "ReceiveBuffer": | ||
| def __iadd__( | ||
| self, byteslike: Union[bytes, bytearray, memoryview] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| ) -> "ReceiveBuffer": | ||
| self._data += byteslike | ||
| return self | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,22 @@ def test_chunk_boundaries() -> None: | |
| assert conn.next_event() == EndOfMessage() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("data_wrapper", [bytearray, memoryview]) | ||
| def test_receive_data_accepts_byteslike_objects(data_wrapper: Any) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this parameter need to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. This is just statistically generated spam. This account is brand new and spamming tonnes of projects |
||
| conn = Connection(our_role=SERVER) | ||
|
|
||
| conn.receive_data( | ||
| data_wrapper(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n") | ||
| ) | ||
|
|
||
| assert conn.next_event() == Request( | ||
| method="GET", | ||
| target="/", | ||
| headers=[("Host", "example.com")], | ||
| ) | ||
| assert conn.next_event() == EndOfMessage() | ||
|
|
||
|
|
||
| def test_client_talking_to_http10_server() -> None: | ||
| c = Connection(CLIENT) | ||
| c.send(Request(method="GET", target="/", headers=[("Host", "example.com")])) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Allow ``Connection.receive_data()`` to accept ``bytearray`` and | ||
| ``memoryview`` inputs in its public type hints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use
collections.abc.Bufferfor Python >= 3.12, as introduced in PEP 688. Alternatively, you can useif typing.TYPE_CHECKING: from typing_extensions import Buffer, which avoids a runtime dependency on typing_extensions.