summaryrefslogtreecommitdiffstats
path: root/Lib/telnetlib.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-07-03 13:01:35 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-07-03 13:01:35 (GMT)
commitede77f5373e38ce1befc02858dcbcff8214c061b (patch)
tree3ca2c1f73b5aa97fa51a93b846d3b9582c8218ca /Lib/telnetlib.py
parent4548239e2b171ea9fa175744f17a32a884ab514a (diff)
downloadcpython-ede77f5373e38ce1befc02858dcbcff8214c061b.zip
cpython-ede77f5373e38ce1befc02858dcbcff8214c061b.tar.gz
cpython-ede77f5373e38ce1befc02858dcbcff8214c061b.tar.bz2
Patch #825417: Fix timeout processing in expect,
read_until. Will backport to 2.4.
Diffstat (limited to 'Lib/telnetlib.py')
-rw-r--r--Lib/telnetlib.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py
index 3523037..a13e85c 100644
--- a/Lib/telnetlib.py
+++ b/Lib/telnetlib.py
@@ -311,6 +311,8 @@ class Telnet:
s_args = s_reply
if timeout is not None:
s_args = s_args + (timeout,)
+ from time import time
+ time_start = time()
while not self.eof and select.select(*s_args) == s_reply:
i = max(0, len(self.cookedq)-n)
self.fill_rawq()
@@ -321,6 +323,11 @@ class Telnet:
buf = self.cookedq[:i]
self.cookedq = self.cookedq[i:]
return buf
+ if timeout is not None:
+ elapsed = time() - time_start
+ if elapsed >= timeout:
+ break
+ s_args = s_reply + (timeout-elapsed,)
return self.read_very_lazy()
def read_all(self):
@@ -601,6 +608,9 @@ class Telnet:
if not hasattr(list[i], "search"):
if not re: import re
list[i] = re.compile(list[i])
+ if timeout is not None:
+ from time import time
+ time_start = time()
while 1:
self.process_rawq()
for i in indices:
@@ -613,7 +623,11 @@ class Telnet:
if self.eof:
break
if timeout is not None:
- r, w, x = select.select([self.fileno()], [], [], timeout)
+ elapsed = time() - time_start
+ if elapsed >= timeout:
+ break
+ s_args = ([self.fileno()], [], [], timeout-elapsed)
+ r, w, x = select.select(*s_args)
if not r:
break
self.fill_rawq()