# Path: flatland/out/generic.py
# def transform(tagname, attributes, contents, context, bind):
#     """Transform tag *attributes* in-place & return transformed *contents*"""
#     for fn in _transforms:
#         contents = fn(tagname, attributes, contents, context, bind)
#     return contents
# 
# class Context(object):
#     """A stacked key/value mapping."""
# 
#     def __init__(self):
#         self._frames = [dict(_default_context)]
# 
#     def push(self, **options):
#         # for this size dict & usage pattern, copying turns out to be cheaper
#         # than directing __getitem__ down through a stack of sparse frames.
#         self._frames.append(self._frames[-1].copy())
#         try:
#             self.update(**options)
#         except KeyError:
#             self.pop()
#             raise
# 
#     def pop(self):
#         if len(self._frames) == 1:
#             raise RuntimeError("Can not pop() the base context frame.")
#         self._frames.pop()
# 
#     def __getitem__(self, key):
#         return self._frames[-1][key]
# 
#     def __setitem__(self, key, value):
#         if key not in self:
#             raise KeyError("%r not permitted in this %s" % (
#                 key, self.__class__.__name__))
#         self._frames[-1][key] = value
# 
#     def __contains__(self, key):
#         return key in self._frames[-1]
# 
#     def update(self, *iterable, **kwargs):
#         if len(iterable):
#             if len(iterable) > 1:
#                 raise TypeError(
#                     "update expected at most 1 arguments, got %s" % (
#                     len(iterable)))
#             source = to_pairs(iterable[0])
#             for key, value in source:
#                 self[key] = value
#         for key, value in kwargs.iteritems():
#             self[key.decode('ascii')] = value
# 
#     def __repr__(self):
#         return "%s(%r)" % (self.__class__.__name__, self._frames[-1])


from collections import deque
from genshi.core import Namespace, QName, END, START, TEXT
from genshi.template.base import (
    DirectiveFactory,
    EXPR,
    SUB,
    TemplateSyntaxError,
    _eval_expr,
    )
from genshi.template.eval import Expression
from genshi.template.directives import Directive
from genshi.template.interpolation import interpolate
from flatland.out.generic import transform, Context

    def process(self, stream, directives, ctxt, vars):
        try:
            render_context = ctxt['flatland_render_context']
        except KeyError:
            ctxt['flatland_render_context'] = render_context = Context()

        if 'filters' not in self.attributes:
            attrs = self.attributes
        else:
            attrs = self.attributes.copy()
            attrs['filters'] = _eval_expr(Expression(attrs['filters']),
                                          ctxt, vars)

        render_context.push()
        render_context.update(attrs)
        assert not directives
        for event in stream:
            yield event
        render_context.pop()


class Set(RenderContextManipulator):
    _name = 'set'
    __slots__ = ()

    def process(self, stream, directives, ctxt, vars):
        try:
            render_context = ctxt['flatland_render_context']
        except KeyError:

# Path: flatland/out/generic.py
# def transform(tagname, attributes, contents, context, bind):
#     """Transform tag *attributes* in-place & return transformed *contents*"""
#     for fn in _transforms:
#         contents = fn(tagname, attributes, contents, context, bind)
#     return contents
# 
# class Context(object):
#     """A stacked key/value mapping."""
# 
#     def __init__(self):
#         self._frames = [dict(_default_context)]
# 
#     def push(self, **options):
#         # for this size dict & usage pattern, copying turns out to be cheaper
#         # than directing __getitem__ down through a stack of sparse frames.
#         self._frames.append(self._frames[-1].copy())
#         try:
#             self.update(**options)
#         except KeyError:
#             self.pop()
#             raise
# 
#     def pop(self):
#         if len(self._frames) == 1:
#             raise RuntimeError("Can not pop() the base context frame.")
#         self._frames.pop()
# 
#     def __getitem__(self, key):
#         return self._frames[-1][key]
# 
#     def __setitem__(self, key, value):
#         if key not in self:
#             raise KeyError("%r not permitted in this %s" % (
#                 key, self.__class__.__name__))
#         self._frames[-1][key] = value
# 
#     def __contains__(self, key):
#         return key in self._frames[-1]
# 
#     def update(self, *iterable, **kwargs):
#         if len(iterable):
#             if len(iterable) > 1:
#                 raise TypeError(
#                     "update expected at most 1 arguments, got %s" % (
#                     len(iterable)))
#             source = to_pairs(iterable[0])
#             for key, value in source:
#                 self[key] = value
#         for key, value in kwargs.iteritems():
#             self[key.decode('ascii')] = value
# 
#     def __repr__(self):
#         return "%s(%r)" % (self.__class__.__name__, self._frames[-1])


# Path: flatland/out/genshi_06.py
from collections import deque
from genshi.core import Namespace, QName, END, START, TEXT
from genshi.template.base import (
    DirectiveFactory,
    EXPR,
    SUB,
    TemplateSyntaxError,
    _eval_expr,
    )
from genshi.template.eval import Expression
from genshi.template.directives import Directive
from genshi.template.interpolation import interpolate
from flatland.out.generic import transform, Context


    def process(self, stream, directives, ctxt, vars):
        try:
            render_context = ctxt['flatland_render_context']
        except KeyError:
            ctxt['flatland_render_context'] = render_context = Context()

        if 'filters' not in self.attributes:
            attrs = self.attributes
        else:
            attrs = self.attributes.copy()
            attrs['filters'] = _eval_expr(Expression(attrs['filters']),
                                          ctxt, vars)

        render_context.push()
        render_context.update(attrs)
        assert not directives
        for event in stream:
            yield event
        render_context.pop()


class Set(RenderContextManipulator):
    _name = 'set'
    __slots__ = ()

    def process(self, stream, directives, ctxt, vars):
        try:
            render_context = ctxt['flatland_render_context']
        except KeyError:

            ctxt['flatland_render_context'] = render_context = Context()