diff markup/filters.py @ 14:76b5d4b189e6

The `<py:match>` directive now protects itself against simple infinite recursion (see MatchDirective), while still allowing recursion in general.
author cmlenz
date Tue, 13 Jun 2006 17:56:42 +0000
parents bf9de5a4c896
children f083101b8e8a
line wrap: on
line diff
--- a/markup/filters.py
+++ b/markup/filters.py
@@ -22,8 +22,7 @@
 from markup.core import Attributes, Markup, Stream
 from markup.path import Path
 
-__all__ = ['EvalFilter', 'IncludeFilter', 'MatchFilter', 'WhitespaceFilter',
-           'HTMLSanitizer']
+__all__ = ['EvalFilter', 'IncludeFilter', 'WhitespaceFilter', 'HTMLSanitizer']
 
 
 class EvalFilter(object):
@@ -141,7 +140,7 @@
                         # If the included template defines any filters added at
                         # runtime (such as py:match templates), those need to be
                         # applied to the including template, too.
-                        filters = template.filters + template._included_filters
+                        filters = template._included_filters + template.filters
                         for filter_ in filters:
                             stream = filter_(stream, ctxt)
 
@@ -183,40 +182,6 @@
             yield event
 
 
-class MatchFilter(object):
-    """A filter that delegates to a given handler function when the input stream
-    matches some path expression.
-    """
-
-    def __init__(self, path, handler):
-        self.path = Path(path)
-        self.handler = handler
-
-    def __call__(self, stream, ctxt=None):
-        from markup.template import Template
-
-        test = self.path.test()
-        for kind, data, pos in stream:
-            result = test(kind, data, pos)
-            if result is True:
-                content = [(kind, data, pos)]
-                depth = 1
-                while depth > 0:
-                    ev = stream.next()
-                    if ev[0] is Stream.START:
-                        depth += 1
-                    elif ev[0] is Stream.END:
-                        depth -= 1
-                    content.append(ev)
-                    test(*ev)
-
-                yield (Template.SUB,
-                       ([lambda stream, ctxt: self.handler(content, ctxt)], []),
-                       pos)
-            else:
-                yield kind, data, pos
-
-
 class WhitespaceFilter(object):
     """A filter that removes extraneous white space from the stream.
 
Copyright (C) 2012-2017 Edgewall Software