~mordred/boots/use-setuptools

« back to all changes in this revision

Viewing changes to boots/api/constructors.py

  • Committer: Max Goodman
  • Date: 2010-03-24 07:33:04 UTC
  • mfrom: (99.1.5 boots-apidoc)
  • Revision ID: chromakode@gmail.com-20100324073304-sesqy1c2m91ecynx
Merge documentation updates from Andreas, with a couple tweaks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
_constructors = {}
32
32
 
33
33
def register_constructor(name, constructor):
34
 
    """Allow the function constructor to be used from PipedSQL under name.  constructor is a
35
 
    function that takes any number of strings as arguments and returns a node."""
 
34
    """Allow the function constructor to be used from PipedSQL under name.
 
35
    Constructor is a function that takes any number of strings as arguments and
 
36
    returns a node."""
36
37
    if name in _constructors:
37
38
        raise KeyError(_('A constructor with name {0} already exists').format(name))
38
39
 
59
60
 
60
61
@register('csv_in')
61
62
def csv_input_file_node(path):
62
 
    """Constructs a node that reads from a csv file and then sends the word to its outputs."""
 
63
    """Constructs a node that reads from a csv file and then sends the word to
 
64
    its outputs."""
63
65
    input_file = open(path)
64
66
    
65
67
    def read_iterator():
78
80
 
79
81
@register('csv_out')
80
82
def csv_output_file_node(path):
81
 
    """Constructs a node that writes each object it is passed to a file and then sends the object to
82
 
    its outputs."""
 
83
    """Constructs a node that writes each object it is passed to a file and 
 
84
    then sends the object to its outputs."""
83
85
    class CSVOutput(object):
84
86
        def __init__(self):
85
87
            self.write_comma = False
112
114
 
113
115
@register('sub')
114
116
def substitute_node(pattern, replacement, column = None):
115
 
    """Constructs a node that replaces any text matching pattern with replacement as if by re.sub.
116
 
    column can be used to specify the name of the column to perform substitution against.  The default
117
 
    is to substitute against all columns."""
 
117
    """Constructs a node that replaces any text matching pattern with 
 
118
    replacement as if by re.sub. column can be used to specify the name of
 
119
    the column to perform substitution against. The default is to substitute
 
120
against all columns."""
118
121
 
119
122
    regexp = re.compile(pattern)
120
123
 
146
149
 
147
150
@register('filter')
148
151
def filter_node(pattern, column = None):
149
 
    """Constructs a node that allows text to pass through only if it matches pattern.  A row is
150
 
    allowed to pass through if at least one of its columns matches pattern.  column can be used to
151
 
    specify the name of the column to perform substitution against.  The default is to substitute
152
 
    against all columns."""
 
152
    """Constructs a node that allows text to pass through only if it matches
 
153
    pattern. A row is allowed to pass through if at least one of its columns
 
154
    matches pattern.  column can be used to specify the name of the column
 
155
    to perform substitution against. The default is to substitute against all
 
156
    columns."""
153
157
 
154
158
    regexp = re.compile(pattern)
155
159