Issue 822974: Telnet.read_until() timeout parameter misleading (original) (raw)

Telnet.read_until(str,timeout) documentation reads as follows: Read until a given string, expected, is encountered or until timeout seconds have passed.

When no match is found, return whatever is available instead, possibly the empty string. Raise EOFError if the connection is closed and no cooked data is available.

However, the method does not behave in this manner. The method will only return if the call to select() on the socket is blocked for longer than the specified timeout. If there is a steady stream of data available, and it does not contain the specified string, this method will NEVER return.

A possible solution would be to subtract the elapsed time from the given timeout each time through the while loop.

Here's a snippet of the code from telnetlib.py read_until():

    if timeout is not None:
        s_args = s_args + (timeout,)
    while not self.eof and apply(select.select,

s_args) == s_reply: i = max(0, len(self.cookedq)-n) self.fill_rawq() self.process_rawq() i = self.cookedq.find(match, i) if i >= 0: i = i+n buf = self.cookedq[:i] self.cookedq = self.cookedq[i:] return buf return self.read_very_lazy()