Mercurial > genshi > mirror
diff genshi/template/base.py @ 947:0f9fe59dfa00 trunk
Add .copy() function to Context objects. Fixes #249.
author | hodgestar |
---|---|
date | Fri, 02 Sep 2011 20:20:21 +0000 |
parents | 59463031d904 |
children | 6fc92535c888 5dccab13ec85 |
line wrap: on
line diff
--- a/genshi/template/base.py +++ b/genshi/template/base.py @@ -247,6 +247,18 @@ def pop(self): """Pop the top-most scope from the stack.""" + def copy(self): + """Create a copy of this Context object.""" + # required to make f_locals a dict-like object + # See http://genshi.edgewall.org/ticket/249 for + # example use case in Twisted tracebacks + ctxt = Context() + ctxt.frames.pop() # pop empty dummy context + ctxt.frames.extend(self.frames) + ctxt._match_templates.extend(self._match_templates) + ctxt._choice_stack.extend(self._choice_stack) + return ctxt + def _apply_directives(stream, directives, ctxt, vars): """Apply the given directives to the stream.