# HG changeset patch # User cmlenz # Date 1149453479 0 # Node ID 87238328a71d18a339cceaa6cb9a09c8ff80432c # Parent d69d935e42994b88dfea727f7b8caad79c073f07 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