Back to index

moin  1.9.0~rc2
Classes | Functions
MoinMoin.support.pygments.filter Namespace Reference

Classes

class  Filter
class  FunctionFilter

Functions

def apply_filters
def simplefilter

Function Documentation

def MoinMoin.support.pygments.filter.apply_filters (   stream,
  filters,
  lexer = None 
)
Use this method to apply an iterable of filters to
a stream. If lexer is given it's forwarded to the
filter, otherwise the filter receives `None`.

Definition at line 13 of file filter.py.

00013 
00014 def apply_filters(stream, filters, lexer=None):
00015     """
00016     Use this method to apply an iterable of filters to
00017     a stream. If lexer is given it's forwarded to the
00018     filter, otherwise the filter receives `None`.
00019     """
00020     def _apply(filter_, stream):
00021         for token in filter_.filter(lexer, stream):
00022             yield token
00023     for filter_ in filters:
00024         stream = _apply(filter_, stream)
00025     return stream
00026 

Decorator that converts a function into a filter::

    @simplefilter
    def lowercase(lexer, stream, options):
        for ttype, value in stream:
            yield ttype, value.lower()

Definition at line 27 of file filter.py.

00027 
00028 def simplefilter(f):
00029     """
00030     Decorator that converts a function into a filter::
00031 
00032         @simplefilter
00033         def lowercase(lexer, stream, options):
00034             for ttype, value in stream:
00035                 yield ttype, value.lower()
00036     """
00037     return type(f.__name__, (FunctionFilter,), {
00038                 'function':     f,
00039                 '__module__':   getattr(f, '__module__'),
00040                 '__doc__':      f.__doc__
00041             })
00042