Skip to content

Commit

Permalink
- LP #193122: New method getVirtualRoot added to the Request class
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Aug 19, 2010
1 parent 72e68c0 commit 3f2cdc6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/CHANGES.rst
Expand Up @@ -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.

Expand Down
7 changes: 7 additions & 0 deletions src/ZPublisher/HTTPRequest.py
Expand Up @@ -232,6 +232,13 @@ def setVirtualRoot(self, path, hard=0):
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(''):
Expand Down
10 changes: 10 additions & 0 deletions src/ZPublisher/tests/testHTTPRequest.py
Expand Up @@ -1029,6 +1029,16 @@ def test_parses_json_cookies(self):
'{"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',
Expand Down

0 comments on commit 3f2cdc6

Please sign in to comment.