Commit 3f2cdc69 authored by Jens Vagelpohl's avatar Jens Vagelpohl

- LP #193122: New method getVirtualRoot added to the Request class

parent 72e68c0f
......@@ -16,6 +16,8 @@ Bugs Fixed
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.
......
......@@ -232,6 +232,13 @@ class HTTPRequest(BaseRequest):
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(''):
......
......@@ -1029,6 +1029,16 @@ class HTTPRequestTests(unittest.TestCase):
'{"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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment