Skip to content
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

Fix Stream.readuntil with non-bytes buffer objects #117653

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/asyncio/streams.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
'StreamReader', 'StreamWriter', 'StreamReaderProtocol',
'open_connection', 'start_server')

import collections
import collections.abc
import socket
import sys
import warnings
@@ -597,7 +597,7 @@ async def readuntil(self, separator=b'\n'):
the shortest possible separator is considered to be the one that
matched.
"""
if isinstance(separator, bytes):
if isinstance(separator, collections.abc.Buffer):
separator = [separator]
else:
# Makes sure shortest matches wins, and supports arbitrary iterables
7 changes: 7 additions & 0 deletions Lib/test/test_asyncio/test_streams.py
Original file line number Diff line number Diff line change
@@ -512,6 +512,13 @@ def test_readuntil_multi_separator_negative_offset(self):
self.assertEqual(b'dataZA', data)
self.assertEqual(b'aaa', stream._buffer)

def test_readuntil_bytearray(self):
stream = asyncio.StreamReader(loop=self.loop)
stream.feed_data(b'some data\r\n')
data = self.loop.run_until_complete(stream.readuntil(bytearray(b'\r\n')))
self.assertEqual(b'some data\r\n', data)
self.assertEqual(b'', stream._buffer)

def test_readexactly_zero_or_less(self):
# Read exact number of bytes (zero or less).
stream = asyncio.StreamReader(loop=self.loop)