[CMF-checkins] CVS: CMF/CMFCore - TextFilters.py:1.1.2.4

Tres Seaver tseaver@zope.com
Thu, 20 Dec 2001 11:20:14 -0500


Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv31540

Modified Files:
      Tag: tseaver-texthandler-branch
	TextFilters.py 
Log Message:
 - Add Pipeline, which chains together filters.

=== CMF/CMFCore/TextFilters.py 1.1.2.3 => 1.1.2.4 ===
     __call__ = filterText
 
+
+class Pipeline:
+    """
+        Composite filter, chaining a list of filters together.
+    """
+    __implements__ = TextFilter
+
+    _filters = ()
+
+    def filterText( self, text_info='' ):
+
+        next = _ensureTextInfo( text_info )
+
+        for filter in self._filters:
+            next = filter.filterText( next )
+
+        return next
+
+    __call__ = filterText
+
+    def addFilter( self, filter ):
+        """
+            Append 'filter' to the end of our chain;  'filter' must
+            implement TextFilter.
+        """
+        if not TextFilter.isImplementedBy( filter ):
+            raise ValueError, 'Not a filter.'
+
+        self._filters = self._filters + ( filter, )
+
+
 #
 #   Helper functions & classes
 #