The homepage of PySed is still under construction. I cut the comments
of sed.py module here to give you a hint about what it is.
Last updated 2005-03-30 00:30:33 CST
[Back to email@example.com]
Sed.py is a Python module that used for stream editing. Just like the
module name, it tries to provide ability like sed(a popular stream editor
for UNIX) does. However, it DOES NOT work as the same way as sed. When you
use Sed.py, you have to write Python script. Don't worry. It's piece of
cake. The hardest work is handled by Sed.py. All you need to do is to
specify the pattern to search and the file to process. A pattern is a
description of the string you want to handle. It is often described in
regular expression. However, if you just want to process some strings in
simple and fixed form, regular expression may not be necessary.
Before you go into the detail of Sed class, you should know about filter
first. Simply speaking, Filter is a list in Python form. it consists of
four items: patterns, replace strings, function and extra flags. The
function and extra flags item are optional.
The syntax looks like:
[ [patterns, replace] , ... ]
[ [patterns, replace , function] , ... ]
[ [patterns, replace , function , extraFlag] , ... ]
pattens is the string you want to handle in the content. It can be a string
in regexp format, a compiled regexp object or a mixed type of sequence that
contains string and compiled regexp object. The default filter will search
the content according to the patterns. If the patterns is a sequence, it
will be processed one by one.
replace is the string to substitute those string matched the pattern in
original content. It can be a single string or a dict. When it is a dict,
the pattern must be a regular expression(or a sequence of regular
expression) with named group specified. If the group is found and its name
is one of the key of dict, the value will replace the corresponding string.
Actually the meaning of replace field is defined by the filter function.
Here we are taking about is based on the FilterDefault function. If you
use other filter function, the meaning of replace parameter should refer
to the document of filter function.
function is used to specified what kind of filter you want to used. If this
field is omitted, FilterDefault will be appliedby default.
Before describe the behavior of FilterDefault, we will show you how to
implement your own filter function first.
A filter function has following prototype:
line, doNext = FILTER_FUNC(sedObj, line, patterns, replace, flags)
The sedObj is the instance of Sed class which is the caller of FILTER_FUNC.
The sedObj will pass the content to filter function line by line. So,
filter function will handle one line each time it has been called. The
return value of filter function is the modified line. The patterns and
replace arguments are represented the patterns and replace field in pattern
configuration list. However, you can define it with other meaning for these
two fields. Or, just follow the same definition of FilterDefault. The flags
is additional fields right after function field in pattern setting. It must
be a list for FILTER_FUNC. No default meaning for it. It depends on the
A filter function must return 2 value. The first value is the line which is
processed by this filter. The second value is a int flag to instruct the
ProcessStream function how to do with next filter. There are three accepted
DO_NEXT_FILTER -- Continue to next filter.
SKIP_NEXT_FILTER -- Skip next filter.
SKIP_ALL_OTHER_FILTERS -- Skip all other filters which did not execute yet.
"Gary W. Lee"
Apology to my poor English. If you find any erratum, incorrect grammar or
sentence which make no sence, please let me know. Suggestions are also