[Zope-Checkins] SVN: Zope/trunk/ - LP #193122: New method getVirtualRoot added to the Request class

Jens Vagelpohl jens at dataflake.org
Thu Aug 19 08:53:53 EDT 2010


Log message for revision 115798:
  - LP #193122: New method getVirtualRoot added to the Request class
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/ZPublisher/HTTPRequest.py
  U   Zope/trunk/src/ZPublisher/tests/testHTTPRequest.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2010-08-19 12:48:35 UTC (rev 115797)
+++ Zope/trunk/doc/CHANGES.rst	2010-08-19 12:53:51 UTC (rev 115798)
@@ -15,6 +15,8 @@
 Features Added
 ++++++++++++++
 
+- LP #193122: New method getVirtualRoot added to the Request class
+
 - Updated test assertions to use unittest's ``assert*`` methods in favor of
   their deprecated `fail*` aliases.
 

Modified: Zope/trunk/src/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/trunk/src/ZPublisher/HTTPRequest.py	2010-08-19 12:48:35 UTC (rev 115797)
+++ Zope/trunk/src/ZPublisher/HTTPRequest.py	2010-08-19 12:53:51 UTC (rev 115798)
@@ -230,6 +230,13 @@
         other['VirtualRootPhysicalPath'] = parents[-1].getPhysicalPath()
         self._resetURLS()
 
+    def getVirtualRoot(self):
+        """ Return a slash-separated virtual root.
+
+        If it is same as the physical root, return ''.
+        """
+        return '/'.join([''] + self._script)
+
     def physicalPathToVirtualPath(self, path):
         """ Remove the path to the VirtualRoot from a physical path """
         if type(path) is type(''):

Modified: Zope/trunk/src/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/trunk/src/ZPublisher/tests/testHTTPRequest.py	2010-08-19 12:48:35 UTC (rev 115797)
+++ Zope/trunk/src/ZPublisher/tests/testHTTPRequest.py	2010-08-19 12:53:51 UTC (rev 115798)
@@ -1036,6 +1036,16 @@
                           '{"intkey":123,"stringkey":"blah"}')
         self.assertEquals(req.cookies['anothercookie'], 'boring')
 
+    def test_getVirtualRoot(self):
+        # https://bugs.launchpad.net/zope2/+bug/193122
+        req = self._makeOne()
+
+        req._script = []
+        self.assertEquals(req.getVirtualRoot(), '')
+
+        req._script = ['foo', 'bar']
+        self.assertEquals(req.getVirtualRoot(), '/foo/bar')
+
 TEST_ENVIRON = {
     'CONTENT_TYPE': 'multipart/form-data; boundary=12345',
     'REQUEST_METHOD': 'POST',



More information about the Zope-Checkins mailing list