[Zope-Checkins] SVN: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Z Avoid code duplication: Use SecureModuleImporter from ZRPythonExpr.py (made available

Philipp von Weitershausen philikon at philikon.de
Sun May 21 07:58:13 EDT 2006


Log message for revision 68207:
  Avoid code duplication: Use SecureModuleImporter from ZRPythonExpr.py (made available
  as an instance by Expressions.py). Minor style cleanup in ZRPythonExpr.py.
  

Changed:
  U   Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZRPythonExpr.py
  U   Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py

-=-
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZRPythonExpr.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZRPythonExpr.py	2006-05-21 11:56:43 UTC (rev 68206)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZRPythonExpr.py	2006-05-21 11:58:12 UTC (rev 68207)
@@ -43,7 +43,8 @@
         return eval(self._code, vars, {})
 
 class _SecureModuleImporter:
-    __allow_access_to_unprotected_subobjects__ = 1
+    __allow_access_to_unprotected_subobjects__ = True
+
     def __getitem__(self, module):
         mod = safe_builtins['__import__'](module)
         path = module.split('.')

Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py	2006-05-21 11:56:43 UTC (rev 68206)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py	2006-05-21 11:58:12 UTC (rev 68207)
@@ -39,6 +39,7 @@
 from zope.pagetemplate.pagetemplatefile import sniff_type
 
 from Products.PageTemplates.Expressions import getEngine
+from Products.PageTemplates.Expressions import SecureModuleImporter
 
 
 # regular expression to extract the encoding from the XML preamble
@@ -48,16 +49,6 @@
 if os.environ.has_key('ZPT_PREFERRED_ENCODING'):
     preferred_encodings.insert(0, os.environ['ZPT_PREFERRED_ENCODING'])
 
-class SecureModuleImporter:
-    __allow_access_to_unprotected_subobjects__ = 1
-    def __getitem__(self, module):
-        mod = safe_builtins['__import__'](module)
-        path = module.split('.')
-        for name in path[1:]:
-            mod = getattr(mod, name)
-        return mod
-
-
 class Src(Acquisition.Explicit):
     """ I am scary code """
 
@@ -259,7 +250,7 @@
              'options': {},
              'root': root,
              'request': getattr(root, 'REQUEST', None),
-             'modules': SecureModuleImporter(),
+             'modules': SecureModuleImporter,
              }
         return c
 



More information about the Zope-Checkins mailing list