aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/streams.py
diff options
context:
space:
mode:
authorBruce Merry <1963944+bmerry@users.noreply.github.com>2024-04-11 16:41:55 +0200
committerGitHub <noreply@github.com>2024-04-11 07:41:55 -0700
commit01a51f949475f1590eb5899f3002304060501ab2 (patch)
tree88528120d948fd0b392f0628a02ad57230f29f4f /Lib/asyncio/streams.py
parent898f6de63fd5285006ee0f4993aeb8ed3e8f97f9 (diff)
downloadcpython-01a51f949475f1590eb5899f3002304060501ab2.tar.gz
cpython-01a51f949475f1590eb5899f3002304060501ab2.zip
gh-117722: Fix Stream.readuntil with non-bytes buffer objects (#117723)
gh-16429 introduced support for an iterable of separators in Stream.readuntil. Since bytes-like types are themselves iterable, this can introduce ambiguities in deciding whether the argument is an iterator of separators or a singleton separator. In gh-16429, only 'bytes' was considered a singleton, but this will break code that passes other buffer object types. Fix it by only supporting tuples rather than arbitrary iterables. Closes gh-117722.
Diffstat (limited to 'Lib/asyncio/streams.py')
-rw-r--r--Lib/asyncio/streams.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index 4517ca22d74..64aac4cc50d 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -591,17 +591,17 @@ class StreamReader:
LimitOverrunError exception will be raised, and the data
will be left in the internal buffer, so it can be read again.
- The ``separator`` may also be an iterable of separators. In this
+ The ``separator`` may also be a tuple of separators. In this
case the return value will be the shortest possible that has any
separator as the suffix. For the purposes of LimitOverrunError,
the shortest possible separator is considered to be the one that
matched.
"""
- if isinstance(separator, bytes):
- separator = [separator]
- else:
- # Makes sure shortest matches wins, and supports arbitrary iterables
+ if isinstance(separator, tuple):
+ # Makes sure shortest matches wins
separator = sorted(separator, key=len)
+ else:
+ separator = [separator]
if not separator:
raise ValueError('Separator should contain at least one element')
min_seplen = len(separator[0])