Commit f7a15140 authored by Evan Simpson's avatar Evan Simpson

Add 'modules' TALES variable.

parent ae062a14
...@@ -87,9 +87,9 @@ ...@@ -87,9 +87,9 @@
HTML- and XML-based template objects using TAL, TALES, and METAL. HTML- and XML-based template objects using TAL, TALES, and METAL.
""" """
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
import os, sys, traceback import os, sys, traceback, pprint
from TAL.TALParser import TALParser from TAL.TALParser import TALParser
from TAL.HTMLTALParser import HTMLTALParser from TAL.HTMLTALParser import HTMLTALParser
from TAL.TALGenerator import TALGenerator from TAL.TALGenerator import TALGenerator
...@@ -127,6 +127,7 @@ class PageTemplate: ...@@ -127,6 +127,7 @@ class PageTemplate:
'options': {}, 'options': {},
'nothing': None, 'nothing': None,
'request': None, 'request': None,
'modules': ModuleImporter,
} }
parent = getattr(self, 'aq_parent', None) parent = getattr(self, 'aq_parent', None)
if parent is not None: if parent is not None:
...@@ -145,7 +146,8 @@ class PageTemplate: ...@@ -145,7 +146,8 @@ class PageTemplate:
output = StringIO() output = StringIO()
c = self.pt_getContext() c = self.pt_getContext()
c.update(extra_context) c.update(extra_context)
#__traceback_info__ = c if __debug__:
__traceback_info__ = pprint.pformat(c)
TALInterpreter(self._v_program, self._v_macros, TALInterpreter(self._v_program, self._v_macros,
getEngine().getContext(c), getEngine().getContext(c),
...@@ -218,3 +220,13 @@ class PageTemplate: ...@@ -218,3 +220,13 @@ class PageTemplate:
def html(self): def html(self):
return self.content_type == 'text/html' return self.content_type == 'text/html'
class _ModuleImporter:
def __getitem__(self, module):
mod = __import__(module)
path = split(module, '.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
ModuleImporter = _ModuleImporter()
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
Zope object encapsulating a Page Template. Zope object encapsulating a Page Template.
""" """
__version__='$Revision: 1.6 $'[11:-2] __version__='$Revision: 1.7 $'[11:-2]
import os, AccessControl, Acquisition, sys import os, AccessControl, Acquisition, sys
from Globals import DTMLFile, MessageDialog, package_home from Globals import DTMLFile, MessageDialog, package_home
...@@ -221,6 +221,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -221,6 +221,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
'options': {}, 'options': {},
'root': root, 'root': root,
'request': getattr(root, 'REQUEST', None), 'request': getattr(root, 'REQUEST', None),
'modules': SecureModuleImporter,
} }
return c return c
...@@ -304,6 +305,16 @@ class Src(Acquisition.Explicit): ...@@ -304,6 +305,16 @@ class Src(Acquisition.Explicit):
d = ZopePageTemplate.__dict__ d = ZopePageTemplate.__dict__
d['source.xml'] = d['source.html'] = Src() d['source.xml'] = d['source.html'] = Src()
from Products.PythonScripts.Guarded import safebin
class _SecureModuleImporter:
__allow_access_to_unprotected_subobjects__ = 1
def __getitem__(self, module):
mod = safebin['__import__'](module)
path = split(module, '.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
SecureModuleImporter = _SecureModuleImporter()
# Product registration and Add support # Product registration and Add support
from urllib import quote from urllib import quote
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment