mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
Make test_socket work.
Don't exclude test_socket from the tests to run.
This commit is contained in:
parent
7cad4f3d02
commit
2bf7138bb7
2 changed files with 14 additions and 8 deletions
20
Lib/io.py
20
Lib/io.py
|
@ -300,17 +300,23 @@ class IOBase:
|
|||
|
||||
def readline(self, limit: int = -1) -> bytes:
|
||||
"""For backwards compatibility, a (slowish) readline()."""
|
||||
if hasattr(self, "peek"):
|
||||
def nreadahead():
|
||||
readahead = self.peek(1, unsafe=True)
|
||||
if not readahead:
|
||||
return 1
|
||||
n = (readahead.find(b"\n") + 1) or len(readahead)
|
||||
if limit >= 0:
|
||||
n = min(n, limit)
|
||||
return n
|
||||
else:
|
||||
def nreadahead():
|
||||
return 1
|
||||
if limit is None:
|
||||
limit = -1
|
||||
res = bytes()
|
||||
while limit < 0 or len(res) < limit:
|
||||
readahead = self.peek(1, unsafe=True)
|
||||
if not readahead:
|
||||
break
|
||||
n = (readahead.find(b"\n") + 1) or len(readahead)
|
||||
if limit >= 0:
|
||||
n = min(n, limit)
|
||||
b = self.read(n)
|
||||
b = self.read(nreadahead())
|
||||
if not b:
|
||||
break
|
||||
res += b
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue