From 2bf7138bb744cbb10f71ed5de2bb977c362a2052 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 8 Jun 2007 00:07:57 +0000 Subject: [PATCH] Make test_socket work. Don't exclude test_socket from the tests to run. --- Lib/io.py | 20 +++++++++++++------- runtests.sh | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Lib/io.py b/Lib/io.py index 4d46b477a55..4c9ddbb87cc 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 diff --git a/runtests.sh b/runtests.sh index 5a03b0a3423..c90460e2fa5 100755 --- a/runtests.sh +++ b/runtests.sh @@ -27,7 +27,7 @@ mkdir -p OUT # Compute the list of tests to run. case $# in 0) - TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//' | grep -v test_socket)` + TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//')` ;; *) TESTS="$@"