[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication - PublicationTraverse.py:1.1.2.2 Traversers.py:1.1.2.10

Martijn Pieters mj@zope.com
Wed, 13 Feb 2002 00:03:36 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication
In directory cvs.zope.org:/tmp/cvs-serv14206/App/ZopePublication

Modified Files:
      Tag: Zope-3x-branch
	PublicationTraverse.py Traversers.py 
Log Message:
Optimizations and code style updates:

  - Use isinstance on type checks

  - Test UnicodeType and StringType through StringTypes

  - Remove use of the string module

  - Use startswith and endswith instead of slices.

  - Fix weird tests where isinstance suffices.


=== Zope3/lib/python/Zope/App/ZopePublication/PublicationTraverse.py 1.1.2.1 => 1.1.2.2 ===
 from Zope.App.Security.SecurityManagement import getSecurityManager
 from Zope.Publisher.Exceptions import NotFound
-from types import StringType, UnicodeType
+from types import StringTypes
 from Zope.ContextWrapper import wrapper
 
 class DuplicateNamespaces(Exception):
@@ -153,7 +153,7 @@
 
     def traversePath(self, request, ob, path):
 
-        if type(path) in (StringType, UnicodeType):
+        if isinstance(path, StringTypes):
             path = path.split('/')
             if len(path) > 1 and not path[-1]:
                 # Remove trailing slash


=== Zope3/lib/python/Zope/App/ZopePublication/Traversers.py 1.1.2.9 => 1.1.2.10 ===
         # TODO:  Look for default view
         ob = self.target
-        if name[:1] == '_':
+        if name.startswith('_'):
             raise Unauthorized("Name %s begins with an underscore" % `name`)
-        if name[-5:]==';view':
+        if name.endswith(';view'):
             return getRequestView( ob, name[:-5], request)
         if hasattr(ob, name):
             subob = getattr(ob, name)