Back to index

plone3  3.1.7
retransform.py
Go to the documentation of this file.
00001 from Products.PortalTransforms.interfaces import itransform
00002 import re
00003 
00004 class retransform:
00005     """abstract class for regex transforms (re.sub wrapper)"""
00006     __implements__ = itransform
00007 
00008     inputs  = ('text/',)
00009 
00010     def __init__(self, name, *args):
00011         self.__name__ = name
00012         self.regexes = []
00013         for pat, repl in args:
00014             self.addRegex(pat, repl)
00015 
00016     def name(self):
00017         return self.__name__
00018 
00019     def addRegex(self, pat, repl):
00020         r = re.compile(pat)
00021         self.regexes.append((r, repl))
00022 
00023     def convert(self, orig, data, **kwargs):
00024         for r, repl in self.regexes:
00025             orig = r.sub(repl, orig)
00026         data.setData(orig)
00027         return data