Skip to content

Commit

Permalink
Refactor telnetlib list->relist
Browse files Browse the repository at this point in the history
  • Loading branch information
egroeper authored and knipknap committed Mar 12, 2017
1 parent 43d5db3 commit 2607214
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Exscript/protocols/telnetlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,17 @@ def _wait_for_data(self, timeout):
if time.time() > end:
return False

def _waitfor(self, list, timeout=None, flush=False, cleanup=None):
def _waitfor(self, relist, timeout=None, flush=False, cleanup=None):
re = None
list = list[:]
indices = range(len(list))
relist = relist[:]
indices = range(len(relist))
search_window_size = 150
head_loockback_size = 10
for i in indices:
if not hasattr(list[i], "search"):
if not hasattr(relist[i], "search"):
if not re: import re
list[i] = re.compile(list[i])
self.msg("Expecting %s" % [l.pattern for l in list])
relist[i] = re.compile(relist[i])
self.msg("Expecting %s" % [l.pattern for l in relist])
incomplete_tail = ''
clean_sw_size = search_window_size
while True:
Expand All @@ -622,7 +622,7 @@ def _waitfor(self, list, timeout=None, flush=False, cleanup=None):
self.cookedq.seek(qlen - search_window_size)
search_window = self.cookedq.read()
for i in indices:
m = list[i].search(search_window)
m = relist[i].search(search_window)
if m is not None:
e = m.end() - m.start()
e = qlen - e + 1
Expand Down Expand Up @@ -652,7 +652,7 @@ def _waitfor(self, list, timeout=None, flush=False, cleanup=None):
raise EOFError
return -1, None, text

def waitfor(self, list, timeout=None, cleanup=None):
def waitfor(self, relist, timeout=None, cleanup=None):
"""Read until one from a list of a regular expressions matches.
The first argument is a list of regular expressions, either
Expand All @@ -673,14 +673,14 @@ def waitfor(self, list, timeout=None, cleanup=None):
or if more than one expression can match the same input, the
results are undeterministic, and may depend on the I/O timing.
"""
return self._waitfor(list, timeout, False, cleanup)
return self._waitfor(relist, timeout, False, cleanup)

def expect(self, list, timeout=None, cleanup=None):
def expect(self, relist, timeout=None, cleanup=None):
"""
Like waitfor(), but removes the matched data from the incoming
buffer.
"""
return self._waitfor(list, timeout, True, cleanup = cleanup)
return self._waitfor(relist, timeout, True, cleanup = cleanup)


def test():
Expand Down

0 comments on commit 2607214

Please sign in to comment.