# HG changeset patch # User cmlenz # Date 1149453479 0 # Node ID 97423376736e44e3a70a861439d843c43e1a084f # Parent 10c80c490c6e7f658c9b9ceaf1f7f9ea7a16e361 Make the XInclude filter track namespace context, to enable it to omit `END_NS` events for the XInclude namespace. diff --git a/markup/filters.py b/markup/filters.py --- a/markup/filters.py +++ b/markup/filters.py @@ -95,15 +95,17 @@ """ self.loader = loader - def __call__(self, stream, ctxt=None): + def __call__(self, stream, ctxt=None, ns_prefixes=None): """Filter the stream, processing any XInclude directives it may contain. @param ctxt: the template context @param stream: the markup event stream to filter """ - from markup.template import TemplateError, TemplateNotFound + from markup.template import Template, TemplateError, TemplateNotFound + if ns_prefixes is None: + ns_prefixes = [] in_fallback = False include_href, fallback_stream = None, None indent = 0 @@ -156,6 +158,11 @@ fallback_stream.append((kind, data, pos)) elif kind is Stream.START_NS and data[1] == self._NAMESPACE: + ns_prefixes.append(data[0]) + continue + + elif kind is Stream.END_NS and data in ns_prefixes: + ns_prefixes.pop() continue else: @@ -165,7 +172,7 @@ # process return - for event in self(stream, ctxt): + for event in self(stream, ctxt, ns_prefixes=ns_prefixes): yield event