[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - BaseRequest.py:1.46.28.1

Casey Duncan c.duncan@nlada.org
Mon, 11 Mar 2002 16:47:47 -0500


Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv13543

Modified Files:
      Tag: casey-death_to_index_html-branch
	BaseRequest.py 
Log Message:
Modified traversal so that browser_default is called for the last object
on the path allowing objects to override the default method name using
this it. This is also forward compatible with Zope 3.


=== Zope/lib/python/ZPublisher/BaseRequest.py 1.46 => 1.46.28.1 ===
         method=req_method=request_get('REQUEST_METHOD', 'GET').upper()
         
-        no_acquire_flag=0
-
-        # Set the default method
         if method=='GET' or method=='POST':
-            method='index_html'
+            # Probably a browser
+            no_acquire_flag=0
+            # index_html is still the default method, only any object can
+            # override it by implementing its own browser_default method
+            method = 'index_html'
+        elif self.maybe_webdav_client:
+            # Probably a WebDAV client.
+            no_acquire_flag=1
         else:
-            if self.maybe_webdav_client:
-                # Probably a WebDAV client.
-                no_acquire_flag=1
-        URL=request['URL']
-        
+            no_acquire_flag=0
+
+        URL=request['URL']        
         parents=request['PARENTS']
         object=parents[-1]
         del parents[:]
@@ -336,6 +338,22 @@
                 parents.append(object)
 
                 steps.append(entry_name)
+
+                # If we have reached the end of the path. We look to see
+                # if the object implements browser_default. If so, we
+                # call it to let the object tell us how to publish it
+                # browser_default returns the object to be published
+                # (usually self) and a sequence of names to traverse to
+                # find the method to be published. (Casey)
+                if not path and hasattr(getattr(object, 'aq_base', object),
+                                        'browser_default'):
+                    object, default_path = object.browser_default(request)
+                    if len(default_path) > 1:
+                        path = list(default_path)
+                        method = path.pop()
+                        request['TraversalRequestNameStack'] = path
+                    else:
+                        method = default_path[0]
         finally:
             parents.reverse()