[Zope-Checkins] SVN: Products.Five/trunk/ The FiveSiteManager
classes now work again, but are deprecated for the
Lennart Regebro
regebro at gmail.com
Tue Jul 25 14:17:24 EDT 2006
Log message for revision 69259:
The FiveSiteManager classes now work again, but are deprecated for the
new zope.component support.
Changed:
U Products.Five/trunk/CHANGES.txt
U Products.Five/trunk/doc/localsite.txt
U Products.Five/trunk/site/browser.py
U Products.Five/trunk/site/localsite.py
U Products.Five/trunk/site/metaconfigure.py
U Products.Five/trunk/site/tests/functional.txt
U Products.Five/trunk/site/tests/sitemanager.txt
U Products.Five/trunk/site/tests/test_localsite.py
U Products.Five/trunk/site/tests/test_utility.py
-=-
Modified: Products.Five/trunk/CHANGES.txt
===================================================================
--- Products.Five/trunk/CHANGES.txt 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/CHANGES.txt 2006-07-25 18:17:23 UTC (rev 69259)
@@ -23,6 +23,9 @@
* Changed the tests to reflect that defaultView no only works for views
(and not on attributes).
+* The FiveSiteManager classes now work again, but are deprecated for the
+ new zope.component support.
+
Five 1.5c (2006-05-29)
======================
Modified: Products.Five/trunk/doc/localsite.txt
===================================================================
--- Products.Five/trunk/doc/localsite.txt 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/doc/localsite.txt 2006-07-25 18:17:23 UTC (rev 69259)
@@ -9,6 +9,81 @@
their configuration be persisted in the ZODB as well as managed
through the web interface.
+
+Five 1.5 supports two distinct and slightly incompatible versions of
+local site support. The first one, (here known as "old" sites) was
+introduced in Five 1.3 and is based on Zope 3.2s site implementation.
+But the site implementation in Zope 3.2 was overly complicated, and
+for 3.3 it was refactored, and Five 1.5 contains support for this new
+local site support as well (known as "new" sites).
+
+For documentation of how to use local sites, see the Zope 3.3 documentation.
+This document is mostly about how the implementation of the old sites work,
+and how to migrate from Five 1.3 and 1.4.
+
+
+Migration from old sites to new sites
+-------------------------------------
+
+New sites are based on Zope 3.3s new site managers and persistent
+component registries. Old sites are based on specific Five implementation
+of site managers, and keeps utilities in a folder called "utilities".
+
+They are used basically the same, but they are created differently,
+and also, when you look up a utility with getUtility or queryUtility, in
+old sites, the utility will have an acquicition context, while in the new
+sites it will not.
+
+Setting up the site
+...................
+
+The old setup of a site was done by marking the class of the site as a
+possible site with five:localsite, and then either manually through the ZMI
+or programmatically through enableLocalSiteHook(site) turn it into a site.
+
+The new setup involves calling enableSite(site) and createing and setting
+a site manager. The simplest way to do this programatically is to look
+up the "components.html" view on the site, and calling view.makeSite().
+As any ObjectManager can be a site there is no longer any need to specially
+mark the class as being a possible site.
+
+Registering local utilities
+...........................
+
+The old usage was to get the site manager, either throgh adapting with
+IFiveUtilityRegistry(site) or by calling getSiteManager(). You could then
+register the utilities with sitemanager.registerUtility(interface, utility)
+
+The new way is to call getSiteManager().registerUtility(object, provided).
+Note that in the old way, the first parameter is the interface name, and
+the second the actual utility object, but in the new way, it is the other
+way around.
+
+Migrating the actual sites
+..........................
+
+Not Yet Implemented.
+
+Experimental forwards compatibility
+...................................
+
+If you have software using the old sites, and software using the new sites,
+there is sligthly experimental support to make software expecting new sites
+to work with old sites. Nothing is promised with this, as it is largely
+untested. The best thing to do is without a doubt to convert your old site
+software and your old sites to use new sites.
+
+
+
+Old site implementation details
+-------------------------------
+
+The rest of this document documents the details of the old site implementation.
+Everything from here on concerns only the old implementation and is of mainly
+hysterical interest:
+
+
+
By default, Zope 3 has a global site which is configured through ZCML.
It provides the fallback for all component look-up. Local sites are
typically set during traversal, when the traverser encounters an
Modified: Products.Five/trunk/site/browser.py
===================================================================
--- Products.Five/trunk/site/browser.py 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/browser.py 2006-07-25 18:17:23 UTC (rev 69259)
@@ -19,7 +19,7 @@
from zope.app.component.hooks import clearSite
from Products.Five.browser import BrowserView
-from Products.Five.component import enableSite, disableSite
+from Products.Five.site.localsite import enableLocalSiteHook, disableLocalSiteHook
class LocalSiteView(BrowserView):
"""View for convering a possible site to a site
@@ -40,7 +40,7 @@
if self.isSite():
raise ValueError('This is already a site')
- enableSite(self.context)
+ enableLocalSiteHook(self.context)
return "This object is now a site"
def unmakeSite(self):
@@ -48,7 +48,7 @@
if not self.isSite():
raise ValueError('This is not a site')
- disableSite(self.context)
+ disableLocalSiteHook(self.context)
# disableLocalSiteHook circumcised our context so that it's
# not an ISite anymore. That can mean that certain things for
Modified: Products.Five/trunk/site/localsite.py
===================================================================
--- Products.Five/trunk/site/localsite.py 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/localsite.py 2006-07-25 18:17:23 UTC (rev 69259)
@@ -29,6 +29,9 @@
# make {get|query}NextSiteManager() work without having to
# resort to Zope 2 acquisition
self.context = self.__parent__ = context
+ warnings.warn("The FiveSiteManager is deprecated and will be removed "
+ "in Zope 2.12. \nSee Five/doc/localsite.txt .",
+ DeprecationWarning, 2)
@property
def __bases__(self):
@@ -97,3 +100,30 @@
def setSiteManager(self, sm):
raise NotImplementedError('This class has a fixed site manager')
+
+
+#BBB: Goes away in Five Zope 2.12
+
+import warnings
+from Products.Five.component import enableSite, disableSite
+from zope.app.component.hooks import setSite, clearSite, setHooks
+
+def enableLocalSiteHook(obj):
+ warnings.warn("The enableLocalSiteHook is deprecated and will be removed "
+ "in Zope 2.12. \nSee Five/doc/localsite.txt .",
+ DeprecationWarning, 2)
+ enableSite(obj)
+ components = FiveSiteManager(obj)
+ obj.setSiteManager(components)
+ setSite(obj)
+ setHooks()
+
+def disableLocalSiteHook(obj):
+ """Remove __before_traverse__ hook for Local Site
+ """
+ warnings.warn("The disableLocalSiteHook is deprecated and will be removed "
+ "in Zope 2.12. \nSee Five/doc/localsite.txt .",
+ DeprecationWarning, 2)
+ disableSite(obj)
+ clearSite()
+ obj.setSiteManager(None)
Modified: Products.Five/trunk/site/metaconfigure.py
===================================================================
--- Products.Five/trunk/site/metaconfigure.py 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/metaconfigure.py 2006-07-25 18:17:23 UTC (rev 69259)
@@ -25,7 +25,7 @@
from Products.Five.site.localsite import FiveSite
-import logging
+import logging, warnings
LOG = logging.getLogger('Five')
@@ -40,21 +40,18 @@
def installSiteHook(_context, class_, site_class=None):
- if site_class is None:
- if not IPossibleSite.implementedBy(class_):
- # This is not a possible site, we need to monkey-patch it so that
- # it is.
- site_class = FiveSite
- else:
- if not IPossibleSite.implementedBy(site_class):
- raise ConfigurationError('Site class does not implement '
- 'IPossibleClass: %s' % site_class)
+ warnings.warn_explicit("The five:localsite directive is deprecated and "
+ "will be removed in Zope 2.12. \n"
+ "See Five/doc/localsite.txt .",
+ DeprecationWarning,
+ _context.info.file, _context.info.line)
if site_class is not None:
_context.action(
discriminator = (class_,),
callable = classSiteHook,
args=(class_, site_class)
)
+ if not IPossibleSite.implementedBy(class_):
_context.action(
discriminator = (class_, IPossibleSite),
callable = classImplements,
Modified: Products.Five/trunk/site/tests/functional.txt
===================================================================
--- Products.Five/trunk/site/tests/functional.txt 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/tests/functional.txt 2006-07-25 18:17:23 UTC (rev 69259)
@@ -48,7 +48,11 @@
... />
...
... </configure>"""
+ >>> import warnings
+ >>> showwarning = warnings.showwarning
+ >>> warnings.showwarning = lambda *a, **k: None
>>> zcml.load_string(zcml_text)
+ >>> warnings.showwarning = showwarning
then we add an instance to our folder:
@@ -57,6 +61,9 @@
Now we check what the info view tells us about local component lookup:
+ >>> import warnings
+ >>> showwarning = warnings.showwarning
+ >>> warnings.showwarning = lambda *a, **k: None
>>> print http(r'''
... GET /test_folder_1_/site/@@checkSiteManager.html HTTP/1.1
... ''')
@@ -74,6 +81,9 @@
>>> uf = self.folder.acl_users
>>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
+ >>> import warnings
+ >>> showwarning = warnings.showwarning
+ >>> warnings.showwarning = lambda *a, **k: None
>>> print http(r'''
... POST /test_folder_1_/site/@@manage_site.html HTTP/1.1
... Authorization: Basic manager:r00t
@@ -83,6 +93,10 @@
HTTP/1.1 200 OK
...
+ >>> warnings.showwarning = showwarning
+
+ >>> warnings.showwarning = showwarning
+
Now we call the info view again and find that local component lookup
is working:
@@ -132,6 +146,9 @@
At last we can "unmake" the site using the browser view provided by
Five:
+ >>> import warnings
+ >>> showwarning = warnings.showwarning
+ >>> warnings.showwarning = lambda *a, **k: None
>>> print http(r'''
... POST /test_folder_1_/site/@@manage_site.html HTTP/1.1
... Authorization: Basic manager:r00t
@@ -141,9 +158,14 @@
HTTP/1.1 200 OK
...
+ >>> warnings.showwarning = showwarning
+
And everything is back to normal with respect to local component
lookup:
+ >>> import warnings
+ >>> showwarning = warnings.showwarning
+ >>> warnings.showwarning = lambda *a, **k: None
>>> print http(r'''
... GET /test_folder_1_/site/@@checkSiteManager.html HTTP/1.1
... ''')
@@ -157,3 +179,4 @@
>>> from zope.app.testing.placelesssetup import tearDown
>>> tearDown()
+
Modified: Products.Five/trunk/site/tests/sitemanager.txt
===================================================================
--- Products.Five/trunk/site/tests/sitemanager.txt 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/tests/sitemanager.txt 2006-07-25 18:17:23 UTC (rev 69259)
@@ -9,6 +9,10 @@
>>> import Products.Five
>>> from Products.Five import zcml
+ >>> import warnings
+ >>> showwarning = warnings.showwarning
+ >>> warnings.showwarning = lambda *a, **k: None
+
>>> zcml.load_config("meta.zcml", Products.Five)
>>> zcml.load_config("permissions.zcml", Products.Five)
>>> zcml.load_config("configure.zcml", Products.Five.site)
@@ -24,15 +28,16 @@
>>> nothing = manage_addDummySite(self.folder, 'dummysite')
>>> dummysite = self.folder.dummysite
-
Local vs. global sites
----------------------
Let's make the possible site a real site:
- >>> from Products.Five.component import enableSite
- >>> enableSite(dummysite)
+ >>> from Products.Five.site.localsite import enableLocalSiteHook
+ >>> enableLocalSiteHook(dummysite)
+ >>> warnings.showwarning = showwarning
+
and tell Zope 3 about it:
>>> from zope.app.component.hooks import setSite, setHooks
@@ -118,7 +123,7 @@
Now we set the current site to the ``subsite``:
- >>> enableSite(subsite)
+ >>> enableLocalSiteHook(subsite)
>>> setSite(subsite)
When we call getServices() now, we get the correct site manager:
Modified: Products.Five/trunk/site/tests/test_localsite.py
===================================================================
--- Products.Five/trunk/site/tests/test_localsite.py 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/tests/test_localsite.py 2006-07-25 18:17:23 UTC (rev 69259)
@@ -95,7 +95,13 @@
<five:localsite
xmlns:five="http://namespaces.zope.org/five"
class="Products.Five.site.tests.dummy.DummySite" />"""
+ import warnings
+ showwarning = warnings.showwarning
+ warnings.showwarning = lambda *a, **k: None
+
zcml.load_string(zcml_text)
+
+ warnings.showwarning = showwarning
# Hook up custom component architecture calls; we need to do
# this here because zope.app.component.hooks registers a
Modified: Products.Five/trunk/site/tests/test_utility.py
===================================================================
--- Products.Five/trunk/site/tests/test_utility.py 2006-07-25 17:58:06 UTC (rev 69258)
+++ Products.Five/trunk/site/tests/test_utility.py 2006-07-25 18:17:23 UTC (rev 69259)
@@ -31,6 +31,7 @@
from zope.app.testing.placelesssetup import setUp, tearDown
from zope.app.component import getNextUtility
from zope.app.component.hooks import setSite, clearSite, setHooks
+from zope.component import getSiteManager
import Products.Five
from Products.Five import zcml
@@ -38,6 +39,7 @@
from Products.Five.site.interfaces import IRegisterUtilitySimply
from Products.Five.site.tests.dummy import manage_addDummySite, \
IDummyUtility, ISuperDummyUtility, DummyUtility
+from Products.Five.site.localsite import enableLocalSiteHook
class LocalUtilityServiceTest(ZopeTestCase.ZopeTestCase):
@@ -51,10 +53,16 @@
<five:localsite
xmlns:five="http://namespaces.zope.org/five"
class="Products.Five.site.tests.dummy.DummySite" />"""
+
+ import warnings
+ showwarning = warnings.showwarning
+ warnings.showwarning = lambda *a, **k: None
+
zcml.load_string(zcml_text)
manage_addDummySite(self.folder, 'site')
- enableSite(self.folder.site)
- setSite(self.folder.site)
+ enableLocalSiteHook(self.folder.site)
+
+ warnings.showwarning = showwarning
# Hook up custom component architecture calls; we need to do
# this here because zope.app.component.hooks registers a
@@ -69,26 +77,26 @@
from Products.Five.site.localsite import FiveSiteManager
from Products.Five.site.utility import SimpleLocalUtilityRegistry
- local_sm = zapi.getSiteManager(None)
+ local_sm = getSiteManager(None)
self.failIf(local_sm is zapi.getGlobalSiteManager())
self.failUnless(isinstance(local_sm, FiveSiteManager))
- local_sm = zapi.getSiteManager(self.folder.site)
+ local_sm = getSiteManager(self.folder.site)
self.failIf(local_sm is zapi.getGlobalSiteManager())
self.failUnless(isinstance(local_sm, FiveSiteManager))
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
self.failUnless(isinstance(sm.utilities, SimpleLocalUtilityRegistry))
def test_getUtilitiesNoUtilitiesFolder(self):
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
self.failUnless(sm.queryUtility(IDummyUtility) is None)
self.assertEquals(list(sm.getUtilitiesFor(IDummyUtility)), [])
self.assertEquals(list(sm.getAllUtilitiesRegisteredFor(IDummyUtility)), [])
def test_registerUtilityOnUtilityRegistry(self):
- utils = zapi.getSiteManager().utilities
+ utils = getSiteManager().utilities
dummy = DummyUtility()
utils.registerUtility(IDummyUtility, dummy, 'dummy')
@@ -99,7 +107,7 @@
IDummyUtility)), [dummy])
def test_registerUtilityOnSiteManager(self):
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
self.failUnless(IRegisterUtilitySimply.providedBy(sm))
dummy = DummyUtility()
sm.registerUtility(IDummyUtility, dummy, 'dummy')
@@ -111,7 +119,7 @@
IDummyUtility)), [dummy])
def test_registerTwoUtilitiesWithSameNameDifferentInterface(self):
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
self.failUnless(IRegisterUtilitySimply.providedBy(sm))
dummy = DummyUtility()
superdummy = DummyUtility()
@@ -129,7 +137,7 @@
# anything registered for IDummyInterface of ISuperDummyInterface
# should come back.
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
self.failUnless(IRegisterUtilitySimply.providedBy(sm))
dummy = DummyUtility()
superdummy = DummyUtility()
@@ -169,13 +177,16 @@
def test_nestedSitesDontConflictButStillAcquire(self):
# let's register a dummy utility in the dummy site
dummy = DummyUtility()
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
sm.registerUtility(IDummyUtility, dummy)
# let's also create a subsite and make that our site
manage_addDummySite(self.folder.site, 'subsite')
- enableSite(self.folder.site.subsite)
- setSite(self.folder.site.subsite)
+ import warnings
+ showwarning = warnings.showwarning
+ warnings.showwarning = lambda *a, **k: None
+ enableLocalSiteHook(self.folder.site.subsite)
+ warnings.showwarning = showwarning
# we should still be able to lookup the original utility from
# the site one level above
@@ -184,7 +195,7 @@
# now we register a dummy utility in the subsite and see that
# its registration doesn't conflict
subdummy = DummyUtility()
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
sm.registerUtility(IDummyUtility, subdummy)
# when we look it up we get the more local one now because the
@@ -205,7 +216,7 @@
def test_registeringTwiceIsConflict(self):
dummy1 = DummyUtility()
dummy2 = DummyUtility()
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
sm.registerUtility(IDummyUtility, dummy1)
self.assertRaises(ValueError, sm.registerUtility,
IDummyUtility, dummy2)
@@ -216,7 +227,7 @@
def test_utilitiesHaveProperAcquisitionContext(self):
dummy = DummyUtility()
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
sm.registerUtility(IDummyUtility, dummy)
# let's see if we can acquire something all the way from the
@@ -241,7 +252,7 @@
provideUtility(global_dummy, IDummyUtility)
local_dummy = DummyUtility()
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
sm.registerUtility(IDummyUtility, local_dummy)
self.assertEquals(zapi.getUtility(IDummyUtility), local_dummy)
@@ -250,11 +261,14 @@
# test local site vs. nested local site
manage_addDummySite(self.folder.site, 'subsite')
- enableSite(self.folder.site.subsite)
- setSite(self.folder.site.subsite)
+ import warnings
+ showwarning = warnings.showwarning
+ warnings.showwarning = lambda *a, **k: None
+ enableLocalSiteHook(self.folder.site.subsite)
+ warnings.showwarning = showwarning
sublocal_dummy = DummyUtility()
- sm = zapi.getSiteManager()
+ sm = getSiteManager()
sm.registerUtility(IDummyUtility, sublocal_dummy)
self.assertEquals(zapi.getUtility(IDummyUtility), sublocal_dummy)
More information about the Zope-Checkins
mailing list