[Zope3-checkins] SVN: Zope3/trunk/src/zope/tales/expressions.py - remove crufty use of the types module

Fred L. Drake, Jr. fred at zope.com
Tue Jul 20 14:46:52 EDT 2004


Log message for revision 26637:
  - remove crufty use of the types module
  - re-factor the module importer for path:modules/
  


Changed:
  U   Zope3/trunk/src/zope/tales/expressions.py


-=-
Modified: Zope3/trunk/src/zope/tales/expressions.py
===================================================================
--- Zope3/trunk/src/zope/tales/expressions.py	2004-07-20 15:55:30 UTC (rev 26636)
+++ Zope3/trunk/src/zope/tales/expressions.py	2004-07-20 18:46:27 UTC (rev 26637)
@@ -16,7 +16,6 @@
 $Id$
 """
 import re
-from types import StringTypes, TupleType
 
 from zope.interface import implements
 from zope.tales.tales import CompilerError
@@ -91,7 +90,7 @@
             # check for initial function
             raise CompilerError(
                 'Namespace function specified in first subpath element')
-        elif isinstance(first,StringTypes):
+        elif isinstance(first, basestring):
             # check for initial ?
             raise CompilerError(
                 'Dynamic name specified in first subpath element')
@@ -117,13 +116,13 @@
             ob = ob()
 
         for element in compiled_path:
-            if isinstance(element,TupleType):
+            if isinstance(element, tuple):
                 ob = self._traverser(ob, element, econtext)
-            elif isinstance(element,StringTypes):
+            elif isinstance(element, basestring):
                 val = vars[element]
                 # If the value isn't a string, assume it's a sequence
                 # of path names.
-                if isinstance(val,StringTypes):
+                if isinstance(val, basestring):
                     val = (val,)
                 ob = self._traverser(ob, val, econtext)
             elif callable(element):
@@ -298,8 +297,12 @@
     """Minimal module importer with no security."""
 
     def __getitem__(self, module):
-        mod = __import__(module)
+        mod = self._get_toplevel_module(module)
         path = module.split('.')
         for name in path[1:]:
             mod = getattr(mod, name)
         return mod
+
+    def _get_toplevel_module(self, module):
+        # This can be overridden to add security proxies.
+        return __import__(module)



More information about the Zope3-Checkins mailing list