Index: genshi/template/eval.py
===================================================================
--- genshi/template/eval.py	(revision 803)
+++ genshi/template/eval.py	(working copy)
@@ -139,9 +139,8 @@
         :return: the result of the evaluation
         """
         __traceback_hide__ = 'before_and_this'
-        _globals = self._globals()
-        _globals['__data__'] = data
-        return eval(self.code, _globals, {'__data__': data})
+        _globals = self._globals(data)
+        return eval(self.code, _globals, data)
 
 
 class Suite(Code):
@@ -161,9 +160,7 @@
         :param data: a mapping containing the data to execute in
         """
         __traceback_hide__ = 'before_and_this'
-        _globals = self._globals()
-        _globals['__data__'] = data
-        exec self.code in _globals, data
+        exec self.code in self._globals(data), data
 
 
 UNDEFINED = object()
@@ -248,29 +245,31 @@
 class LookupBase(object):
     """Abstract base class for variable lookup implementations."""
 
-    def globals(cls):
+    def globals(cls, data):
         """Construct the globals dictionary to use as the execution context for
         the expression or suite.
         """
         return {
-            '_lookup_name': cls.lookup_name,
+            '_lookup_name': cls.lookup_name(data),
             '_lookup_attr': cls.lookup_attr,
             '_lookup_item': cls.lookup_item,
             'UndefinedError': UndefinedError
         }
     globals = classmethod(globals)
 
-    def lookup_name(cls, data, name):
-        __traceback_hide__ = True
-        val = data.get(name, UNDEFINED)
-        if val is UNDEFINED:
-            val = BUILTINS.get(name, val)
+    def lookup_name(cls, data):
+        def _lookup(name):
+            __traceback_hide__ = True
+            val = data.get(name, UNDEFINED)
             if val is UNDEFINED:
-                val = cls.undefined(name)
-        return val
+                val = BUILTINS.get(name, val)
+                if val is UNDEFINED:
+                    val = cls.undefined(name)
+            return val
+        return _lookup
     lookup_name = classmethod(lookup_name)
 
-    def lookup_attr(cls, data, obj, key):
+    def lookup_attr(cls, obj, key):
         __traceback_hide__ = True
         val = getattr(obj, key, UNDEFINED)
         if val is UNDEFINED:
@@ -281,7 +280,7 @@
         return val
     lookup_attr = classmethod(lookup_attr)
 
-    def lookup_item(cls, data, obj, key):
+    def lookup_item(cls, obj, key):
         __traceback_hide__ = True
         if len(key) == 1:
             key = key[0]
@@ -742,7 +741,7 @@
         # generator expression, leave it alone
         if node.name not in flatten(self.locals):
             # Otherwise, translate the name ref into a context lookup
-            func_args = [ast.Name('__data__'), ast.Const(node.name)]
+            func_args = [ast.Const(node.name)]
             node = ast.CallFunc(ast.Name('_lookup_name'), func_args)
         return node
 
@@ -754,12 +753,11 @@
 
     def visitGetattr(self, node):
         return ast.CallFunc(ast.Name('_lookup_attr'), [
-            ast.Name('__data__'), self.visit(node.expr),
-            ast.Const(node.attrname)
+            self.visit(node.expr), ast.Const(node.attrname)
         ])
 
     def visitSubscript(self, node):
         return ast.CallFunc(ast.Name('_lookup_item'), [
-            ast.Name('__data__'), self.visit(node.expr),
+            self.visit(node.expr),
             ast.Tuple([self.visit(sub) for sub in node.subs])
         ])
