[Zope-Checkins] SVN: Zope/trunk/src/Products/SiteAccess/ Merge saner SiteRoot impl. from 2.12 branch.
Tres Seaver
tseaver at palladion.com
Fri May 21 11:20:14 EDT 2010
Log message for revision 112623:
Merge saner SiteRoot impl. from 2.12 branch.
Changed:
U Zope/trunk/src/Products/SiteAccess/SiteRoot.py
U Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py
-=-
Modified: Zope/trunk/src/Products/SiteAccess/SiteRoot.py
===================================================================
--- Zope/trunk/src/Products/SiteAccess/SiteRoot.py 2010-05-21 15:20:04 UTC (rev 112622)
+++ Zope/trunk/src/Products/SiteAccess/SiteRoot.py 2010-05-21 15:20:13 UTC (rev 112623)
@@ -87,20 +87,6 @@
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 @@
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
Modified: Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py
===================================================================
--- Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py 2010-05-21 15:20:04 UTC (rev 112622)
+++ Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py 2010-05-21 15:20:13 UTC (rev 112623)
@@ -127,18 +127,12 @@
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 @@
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 @@
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)
More information about the Zope-Checkins
mailing list