[Zope3-checkins] CVS: Zope3/src/zope/publisher - http.py:1.34

Jim Fulton jim at zope.com
Fri Aug 8 15:08:13 EDT 2003


Update of /cvs-repository/Zope3/src/zope/publisher
In directory cvs.zope.org:/tmp/cvs-serv5702/src/zope/publisher

Modified Files:
	http.py 
Log Message:
Refactoried virtual host support.

Merged setApplicationNames into setVirtualHostRoot

Got rid of the _vh_trunc variable. Truncation now happens immediately, 
which simplifies the implementation.

Added the shiftNameToApplication method, which allows side-effect path
elements (e.g. ++skin++ZopeTop) to be moved into the "application"
part of the url, so that we son't have to keep track of them in
context wrappers.


=== Zope3/src/zope/publisher/http.py 1.33 => 1.34 ===
--- Zope3/src/zope/publisher/http.py:1.33	Fri Aug  8 09:10:10 2003
+++ Zope3/src/zope/publisher/http.py	Fri Aug  8 14:08:07 2003
@@ -282,8 +282,6 @@
         'method',         # The upper-cased request method (REQUEST_METHOD)
         '_locale',        # The locale for the request
         '_vh_root',       # Object at the root of the virtual host
-        '_vh_trunc',      # The number of path elements to be removed
-                          # from _traversed_names
         )
 
     retry_max_count = 3    # How many times we're willing to retry
@@ -311,7 +309,6 @@
         self.__setupCookies()
         self.__setupPath()
         self.__setupURLBase()
-        self._vh_trunc = 0
         self._vh_root = None
 
         self.response.setCharsetUsingRequest(self)
@@ -435,16 +432,11 @@
     def traverse(self, object):
         'See IPublisherRequest'
 
-        self._vh_trunc = 0
         ob = super(HTTPRequest, self).traverse(object)
         if self._path_suffix:
             self._traversal_stack = self._path_suffix
             ob = super(HTTPRequest, self).traverse(ob)
 
-        if self._vh_trunc:
-            del self._traversed_names[:self._vh_trunc]
-            self._vh_trunc = 0
-
         return ob
 
     # This method is not part of the interface.
@@ -543,10 +535,12 @@
         names = [quote(name, safe='/+@') for name in names]
 
         if path_only:
-            if not names: return '/'
+            if not names:
+                return '/'
             return '/' + '/'.join(names)
         else:
-            if not names: return self._app_server
+            if not names:
+                return self._app_server
             return "%s/%s" % (self._app_server, '/'.join(names))
 
     def getApplicationURL(self, depth=0, path_only=False):
@@ -572,12 +566,25 @@
             host = '%s:%s' % (host, port)
         self._app_server = '%s://%s' % (proto, host)
 
-    def setApplicationNames(self, names):
-        self._app_names = list(names)
+    def shiftNameToApplication(self):
+        """Add the name being traversed to the application name
+
+        This is only allowed in the case where the name is the first name.
+
+        A Value error is raise if the shift can't be performed.
+        """
 
-    def setVirtualHostRoot(self):
-        self._vh_trunc = len(self._traversed_names) + 1
+        if len(self._traversed_names) == 1:
+            self._app_names.append(self._traversed_names.pop())
+            return
+
+        raise ValueError("Can only shift leading traversal "
+                         "names to application names")
+
+    def setVirtualHostRoot(self, names=()):
+        del self._traversed_names[:]
         self._vh_root = self._last_obj_traversed
+        self._app_names = list(names)
 
     def getVirtualHostRoot(self):
         return self._vh_root




More information about the Zope3-Checkins mailing list