scipy/weave/ast_tools.py
def match(pattern, data, vars=None):
    """match `data' to `pattern', with variable extraction.

    pattern
        Pattern to match against, possibly containing variables.

    data
        Data to be checked and against which variables are extracted.

    vars
        Dictionary of variables which have already been found.  If not
        provided, an empty dictionary is created.

    The `pattern' value may contain variables of the form ['varname'] which
    are allowed to match anything.  The value that is matched is returned as
    part of a dictionary which maps 'varname' to the matched value.  'varname'
    is not required to be a string object, but using strings makes patterns
    and the code which uses them more readable.

    This function returns two values: a boolean indicating whether a match
    was found and a dictionary mapping variable names to their associated
    values.

    From the Demo/Parser/example.py file
    """
    if vars is None:
        vars = {}
    if isinstance(pattern, list):       # 'variables' are ['varname']
        vars[pattern[0]] = data
        return 1, vars
    if not isinstance(pattern, tuple):
        return (pattern == data), vars
    if len(data) != len(pattern):
        return 0, vars
    for pattern, data in zip(pattern, data):
        same, vars = match(pattern, data, vars)
        if not same:
            break
    return same, vars
match `data' to `pattern', with variable extraction.

    pattern
        Pattern to match against, possibly containing variables.

    data
        Data to be checked and against which variables are extracted.

    vars
        Dictionary of variables which have already been found.  If not
        provided, an empty dictionary is created.

    The `pattern' value may contain variables of the form ['varname'] which
    are allowed to match anything.  The value that is matched is returned as
    part of a dictionary which maps 'varname' to the matched value.  'varname'
    is not required to be a string object, but using strings makes patterns
    and the code which uses them more readable.

    This function returns two values: a boolean indicating whether a match
    was found and a dictionary mapping variable names to their associated
    values.

    From the Demo/Parser/example.py file
    
match `data' to `pattern', with variable extraction.
pattern
Pattern to match against, possibly containing variables.

data
Data to be checked and against which variables are extracted.

vars
Dictionary of variables which have already been found.  If not
provided, an empty dictionary is created.

The `pattern' value may contain variables of the form ['varname'] which
are allowed to match anything.  The value that is matched is returned as
part of a dictionary which maps 'varname' to the matched value.  'varname'
is not required to be a string object, but using strings makes patterns
and the code which uses them more readable.

This function returns two values: a boolean indicating whether a match
was found and a dictionary mapping variable names to their associated
values.


match ` data ' to ` pattern ' with variable extraction . pattern Pattern to match against possibly containing variables . data Data to be checked and against which variables are extracted . vars Dictionary of variables which have already been found . If not provided an empty dictionary is created . The ` pattern ' value may contain variables of the form [ ' varname ' ] which are allowed to match anything . The value that is matched is returned as part of a dictionary which maps ' varname ' to the matched value . ' varname ' is not required to be a string object but using strings makes patterns and the code which uses them more readable . This function returns two values : a boolean indicating whether a match was found and a dictionary mapping variable names to their associated values .
def match(pattern, data, vars=None):
    if vars is None:
        vars = {}
    if isinstance(pattern, list):       
        vars[pattern[0]] = data
        return 1, vars
    if not isinstance(pattern, tuple):
        return (pattern == data), vars
    if len(data) != len(pattern):
        return 0, vars
    for pattern, data in zip(pattern, data):
        same, vars = match(pattern, data, vars)
        if not same:
            break
    return same, vars
def match ( pattern , data , vars = None ) : if vars is None : vars = { } if isinstance ( pattern , list ) : vars [ pattern [ 0 ] ] = data return 1 , vars if not isinstance ( pattern , tuple ) : return ( pattern == data ) , vars if len ( data ) != len ( pattern ) : return 0 , vars for pattern , data in zip ( pattern , data ) : same , vars = match ( pattern , data , vars ) if not same : break return same , vars
match `data' to `pattern', with variable extraction.
match ` data ' to ` pattern ' with variable extraction .
"""match `data' to `pattern', with variable extraction.

    pattern
        Pattern to match against, possibly containing variables.

    data
        Data to be checked and against which variables are extracted.

    vars
        Dictionary of variables which have already been found.  If not
        provided, an empty dictionary is created.

    The `pattern' value may contain variables of the form ['varname'] which
    are allowed to match anything.  The value that is matched is returned as
    part of a dictionary which maps 'varname' to the matched value.  'varname'
    is not required to be a string object, but using strings makes patterns
    and the code which uses them more readable.

    This function returns two values: a boolean indicating whether a match
    was found and a dictionary mapping variable names to their associated
    values.

    From the Demo/Parser/example.py file
    """ # 'variables' are ['varname']
pattern
data
vars