summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorBruce Merry <1963944+bmerry@users.noreply.github.com>2024-04-11 14:41:55 (GMT)
committerGitHub <noreply@github.com>2024-04-11 14:41:55 (GMT)
commit01a51f949475f1590eb5899f3002304060501ab2 (patch)
tree88528120d948fd0b392f0628a02ad57230f29f4f /Lib/asyncio
parent898f6de63fd5285006ee0f4993aeb8ed3e8f97f9 (diff)
downloadcpython-01a51f949475f1590eb5899f3002304060501ab2.zip
cpython-01a51f949475f1590eb5899f3002304060501ab2.tar.gz
cpython-01a51f949475f1590eb5899f3002304060501ab2.tar.bz2
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')
-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 4517ca2..64aac4c 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])