[Zope3-checkins] CVS: Zope3/src/zope/tal - dummyengine.py:1.11.20.2

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Aug 20 12:24:47 EDT 2003


Update of /cvs-repository/Zope3/src/zope/tal
In directory cvs.zope.org:/tmp/cvs-serv3164

Modified Files:
      Tag: srichter-inlinepython-branch
	dummyengine.py 
Log Message:
Got some more tests working.


=== Zope3/src/zope/tal/dummyengine.py 1.11.20.1 => 1.11.20.2 ===
--- Zope3/src/zope/tal/dummyengine.py:1.11.20.1	Wed Aug 20 08:59:55 2003
+++ Zope3/src/zope/tal/dummyengine.py	Wed Aug 20 11:24:17 2003
@@ -45,6 +45,7 @@
         self.locals = self.globals = dict
         self.stack = [dict]
         self.translationService = DummyTranslationService()
+        self.useEngineAttrDicts = False
 
     def getCompilerError(self):
         return CompilerError
@@ -198,15 +199,45 @@
             msgid, domain, mapping, default=default)
 
     def evaluateCode(self, lang, code):
+        # We probably implement too much, but I use the dummy engine to test
+        # some of the issues that we will have.
+
+        # For testing purposes only
+        locals = {}
+        globals = {}
+        if self.useEngineAttrDicts:
+            globals = self.globals.copy()
+            locals = self.locals.copy()
+            
         assert lang == 'server-python'
         import sys, StringIO
+
+        # Removing probable comments
+        if code.strip().startswith('<!--') and code.strip().endswith('-->'):
+            code = code.strip()[4:-3]
+
+        # Prepare code.
+        lines = code.split('\n')
+        lines = filter(lambda l: l.strip() != '', lines)
+        code = '\n'.join(lines)
+        # This saves us from all indentation issues :)
+        if code.startswith(' ') or code.startswith('\t'):
+            code = 'if 1 == 1:\n' + code
         tmp = sys.stdout
         sys.stdout = StringIO.StringIO()
         try:
-            exec code in self.globals, self.locals
+            exec code in globals, locals
         finally:
             result = sys.stdout
             sys.stdout = tmp
+
+        # For testing purposes only
+        self.codeLocals = locals
+        self.codeGlobals = globals
+
+        self.locals.update(locals)
+        self.globals.update(globals)
+
         return result.getvalue()
 
 class Iterator:




More information about the Zope3-Checkins mailing list