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

Nikolay Kim <[email protected]>
Newsgroups gmane.comp.web.zope.cvs
Message-ID <20110801062544.E1812740B4B__1055.06962067938$1312179954$gmane$org@cvs.zope.org>
Log message for revision 122433:
  micro optimization

Changed:
  U   Zope/branches/2.13/src/OFS/ObjectManager.py
  U   Zope/branches/2.13/src/OFS/Traversable.py
  U   Zope/branches/2.13/src/Products/PageTemplates/Expressions.py
  U   Zope/branches/2.13/src/ZPublisher/HTTPRequest.py

-=-
Modified: Zope/branches/2.13/src/OFS/ObjectManager.py
===================================================================
--- Zope/branches/2.13/src/OFS/ObjectManager.py	2011-07-30 11:49:07 UTC (rev 122432)
+++ Zope/branches/2.13/src/OFS/ObjectManager.py	2011-08-01 06:25:44 UTC (rev 122433)
@@ -425,7 +425,7 @@
         # Returns a list of actual subobjects of the current object.
         # If 'spec' is specified, returns only objects whose meta_type
         # match 'spec'.
-        return [ self._getOb(id) for id in self.objectIds(spec) ]
+        return [ getattr(self, id) for id in self.objectIds(spec) ]
 
     security.declareProtected(access_contents_information, 'objectItems')
     def objectItems(self, spec=None):
@@ -763,7 +763,7 @@
         return self.manage_delObjects(ids=[name])
 
     def __getitem__(self, key):
-        v=self._getOb(key, None)
+        v=getattr(self, key, None)
         if v is not None: return v
         if hasattr(self, 'REQUEST'):
             request=self.REQUEST

Modified: Zope/branches/2.13/src/OFS/Traversable.py
===================================================================
--- Zope/branches/2.13/src/OFS/Traversable.py	2011-07-30 11:49:07 UTC (rev 122432)
+++ Zope/branches/2.13/src/OFS/Traversable.py	2011-08-01 06:25:44 UTC (rev 122433)
@@ -153,17 +153,16 @@
             path = list(path)
 
         REQUEST = {'TraversalRequestNameStack': path}
-        #path.reverse()
         path_pop = path.pop
 
-        if len(path) > 1 and not path[-1]:
+        if not path[-1]:
             # Remove trailing slash
             path_pop()
 
         if restricted:
             validate = getSecurityManager().validate
 
-        if not path[0]:
+        if path and not path[0]:
             # If the path starts with an empty string, go to the root first.
             path_pop(0)
             obj = self.getPhysicalRoot()
@@ -189,7 +188,7 @@
                         obj = next
                         continue
 
-                bobo_traverse = None
+                bobo_traverse = getattr(obj, '__bobo_traverse__', None)
                 try:
                     if name and name[:1] in '@+' and name != '+' and nsParse(name)[1]:
                         # Process URI segment parameters.
@@ -208,7 +207,6 @@
                     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:

Modified: Zope/branches/2.13/src/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/branches/2.13/src/Products/PageTemplates/Expressions.py	2011-07-30 11:49:07 UTC (rev 122432)
+++ Zope/branches/2.13/src/Products/PageTemplates/Expressions.py	2011-08-01 06:25:44 UTC (rev 122433)
@@ -71,7 +71,7 @@
     while path_items:
         name = path_items.pop()
         if OFS.interfaces.ITraversable.providedBy(object):
-            object = object.restrictedTraverse(name)
+            object = object.unrestrictedTraverse(name, restricted=True)
         else:
             object = traversePathElement(object, name, path_items,
                                          request=request)

Modified: Zope/branches/2.13/src/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/2.13/src/ZPublisher/HTTPRequest.py	2011-07-30 11:49:07 UTC (rev 122432)
+++ Zope/branches/2.13/src/ZPublisher/HTTPRequest.py	2011-08-01 06:25:44 UTC (rev 122433)
@@ -169,6 +169,9 @@
 
     retry_max_count = 3
 
+    def __conform__(self, iface):
+        return iface.__adapt__(self)
+
     def supports_retry(self):
         if self.retry_count < self.retry_max_count:
             time.sleep(random.uniform(0, 2 ** (self.retry_count)))
@@ -254,11 +257,11 @@
 
     def physicalPathToURL(self, path, relative=0):
         """ Convert a physical path into a URL in the current context """
-        path = self._script + map(quote, self.physicalPathToVirtualPath(path))
+        path = self._script + [quote(s) for s in self.physicalPathToVirtualPath(path)]
         if relative:
             path.insert(0, '')
         else:
-            path.insert(0, self['SERVER_URL'])
+            path.insert(0, self.other['SERVER_URL'])
         return '/'.join(path)
 
     def physicalPathFromURL(self, URL):
@@ -338,7 +341,7 @@
         self.steps = []
         self._steps = []
         self._lazies = {}
-        self._debug = DebugFlags()
+        self.debug = DebugFlags()
         # We don't set up the locale initially but just on first access
         self._locale = _marker
 
@@ -450,6 +453,9 @@
         self.cookies = cookies
         self.taintedcookies = taintedcookies
 
+    def __nonzero__(self):
+        return True
+
     def processInputs(
         self,
         # "static" variables that we want to be local for speed
@@ -1251,7 +1257,7 @@
         categories. The search order is environment variables,
         other variables, form data, and then cookies.
 
-        """ #"
+        """
         other = self.other
         if key in other:
             return other[key]
@@ -1379,8 +1385,6 @@
                 if self._locale is _marker:
                     self.setupLocale()
                 return self._locale
-            if key == 'debug':
-                return self._debug
             raise AttributeError, key
         return v
 
@@ -1517,7 +1521,7 @@
                     base64.decodestring(auth.split()[-1]).split(':', 1)
                 return name, password
 
-    def taintWrapper(self, enabled=False):
+    def taintWrapper(self, enabled=TAINTING_ENABLED):
         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.