[Zope3-checkins] CVS: Zope3/src/zope/app/pagetemplate - engine.py:1.18.14.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Aug 20 21:11:13 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/pagetemplate
In directory cvs.zope.org:/tmp/cvs-serv26608/pagetemplate

Modified Files:
      Tag: srichter-inlinepython-branch
	engine.py 
Log Message:
Hooked up the new TAL script support to Templated Pages. The support has to
be manually activated on a separate page (as requested by __gotcha).

Also, currently we only have support for the "text/server-python" type. 
Later we might want to add other languages too.

TO DO:

  - tests

  - documentation



=== Zope3/src/zope/app/pagetemplate/engine.py 1.18 => 1.18.14.1 ===
--- Zope3/src/zope/app/pagetemplate/engine.py:1.18	Tue Jul  1 13:30:59 2003
+++ Zope3/src/zope/app/pagetemplate/engine.py	Wed Aug 20 20:11:12 2003
@@ -37,6 +37,7 @@
 from zope.security.builtins import RestrictedBuiltins
 from zope.i18n.translate import Translator
 
+from zope.app import zapi
 from zope.app.traversing.adapters import Traverser
 
 
@@ -88,6 +89,21 @@
         translator = Translator(request.locale, domain, self.context)
         return translator.translate(msgid, mapping, default=default)
 
+    evaluateInlineCode = False
+
+    def evaluateCode(self, lang, code):
+        if not self.evaluateInlineCode:
+            raise 'InlineCodeError', 'Inline Code Evaluation is deactivated.'
+        service = zapi.getService(self.context, 'Interpreter')
+        interpreter = service.getInterpreter(lang)
+        globals = self.vars.copy()
+        result = interpreter.evaluateRawCode(code, globals)
+        # Add possibly new global variables.
+        old_names = self.vars.keys()
+        for name, value in globals.items():
+            if name not in old_names:
+                self.setGlobal(name, value)
+        return result
 
 class ZopeEngine(ExpressionEngine):
 




More information about the Zope3-Checkins mailing list