Commit f7a15140 authored by Evan Simpson's avatar Evan Simpson

Add 'modules' TALES variable.

parent ae062a14
......@@ -87,9 +87,9 @@
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.HTMLTALParser import HTMLTALParser
from TAL.TALGenerator import TALGenerator
......@@ -127,6 +127,7 @@ class PageTemplate:
'options': {},
'nothing': None,
'request': None,
'modules': ModuleImporter,
}
parent = getattr(self, 'aq_parent', None)
if parent is not None:
......@@ -145,7 +146,8 @@ class PageTemplate:
output = StringIO()
c = self.pt_getContext()
c.update(extra_context)
#__traceback_info__ = c
if __debug__:
__traceback_info__ = pprint.pformat(c)
TALInterpreter(self._v_program, self._v_macros,
getEngine().getContext(c),
......@@ -218,3 +220,13 @@ class PageTemplate:
def html(self):
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 @@
Zope object encapsulating a Page Template.
"""
__version__='$Revision: 1.6 $'[11:-2]
__version__='$Revision: 1.7 $'[11:-2]
import os, AccessControl, Acquisition, sys
from Globals import DTMLFile, MessageDialog, package_home
......@@ -221,6 +221,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
'options': {},
'root': root,
'request': getattr(root, 'REQUEST', None),
'modules': SecureModuleImporter,
}
return c
......@@ -304,6 +305,16 @@ class Src(Acquisition.Explicit):
d = ZopePageTemplate.__dict__
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
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