[Checkins] SVN: Sandbox/philikon/five.publication/trunk/five/publication/ Now that I've finally figured out what BASE and BASEPATH are supposed to do,

Philipp von Weitershausen philikon at philikon.de
Sun Aug 5 18:44:43 EDT 2007


Log message for revision 78612:
  Now that I've finally figured out what BASE and BASEPATH are supposed to do,
  fixed their implementation in five.publication and fleshed out the test case to
  support testing their behaviour.  All tests pass!
  

Changed:
  U   Sandbox/philikon/five.publication/trunk/five/publication/request.py
  U   Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py

-=-
Modified: Sandbox/philikon/five.publication/trunk/five/publication/request.py
===================================================================
--- Sandbox/philikon/five.publication/trunk/five/publication/request.py	2007-08-05 22:21:57 UTC (rev 78611)
+++ Sandbox/philikon/five.publication/trunk/five/publication/request.py	2007-08-05 22:44:43 UTC (rev 78612)
@@ -1,4 +1,5 @@
 import re
+from urllib import quote
 import zope.publisher.browser
 
 marker = object()
@@ -54,6 +55,22 @@
             if match is not None:
                 pathonly, n = match.groups()
                 n = int(n) - 1
+                if n < 0:
+                    # BASE{PATH}0 is the URL/path up to but *not*
+                    # including the application.  The following
+                    # section is mostly a duplication from
+                    # HTTPRequest.getApplicationURL() :(
+                    names = self._app_names[:-1]
+                    # See: http://www.ietf.org/rfc/rfc2718.txt, Section 2.2.5
+                    names = [quote(name.encode("utf-8"), safe='/+@')
+                             for name in names]
+                    if pathonly:
+                        return names and ('/' + '/'.join(names)) or ''
+                    else:
+                        return (names and ("%s/%s" % (self._app_server,
+                                                      '/'.join(names)))
+                                or self._app_server)
+
                 try:
                     url = self.getApplicationURL(n, bool(pathonly))
                     if url == '/':

Modified: Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py
===================================================================
--- Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py	2007-08-05 22:21:57 UTC (rev 78611)
+++ Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py	2007-08-05 22:44:43 UTC (rev 78612)
@@ -11,7 +11,7 @@
 test_environ = {
     # XXX better cookie
     'HTTP_COOKIE': 'tree-s=eJzT0MgpMOQKVneEA1dbda4CI67EkgJjLj0AeGcHew',
-    'SCRIPT_NAME': '',
+    'SCRIPT_NAME': '/zope',
     'REQUEST_METHOD': 'GET',
     'PATH_INFO': '/john/mc/clane',
     'SERVER_PROTOCOL': 'HTTP/1.1',
@@ -43,12 +43,15 @@
         # equivalent of calling request.getURL(n) for zope.publisher's
         # request.
         request = self.makeRequest()
-        self.assertEqual(request['URL'], 'http://diehard.tv:8080/john/mc/clane')
-        self.assertEqual(request['URL0'], 'http://diehard.tv:8080/john/mc/clane')
-        self.assertEqual(request['URL1'], 'http://diehard.tv:8080/john/mc')
-        self.assertEqual(request['URL2'], 'http://diehard.tv:8080/john')
-        self.assertEqual(request['URL3'], 'http://diehard.tv:8080')
-        self.assertRaises(KeyError, request.get, 'URL4')
+        self.assertEqual(request['URL'],
+                         'http://diehard.tv:8080/zope/john/mc/clane')
+        self.assertEqual(request['URL0'],
+                         'http://diehard.tv:8080/zope/john/mc/clane')
+        self.assertEqual(request['URL1'], 'http://diehard.tv:8080/zope/john/mc')
+        self.assertEqual(request['URL2'], 'http://diehard.tv:8080/zope/john')
+        self.assertEqual(request['URL3'], 'http://diehard.tv:8080/zope')
+        self.assertEqual(request['URL4'], 'http://diehard.tv:8080')
+        self.assertRaises(KeyError, request.get, 'URL5')
 
     def test_urlpath(self):
         # URLPATH0, etc. works the same as URL0, etc., except that the
@@ -56,31 +59,43 @@
         # part.  This is the equivalent of calling request.getURL(n,
         # True) for zope.publisher's request.
         request = self.makeRequest()
-        self.assertEqual(request['URLPATH0'], '/john/mc/clane')
-        self.assertEqual(request['URLPATH1'], '/john/mc')
-        self.assertEqual(request['URLPATH2'], '/john')
-        self.assertEqual(request['URLPATH3'], '')
-        self.assertRaises(KeyError, request.get, 'URLPATH4')
+        self.assertEqual(request['URLPATH0'], '/zope/john/mc/clane')
+        self.assertEqual(request['URLPATH1'], '/zope/john/mc')
+        self.assertEqual(request['URLPATH2'], '/zope/john')
+        self.assertEqual(request['URLPATH3'], '/zope')
+        self.assertEqual(request['URLPATH4'], '')
+        self.assertRaises(KeyError, request.get, 'URLPATH5')
 
     def test_base(self):
-        # XXX I have no idea what BASE does... help?
+        # BASE0 is the URL up to but not including the Zope
+        # application, BASE1 is the URL of the Zope application, as is
+        # BASE2 with an additional path element appended, etc.
+
+        # With the exception of BASE0, asking for BASEn is the same as
+        # request.getApplicationURL(n-1) for zope.publisher's request.
         request = self.makeRequest()
         self.assertEqual(request['BASE0'], 'http://diehard.tv:8080')
-        self.assertEqual(request['BASE1'], 'http://diehard.tv:8080')
-        self.assertEqual(request['BASE2'], 'http://diehard.tv:8080/john')
-        self.assertEqual(request['BASE3'], 'http://diehard.tv:8080/john/mc')
+        self.assertEqual(request['BASE1'], 'http://diehard.tv:8080/zope')
+        self.assertEqual(request['BASE2'], 'http://diehard.tv:8080/zope/john')
+        self.assertEqual(request['BASE3'],
+                         'http://diehard.tv:8080/zope/john/mc')
         self.assertEqual(request['BASE4'],
-                         'http://diehard.tv:8080/john/mc/clane')
+                         'http://diehard.tv:8080/zope/john/mc/clane')
         self.assertRaises(KeyError, request.get, 'BASE5')
 
     def test_basepath(self):
-        # XXX I have no idea what BASEPATH does... help?
+        # BASEPATH0, etc. works the same as BASE0, except that the URL
+        # scheme and server name aren't included, just the path part.
+
+        # With the exception of BASEPATH0, asking for BASEPATHn is the
+        # same as request.getApplicationURL(n-1, True) for
+        # zope.publisher's request.
         request = self.makeRequest()
         self.assertEqual(request['BASEPATH0'], '')
-        self.assertEqual(request['BASEPATH1'], '')
-        self.assertEqual(request['BASEPATH2'], '/john')
-        self.assertEqual(request['BASEPATH3'], '/john/mc')
-        self.assertEqual(request['BASEPATH4'], '/john/mc/clane')
+        self.assertEqual(request['BASEPATH1'], '/zope')
+        self.assertEqual(request['BASEPATH2'], '/zope/john')
+        self.assertEqual(request['BASEPATH3'], '/zope/john/mc')
+        self.assertEqual(request['BASEPATH4'], '/zope/john/mc/clane')
         self.assertRaises(KeyError, request.get, 'BASEPATH5')
 
     def test_response(self):
@@ -103,7 +118,8 @@
         # fellow... zope.publisher's request.URL is a class property
         # that supports a __str__ method.  In five.publisher, we
         # really need it to be a string.
-        self.assertEqual(request.URL, 'http://diehard.tv:8080/john/mc/clane')
+        self.assertEqual(request.URL,
+                         'http://diehard.tv:8080/zope/john/mc/clane')
         self.assertEqual(request.URL[:17], 'http://diehard.tv')
 
     def test_body(self):



More information about the Checkins mailing list