summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoractsofcreation <actsofcreation@656d521f-e311-0410-88e0-e7920216d269>2004-04-24 20:33:13 +0000
committeractsofcreation <actsofcreation@656d521f-e311-0410-88e0-e7920216d269>2004-04-24 20:33:13 +0000
commit831a8cb03d243098abce75b99b8f268a374b9aa1 (patch)
tree12bf8ae9f859e27e86eba45bcb7fcf73260dd8f1
parentf4b1bc0379ae00495113c14df7f819922291534a (diff)
downloadpexpect-831a8cb03d243098abce75b99b8f268a374b9aa1.tar.gz
Applied patch 876859, implementing maxsearchsize
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/branches/patch_876859@228 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/pexpect.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index c313f46..c83df56 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -130,7 +130,7 @@ class spawn:
self.maxread = 1 # Maximum to read at a time
### IMPLEMENT THIS FEATURE!!!
# anything before maxsearchsize point is preserved, but not searched.
- #self.maxsearchsize = 1000
+ self.maxsearchsize = 1000
# If command is an int type then it must represent an open file descriptor.
if type (command) == type(0):
@@ -291,6 +291,14 @@ class spawn:
"""
self.maxread = maxread
+ def setmaxsearchsize(self,maxsearchsize):
+ """This sets the maximum size to search. The last maxsearchsize
+ bytes read will be searched for the expect patterns. All
+ data will be available in the spawn.before variable,
+ but only the last maxsearchsize bytes will be searched."""
+ self.maxsearchsize = maxsearchsize
+
+
def read_nonblocking (self, size = 1, timeout = None):
"""
This reads at most size characters from the child application.
@@ -663,7 +671,11 @@ class spawn:
index = index + 1
if str_target is EOF or str_target is TIMEOUT:
continue # The Exception patterns are handled differently.
- match_index = incoming.find (str_target)
+ if(self.maxsearchsize != None):
+ searchbuffer = incoming[-self.maxsearchsize:]
+ else:
+ searchbuffer = incoming
+ match_index = searchbuffer.find (str_target)
if match_index >= 0:
self.before = incoming [ : match_index]
self.after = incoming [match_index : ]
@@ -725,7 +737,11 @@ class spawn:
index = index + 1
if cre is EOF or cre is TIMEOUT:
continue # The patterns for PexpectExceptions are handled differently.
- match = cre.search(incoming)
+ if(self.maxsearchsize != None):
+ searchbuffer = incoming[-self.maxsearchsize:]
+ else:
+ searchbuffer = incoming
+ match = cre.search(searchbuffer)
if match is not None:
self.before = incoming[ : match.start()]
self.after = incoming[match.start() : ]