SVN: Zope/branches/2.13/src/ micro optimizations

Nikolay Kim <[email protected]>
Newsgroups gmane.comp.web.zope.cvs
Message-ID <20110730023611.58397941EC__3356.55433959818$1311993384$gmane$org@cvs.zope.org>
Log message for revision 122429:
  micro optimizations

Changed:
  U   Zope/branches/2.13/src/OFS/PropertyManager.py
  U   Zope/branches/2.13/src/OFS/Traversable.py
  U   Zope/branches/2.13/src/ZPublisher/HTTPRequest.py

-=-
Modified: Zope/branches/2.13/src/OFS/PropertyManager.py
===================================================================
--- Zope/branches/2.13/src/OFS/PropertyManager.py	2011-07-29 19:11:59 UTC (rev 122428)
+++ Zope/branches/2.13/src/OFS/PropertyManager.py	2011-07-30 02:36:10 UTC (rev 122429)
@@ -144,8 +144,9 @@
         Returns the optional second argument or None if no such property is
         found.
         """
-        if self.hasProperty(id):
-            return getattr(self, id)
+        for p in self._properties:
+            if id==p['id']:
+                return getattr(self, id)
         return d
 
     security.declareProtected(access_contents_information, 'getPropertyType')

Modified: Zope/branches/2.13/src/OFS/Traversable.py
===================================================================
--- Zope/branches/2.13/src/OFS/Traversable.py	2011-07-29 19:11:59 UTC (rev 122428)
+++ Zope/branches/2.13/src/OFS/Traversable.py	2011-07-30 02:36:10 UTC (rev 122429)
@@ -39,6 +39,7 @@
 from zope.traversing.namespace import nsParse
 
 _marker = object()
+NullResource = None
 
 
 class Traversable:
@@ -142,30 +143,29 @@
         If true, then all of the objects along the path are validated with
         the security machinery. Usually invoked using restrictedTraverse().
         """
-        from webdav.NullResource import NullResource
         if not path:
             return self
 
-        if isinstance(path, str):
+        if type(path) is str:
             # Unicode paths are not allowed
             path = path.split('/')
         else:
             path = list(path)
 
         REQUEST = {'TraversalRequestNameStack': path}
-        path.reverse()
+        #path.reverse()
         path_pop = path.pop
 
-        if len(path) > 1 and not path[0]:
+        if len(path) > 1 and not path[-1]:
             # Remove trailing slash
-            path_pop(0)
+            path_pop()
 
         if restricted:
             validate = getSecurityManager().validate
 
-        if not path[-1]:
+        if not path[0]:
             # If the path starts with an empty string, go to the root first.
-            path_pop()
+            path_pop(0)
             obj = self.getPhysicalRoot()
             if restricted:
                 validate(None, None, None, obj) # may raise Unauthorized
@@ -174,8 +174,7 @@
 
         resource = _marker
         try:
-            while path:
-                name = path_pop()
+            for name in path:
                 __traceback_info__ = path, name
 
                 if name[0] == '_':
@@ -190,7 +189,7 @@
                         obj = next
                         continue
 
-                bobo_traverse = getattr(obj, '__bobo_traverse__', None)
+                bobo_traverse = None
                 try:
                     if name and name[:1] in '@+' and name != '+' and nsParse(name)[1]:
                         # Process URI segment parameters.
@@ -209,6 +208,7 @@
                     else:
                         next = UseTraversalDefault # indicator
                         try:
+                            bobo_traverse = getattr(obj, '__bobo_traverse__', None)
                             if bobo_traverse is not None:
                                 next = bobo_traverse(REQUEST, name)
                                 if restricted:
@@ -256,6 +256,10 @@
                                     # The item lookup may return a NullResource,
                                     # if this is the case we save it and return it
                                     # if all other lookups fail.
+                                    global NullResource
+                                    if NullResource is None:
+                                        from webdav.NullResource import NullResource
+
                                     if isinstance(next, NullResource):
                                         resource = next
                                         raise KeyError(name)

Modified: Zope/branches/2.13/src/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/2.13/src/ZPublisher/HTTPRequest.py	2011-07-29 19:11:59 UTC (rev 122428)
+++ Zope/branches/2.13/src/ZPublisher/HTTPRequest.py	2011-07-30 02:36:10 UTC (rev 122429)
@@ -332,7 +332,7 @@
         self.environ = environ
         get_env = environ.get
         self.response = response
-        other = self.other = {'RESPONSE': response}
+        other = self.other = {'REQUEST': self, 'RESPONSE': response}
         self.form = {}
         self.taintedform = {}
         self.steps = []
@@ -379,9 +379,8 @@
         while b and b[0] == '/':
             b = b[1:]
 
-        server_url = get_env('SERVER_URL',None)
-        if server_url is not None:
-            other['SERVER_URL'] = server_url = server_url.strip()
+        if 'SERVER_URL' in environ:
+            other['SERVER_URL'] = server_url = environ['SERVER_URL'].strip()
         else:
             if 'HTTPS' in environ and (
                 environ['HTTPS'] == "on" or environ['HTTPS'] == "ON"):
@@ -1255,8 +1254,6 @@
         """ #"
         other = self.other
         if key in other:
-            if key == 'REQUEST':
-                return self
             return other[key]
 
         if key[:1] == 'U':
@@ -1266,7 +1263,7 @@
                 path = self._script + self._steps
                 n = len(path) - int(n)
                 if n < 0:
-                    raise KeyError, key
+                    return default
                 if pathonly:
                     path = [''] + path[:n]
                 else:
@@ -1284,9 +1281,6 @@
                 return environ[key]
             return ''
 
-        if key == 'REQUEST':
-            return self
-
         if key[:1] == 'B':
             match = BASEmatch(key)
             if match is not None:
@@ -1296,7 +1290,7 @@
                 if n:
                     n = n - 1
                     if len(path) < n:
-                        raise KeyError, key
+                        return default
 
                     v = self._script + path[:n]
                 else:
@@ -1394,12 +1388,10 @@
         self._lazies[key] = callable
 
     def has_key(self, key, returnTaints=0):
-        try:
-            self.__getitem__(key, returnTaints=returnTaints)
-        except:
-            return 0
-        else:
-            return 1
+        v = self.get(key, _marker, returnTaints=returnTaints)
+        if v is _marker:
+            return False
+        return True
 
     def keys(self, returnTaints=0):
         keys = {}
@@ -1525,7 +1517,7 @@
                     base64.decodestring(auth.split()[-1]).split(':', 1)
                 return name, password
 
-    def taintWrapper(self, enabled=TAINTING_ENABLED):
+    def taintWrapper(self, enabled=False):
         return enabled and TaintRequestWrapper(self) or self
 
     def shiftNameToApplication(self):

_______________________________________________
Zope-Checkins maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-checkins
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.