summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-06-08 00:07:57 (GMT)
committerGuido van Rossum <guido@python.org>2007-06-08 00:07:57 (GMT)
commit2bf7138bb744cbb10f71ed5de2bb977c362a2052 (patch)
tree23c45ca069e984dd0017621772004c06986a10dc /Lib/io.py
parent7cad4f3d02861d143c0d5d71a93eab81972588e4 (diff)
downloadcpython-2bf7138bb744cbb10f71ed5de2bb977c362a2052.zip
cpython-2bf7138bb744cbb10f71ed5de2bb977c362a2052.tar.gz
cpython-2bf7138bb744cbb10f71ed5de2bb977c362a2052.tar.bz2
Make test_socket work.
Don't exclude test_socket from the tests to run.
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 4d46b47..4c9ddbb 100644
--- a/Lib/io.py
+++ b/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