home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2344 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  2.2 KB  |  52 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. def apply_filters(stream, filters, lexer = None):
  6.     
  7.     def _apply(filter_, stream):
  8.         for token in filter_.filter(lexer, stream):
  9.             yield token
  10.         
  11.  
  12.     for filter_ in filters:
  13.         stream = _apply(filter_, stream)
  14.     
  15.     return stream
  16.  
  17.  
  18. def simplefilter(f):
  19.     return type(f.__name__, (FunctionFilter,), {
  20.         'function': f,
  21.         '__module__': getattr(f, '__module__'),
  22.         '__doc__': f.__doc__ })
  23.  
  24.  
  25. class Filter(object):
  26.     
  27.     def __init__(self, **options):
  28.         self.options = options
  29.  
  30.     
  31.     def filter(self, lexer, stream):
  32.         raise NotImplementedError()
  33.  
  34.  
  35.  
  36. class FunctionFilter(Filter):
  37.     function = None
  38.     
  39.     def __init__(self, **options):
  40.         if not hasattr(self, 'function'):
  41.             raise TypeError('%r used without bound function' % self.__class__.__name__)
  42.         hasattr(self, 'function')
  43.         Filter.__init__(self, **options)
  44.  
  45.     
  46.     def filter(self, lexer, stream):
  47.         for ttype, value in self.function(lexer, stream, self.options):
  48.             yield (ttype, value)
  49.         
  50.  
  51.  
  52.