diff options
author | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2003-02-25 21:59:59 +0000 |
---|---|---|
committer | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2003-02-25 21:59:59 +0000 |
commit | 47b713566d16fef5510799daff546299a2d9f166 (patch) | |
tree | fb6a6e983979f7b8b537425334eb02c80daa19d6 | |
parent | 300479e6c75c7697fcd29e5c23e0395ede8a4a9d (diff) | |
download | pexpect-47b713566d16fef5510799daff546299a2d9f166.tar.gz |
Fixed some bugs with timeout default values in the expect methods.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@155 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r-- | pexpect/pexpect.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py index ae5ab0b..9f4ff40 100644 --- a/pexpect/pexpect.py +++ b/pexpect/pexpect.py @@ -485,7 +485,7 @@ class spawn: return compiled_pattern_list - def expect(self, pattern, timeout = None): + def expect(self, pattern, timeout = -1): """This seeks through the stream until an expected pattern is matched. The pattern is overloaded and may take several types including a list. The pattern can be a StringType, EOF, a compiled re, or @@ -493,7 +493,8 @@ class spawn: This returns the index into the pattern list. If the pattern was not a list this returns index 0 on a successful match. This may raise exceptions for EOF or TIMEOUT. - To avoid the EOF exception add EOF to the pattern list. + To avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to + the pattern list. After a match is found the instance attributes 'before', 'after' and 'match' will be set. @@ -503,6 +504,8 @@ class spawn: If an error occured then 'before' will be set to all the data read so far and 'after' and 'match' will be None. + If timeout is -1 then timeout will be set to the self.timeout value. + Note: A list entry may be EOF or TIMEOUT instead of a string. This will catch these exceptions and return the index of the list entry instead of raising the exception. @@ -547,10 +550,13 @@ class spawn: regular expression characters that you want to match. You may also pass just a string without a list and the single string will be converted to a list. + If timeout is -1 then timeout will be set to the self.timeout value. """ ### This is dumb. It shares most of the code with expect_list. ### The only different is the comparison method and that ### self.match is always None after calling this. + if timeout == -1: + timeout = self.timeout if type(pattern_list) is StringType: pattern_list = [pattern_list] @@ -597,9 +603,10 @@ class spawn: """This is called by expect(). This takes a list of compiled regular expressions. This returns the index into the pattern_list that matched the child's output. + If timeout is -1 then timeout will be set to the self.timeout value. """ - if timeout is None: + if timeout == -1: timeout = self.timeout try: |