Commits

Mike Bayer  committed 6c06a32

- the keys() in the Context, as well as
it's internal _data dictionary, now
include just what was specified to
render() as well as Mako builtins
'caller', 'capture'. The contents
of __builtin__ are no longer copied.

  • Participants
  • Parent commits 4737c26

Comments (0)

Files changed (3)

   if the 'template' and 'module' attributes
   are specified at the same time.
 
+- the keys() in the Context, as well as 
+  it's internal _data dictionary, now
+  include just what was specified to 
+  render() as well as Mako builtins
+  'caller', 'capture'.  The contents
+  of __builtin__ are no longer copied.
+
 0.3.6
 - Documentation is on Sphinx.
   [ticket:126]

File mako/runtime.py

     def __init__(self, buffer, **data):
         self._buffer_stack = [buffer]
  
-        # original data, minus the builtins
-        self._orig = data
- 
-        # the context data which includes builtins
-        self._data = __builtin__.__dict__.copy()
-        self._data.update(data)
+        self._data = data
         self._kwargs = data.copy()
         self._with_template = None
         self._outputting_as_unicode = None
         return self._data.keys()
  
     def __getitem__(self, key):
-        return self._data[key]
+        if key in self._data:
+            return self._data[key]
+        else:
+            return __builtin__.__dict__[key]
 
     def _push_writer(self):
         """push a capturing buffer onto this Context and return
     def get(self, key, default=None):
         """Return a value from this :class:`.Context`."""
  
-        return self._data.get(key, default)
+        return self._data.get(key, 
+                __builtin__.__dict__.get(key, default)
+                )
  
     def write(self, string):
         """Write a string to this :class:`.Context` object's
         c = Context.__new__(Context)
         c._buffer_stack = self._buffer_stack
         c._data = self._data.copy()
-        c._orig = self._orig
         c._kwargs = self._kwargs
         c._with_template = self._with_template
         c._outputting_as_unicode = self._outputting_as_unicode
     (callable_, ctx) = _populate_self_namespace(
                                 context._clean_inheritance_tokens(), 
                                 template)
-    callable_(ctx, **_kwargs_for_include(callable_, context._orig, **kwargs))
+    callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
  
 def _inherit_from(context, uri, calling_uri):
     """called by the _inherit method in template modules to set

File test/test_template.py

 from mako.template import Template, ModuleTemplate
 from mako.lookup import TemplateLookup
 from mako.ext.preprocessors import convert_comments
-from mako import exceptions, util
-import re, os
+from mako import exceptions, util, runtime
+import re
+import os
 from util import flatten_result, result_lines
 import codecs
-from test import TemplateTest, eq_, template_base, module_base, skip_if, assert_raises
+from test import TemplateTest, eq_, template_base, module_base, \
+    skip_if, assert_raises
 
 class EncodingTest(TemplateTest):
     def test_unicode(self):
             template_args={'variable':'var', 'bar':'bar', 'foo':'foo'}
 
         )
- 
+
+    def test_context_small(self):
+        ctx = runtime.Context([].append, x=5, y=4)
+        eq_(sorted(ctx.keys()), ['caller', 'capture', 'x', 'y'])
+
     def test_with_context(self):
         template = Template("""
             <%page args="x, y, z=7"/>