Log message for revision 115797: - LP #193122: New method getVirtualRoot added to the Request class
Changed: U Zope/branches/2.12/doc/CHANGES.rst U Zope/branches/2.12/src/ZPublisher/HTTPRequest.py U Zope/branches/2.12/src/ZPublisher/tests/testHTTPRequest.py -=- Modified: Zope/branches/2.12/doc/CHANGES.rst =================================================================== --- Zope/branches/2.12/doc/CHANGES.rst 2010-08-19 12:33:38 UTC (rev 115796) +++ Zope/branches/2.12/doc/CHANGES.rst 2010-08-19 12:48:35 UTC (rev 115797) @@ -16,6 +16,8 @@ Features Added ++++++++++++++ +- LP #193122: New method getVirtualRoot added to the Request class + - Added forward-compatibility shims for some frequently used modules moved in Zope 2.13. Modified: Zope/branches/2.12/src/ZPublisher/HTTPRequest.py =================================================================== --- Zope/branches/2.12/src/ZPublisher/HTTPRequest.py 2010-08-19 12:33:38 UTC (rev 115796) +++ Zope/branches/2.12/src/ZPublisher/HTTPRequest.py 2010-08-19 12:48:35 UTC (rev 115797) @@ -232,6 +232,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/branches/2.12/src/ZPublisher/tests/testHTTPRequest.py =================================================================== --- Zope/branches/2.12/src/ZPublisher/tests/testHTTPRequest.py 2010-08-19 12:33:38 UTC (rev 115796) +++ Zope/branches/2.12/src/ZPublisher/tests/testHTTPRequest.py 2010-08-19 12:48:35 UTC (rev 115797) @@ -1029,6 +1029,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', _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins