[Checkins] SVN: five.pt/trunk/ Made Econtext class more robust.

Malthe Borch mborch at gmail.com
Sun Nov 16 07:34:15 EST 2008


Log message for revision 93009:
  Made Econtext class more robust.

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/src/five/pt/cmf.py

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2008-11-16 12:32:30 UTC (rev 93008)
+++ five.pt/trunk/CHANGES.txt	2008-11-16 12:34:15 UTC (rev 93009)
@@ -4,6 +4,8 @@
 HEAD
 ----
 
+- Made `EContext` class more robust. [malthe]
+
 - Register custom file-system page template class for use with CMF
   form controllers. [malthe]
 

Modified: five.pt/trunk/src/five/pt/cmf.py
===================================================================
--- five.pt/trunk/src/five/pt/cmf.py	2008-11-16 12:32:30 UTC (rev 93008)
+++ five.pt/trunk/src/five/pt/cmf.py	2008-11-16 12:34:15 UTC (rev 93009)
@@ -19,20 +19,30 @@
 _marker = object()
 
 class EContext(object):
-    vars = None
+    """This class emulates the `econtext` variable scope dictionary of
+    ZPT; it uses `sys._getframe` to acquire the variable and adds
+    required methods."""
     
-    def setLocal(self, name, value):
-        if self.vars is None:
+    _scope = None
+
+    @property
+    def vars(self):
+        if self._scope is None:
             frame = sys._getframe()
-            vars = _marker
-            while vars is _marker and frame is not None:
-                vars = frame.f_locals.get('_scope', _marker)
+            scope = _marker
+            while scope is _marker and frame is not None:
+                scope = frame.f_locals.get('_scope', _marker)
                 frame = frame.f_back
             if vars is _marker:
                 raise RuntimeError, 'Context not found'
-            self.vars = vars
+            self._scope = scope
+        return self._scope
+        
+    def setLocal(self, name, value):
         self.vars[name] = value
 
+    setGlobal = setLocal
+    
 class CMFTemplateFile(FiveTemplateFile):
     @property
     def utility_builtins(self):



More information about the Checkins mailing list