Commit 0d876e35 authored by Tres Seaver's avatar Tres Seaver

Merge saner SiteRoot impl. from 2.12 branch.

parent 7c57d06e
......@@ -87,20 +87,6 @@ class SiteRoot(Traverser, Implicit):
self.title = title.strip()
self.base = base = base.strip()
self.path = path = path.strip()
if base:
self.SiteRootBASE = base
else:
try:
del self.SiteRootBASE
except:
pass
if path:
self.SiteRootPATH = path
else:
try:
del self.SiteRootPATH
except:
pass
def manage_edit(self, title, base, path, REQUEST=None):
""" Set the title, base, and path.
......@@ -114,30 +100,26 @@ class SiteRoot(Traverser, Implicit):
def __call__(self, client, request, response=None):
""" Traversing.
"""
rq = request
if SUPPRESS_SITEROOT:
return
if '_SUPPRESS_SITEROOT' in _swallow(request, '_SUPPRESS'):
request.setVirtualRoot(request.steps)
if '_SUPPRESS_SITEROOT' in _swallow(rq, '_SUPPRESS'):
rq.setVirtualRoot(rq.steps)
return
srd = [None, None]
for i in (0, 1):
srp = ('SiteRootBASE', 'SiteRootPATH')[i]
try:
srd[i] = getattr(self, srp)
except AttributeError:
srd[i] = request.get(srp, None)
if srd[i] is None:
srd[i] = request.environ.get(srp, None)
if srd[0] is not None:
request['ACTUAL_URL'] = request['ACTUAL_URL'].replace(
request['SERVER_URL'], srd[0])
request['SERVER_URL'] = srd[0]
request._resetURLS()
if srd[1] is not None:
old = request['URL']
request.setVirtualRoot(srd[1])
request['ACTUAL_URL'] = request['ACTUAL_URL'].replace(
old, request['URL'])
base = (self.base or
rq.get('SiteRootBASE') or
rq.environ.get('SiteRootBASE'))
path = (self.path or
rq.get('SiteRootPATH') or
rq.environ.get('SiteRootPATH'))
if base is not None:
rq['ACTUAL_URL'] = rq['ACTUAL_URL'].replace(rq['SERVER_URL'], base)
rq['SERVER_URL'] = base
rq._resetURLS()
if path is not None:
old = rq['URL']
rq.setVirtualRoot(path)
rq['ACTUAL_URL'] = rq['ACTUAL_URL'].replace(old, rq['URL'])
def get_size(self):
""" Make FTP happy
......
......@@ -127,18 +127,12 @@ class SiteRootTests(unittest.TestCase):
self.assertEqual(siteroot.title, 'TITLE')
self.assertEqual(siteroot.base, '')
self.assertEqual(siteroot.path, '')
# XXX Why aren't these defaulted to None at class scope?
# Even better: why do they exist at all?
self.failUnless(getattr(siteroot, 'SiteRootBase', self) is self)
self.failUnless(getattr(siteroot, 'SiteRootPath', self) is self)
def test___init___w_base_and_path(self):
siteroot = self._makeOne(base='http://example.com', path='/path')
self.assertEqual(siteroot.title, 'TITLE')
self.assertEqual(siteroot.base, 'http://example.com')
self.assertEqual(siteroot.path, '/path')
self.assertEqual(siteroot.SiteRootBASE, 'http://example.com')
self.assertEqual(siteroot.SiteRootPATH, '/path')
def test_manage_edit_no_REQUEST(self):
siteroot = self._makeOne(title='Before',
......@@ -150,8 +144,6 @@ class SiteRootTests(unittest.TestCase):
self.assertEqual(siteroot.title, 'After')
self.assertEqual(siteroot.base, 'http://after.example.com')
self.assertEqual(siteroot.path, '/after')
self.assertEqual(siteroot.SiteRootBASE, 'http://after.example.com')
self.assertEqual(siteroot.SiteRootPATH, '/after')
def test_manage_edit_w_REQUEST(self):
siteroot = self._makeOne(title='Before',
......@@ -165,8 +157,6 @@ class SiteRootTests(unittest.TestCase):
self.assertEqual(siteroot.title, 'After')
self.assertEqual(siteroot.base, 'http://after.example.com')
self.assertEqual(siteroot.path, '/after')
self.assertEqual(siteroot.SiteRootBASE, 'http://after.example.com')
self.assertEqual(siteroot.SiteRootPATH, '/after')
def test___call___w_SUPPRESS_SITEROOT_set(self):
self._set_SUPPRESS_SITEROOT(1)
......
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