Exemplo n.º 1
0
 def define_filter(self, name, filter, dynamic=False):
   """Adds a new FILTER definition to the local FILTER_CACHE."""
   if dynamic:
     filter = util.dynamic_filter(filter)
   for provider in self.__load_filters:
     try:
       provider.store(name, filter)
       return 1
     except Exception, e:
       self.throw(ERROR_FILTER, e)
Exemplo n.º 2
0
 def testFilter(self):
     dir = 'test/tmp'
     file = 'xyz'
     a, b, c, d = 'alpha', 'bravo', 'charlie', 'delta'
     params = {
         'a': a,
         'b': b,
         'c': c,
         'd': d,
         'list': [a, b, c, d],
         'text': 'The cat sat on the mat',
         'outfile': file,
         'stderr': lambda *_: sys.stderr.getvalue(),
     }
     filters = {
         'nonfilt': 'nonsense',
         'microjive': microjive,
         'microsloth': microsloth,
         'censor': censor_factory,
         'badfact': dynamic_filter(lambda *_: 'nonsense'),
         'badfilt': 'rubbish',
         'barfilt': barf_up
     }
     config1 = {'INTERPOLATE': 1, 'POST_CHOMP': 1, 'FILTERS': filters}
     config2 = {
         'EVAL_PYTHON': 1,
         'FILTERS': filters,
         'OUTPUT_PATH': dir,
         'BARVAL': 'some random value'
     }
     path = os.path.join(dir, file)
     if os.path.exists(path):
         os.remove(path)
     tt1 = Template(config1)
     tt2 = Template(config2)
     tt2.context().define_filter('another', another, True)
     self.Expect(DATA, (('default', tt1), ('evalpython', tt2)), params)
     self.assertTrue(os.path.exists(path))
     os.remove(path)
Exemplo n.º 3
0
 def testFilter(self):
   dir = 'test/tmp'
   file = 'xyz'
   a, b, c, d = 'alpha', 'bravo', 'charlie', 'delta'
   params = { 'a': a,
              'b': b,
              'c': c,
              'd': d,
              'list': [ a, b, c, d ],
              'text': 'The cat sat on the mat',
              'outfile': file,
              'stderr': lambda *_: sys.stderr.getvalue(),
              }
   filters = { 'nonfilt': 'nonsense',
               'microjive': microjive,
               'microsloth': microsloth,
               'censor': censor_factory,
               'badfact': dynamic_filter(lambda *_: 'nonsense'),
               'badfilt': 'rubbish',
               'barfilt': barf_up }
   config1 = { 'INTERPOLATE': 1,
               'POST_CHOMP': 1,
               'FILTERS': filters }
   config2 = { 'EVAL_PYTHON': 1,
               'FILTERS': filters,
               'OUTPUT_PATH': dir,
               'BARVAL': 'some random value' }
   path = os.path.join(dir, file)
   if os.path.exists(path):
     os.remove(path)
   tt1 = Template(config1)
   tt2 = Template(config2)
   tt2.context().define_filter('another', another, True)
   self.Expect(DATA, (('default', tt1), ('evalpython', tt2)), params)
   self.failUnless(os.path.exists(path))
   os.remove(path)