Logo Search packages:      
Sourcecode: kayali version File versions  Download package

def pexpect::spawn::compile_pattern_list (   self,
  patterns 
)

This compiles a pattern-string or a list of pattern-strings.
Patterns must be a StringType, EOF, TIMEOUT, SRE_Pattern, or 
a list of those.

This is used by expect() when calling expect_list().
Thus expect() is nothing more than::
     cpl = self.compile_pattern_list(pl)
     return self.expect_list(clp, timeout)

If you are using expect() within a loop it may be more
efficient to compile the patterns first and then call expect_list().
This avoid calls in a loop to compile_pattern_list():
     cpl = self.compile_pattern_list(my_pattern)
     while some_condition:
...
i = self.expect_list(clp, timeout)
...

Definition at line 588 of file pexpect.py.

00588                                             :
        """This compiles a pattern-string or a list of pattern-strings.
        Patterns must be a StringType, EOF, TIMEOUT, SRE_Pattern, or 
        a list of those.

        This is used by expect() when calling expect_list().
        Thus expect() is nothing more than::
             cpl = self.compile_pattern_list(pl)
             return self.expect_list(clp, timeout)

        If you are using expect() within a loop it may be more
        efficient to compile the patterns first and then call expect_list().
        This avoid calls in a loop to compile_pattern_list():
             cpl = self.compile_pattern_list(my_pattern)
             while some_condition:
                ...
                i = self.expect_list(clp, timeout)
                ...
        """
        if type(patterns) is not ListType:
            patterns = [patterns]

        compiled_pattern_list = []
        for p in patterns:
            if type(p) is StringType:
                compiled_pattern_list.append(re.compile(p, re.DOTALL))
            elif p is EOF:
                compiled_pattern_list.append(EOF)
            elif p is TIMEOUT:
                compiled_pattern_list.append(TIMEOUT)
            elif type(p) is type(re.compile('')):
                compiled_pattern_list.append(p)
            else:
                raise TypeError, 'Argument must be one of StringType, EOF, TIMEOUT, SRE_Pattern, or a list of those type. %s' % str(type(p))

        return compiled_pattern_list
 
    def expect(self, pattern, timeout = -1):


Generated by  Doxygen 1.6.0   Back to index