[Checkins] SVN: five.pt/trunk/src/five/pt/ Chameleon now provides a compatible dynamic scope variable, so there's no need to emulate it here.
Malthe Borch
mborch at gmail.com
Tue Nov 18 19:55:23 EST 2008
Log message for revision 93111:
Chameleon now provides a compatible dynamic scope variable, so there's no need to emulate it here.
Changed:
U five.pt/trunk/src/five/pt/cmf.py
U five.pt/trunk/src/five/pt/pagetemplate.py
-=-
Modified: five.pt/trunk/src/five/pt/cmf.py
===================================================================
--- five.pt/trunk/src/five/pt/cmf.py 2008-11-19 00:55:13 UTC (rev 93110)
+++ five.pt/trunk/src/five/pt/cmf.py 2008-11-19 00:55:23 UTC (rev 93111)
@@ -13,7 +13,6 @@
from RestrictedPython import Utilities
from pagetemplate import BaseTemplateFile
-from pagetemplate import EContext
class FSPageTemplate(BaseTemplateFile, FSObject, Script):
meta_type = 'Filesystem Page Template'
@@ -23,6 +22,8 @@
_default_bindings = {'name_subpath': 'traverse_subpath'}
+ utility_builtins = Utilities.utility_builtins
+
def __init__(self, id, filepath, fullname=None, properties=None):
FSObject.__init__(self, id, filepath, fullname, properties)
self.ZBindings_edit(self._default_bindings)
@@ -37,15 +38,7 @@
def __call__(self, *args, **kwargs):
kwargs['args'] = args
- return BaseTemplateFile.__call__(self, self, **kwargs)
-
- @property
- def utility_builtins(self):
- builtins = dict(
- econtext=EContext())
- builtins.update(
- Utilities.utility_builtins)
- return builtins
+ return BaseTemplateFile.__call__(self, self, **kwargs)
class FSControllerPageTemplate(FSPageTemplate, FSControllerBase, BaseCPT):
def __init__(self, id, filepath, fullname=None, properties=None):
Modified: five.pt/trunk/src/five/pt/pagetemplate.py
===================================================================
--- five.pt/trunk/src/five/pt/pagetemplate.py 2008-11-19 00:55:13 UTC (rev 93110)
+++ five.pt/trunk/src/five/pt/pagetemplate.py 2008-11-19 00:55:23 UTC (rev 93111)
@@ -52,7 +52,13 @@
_expr_cache[key] = symbol_mapping, parts, source
# acquire template locals and update with symbol mapping
- _locals = EContext().locals
+ frame = sys._getframe()
+ while frame.f_locals.get('econtext', _marker) is _marker:
+ frame = frame.f_back
+ if frame is None:
+ raise RuntimeError, "Can't locate template frame."
+
+ _locals = frame.f_locals
_locals.update(symbol_mapping)
# execute code and return evaluation
@@ -65,39 +71,6 @@
def evaluate_exists(expr):
return evaluate_expression('exists', expr)
-class EContext(object):
- """This class emulates the `econtext` variable scope dictionary of
- ZPT; it uses `sys._getframe` to acquire the variable and adds
- required methods."""
-
- _scope = None
- _locals = None
-
- @property
- def locals(self):
- self.vars; return self._locals
-
- @property
- def vars(self):
- if self._scope is None:
- frame = sys._getframe()
- scope = _marker
- while frame is not None:
- scope = frame.f_locals.get('_scope', _marker)
- if scope is not _marker:
- self._locals = frame.f_locals
- break
- frame = frame.f_back
- else:
- raise RuntimeError, "Can't locate variable scope."
- self._scope = scope
- return self._scope
-
- def setLocal(self, name, value):
- self.vars[name] = value
-
- setGlobal = setLocal
-
class BaseTemplateFile(pagetemplate.BaseTemplateFile):
"""Zope 2-compatible page template class."""
More information about the Checkins
mailing list