[Checkins] SVN: z3c.baseregistry/branches/adamg-fix-with-ztk1.0/ made it work with ZTK 1.0

Adam Groszer agroszer at gmail.com
Thu Oct 28 08:53:33 EDT 2010


Log message for revision 118000:
  made it work with ZTK 1.0

Changed:
  U   z3c.baseregistry/branches/adamg-fix-with-ztk1.0/CHANGES.txt
  U   z3c.baseregistry/branches/adamg-fix-with-ztk1.0/setup.py
  U   z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/README.txt
  U   z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/zcml.py

-=-
Modified: z3c.baseregistry/branches/adamg-fix-with-ztk1.0/CHANGES.txt
===================================================================
--- z3c.baseregistry/branches/adamg-fix-with-ztk1.0/CHANGES.txt	2010-10-28 12:46:07 UTC (rev 117999)
+++ z3c.baseregistry/branches/adamg-fix-with-ztk1.0/CHANGES.txt	2010-10-28 12:53:33 UTC (rev 118000)
@@ -2,10 +2,14 @@
 CHANGES
 =======
 
-1.2.1 (unreleased)
+1.3.0 (unreleased)
 ------------------
 
-- ...
+- Fundamental change in the way how baseregistry hooks into ZCA.
+  Now it uses ``hooks.setSite``, which requires that ``zope.component`` hooks
+  are in place. Usually they are installed by ``zope.app.appsetup``.
+  Unless you use ``zope.app.appsetup``, install the hooks with
+  ``zope.component.hooks.setHooks()``.
 
 
 1.2.0 (2009-12-27)

Modified: z3c.baseregistry/branches/adamg-fix-with-ztk1.0/setup.py
===================================================================
--- z3c.baseregistry/branches/adamg-fix-with-ztk1.0/setup.py	2010-10-28 12:46:07 UTC (rev 117999)
+++ z3c.baseregistry/branches/adamg-fix-with-ztk1.0/setup.py	2010-10-28 12:53:33 UTC (rev 118000)
@@ -67,7 +67,7 @@
         ),
     install_requires = [
         'setuptools',
-        'zope.component',
+        'zope.component >= 3.9.4',
         'zope.configuration',
         'zope.i18nmessageid',
         'zope.interface',

Modified: z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/README.txt
===================================================================
--- z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/README.txt	2010-10-28 12:46:07 UTC (rev 117999)
+++ z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/README.txt	2010-10-28 12:53:33 UTC (rev 118000)
@@ -87,6 +87,13 @@
   >>> myRegistry
   <BaseComponents myRegistry>
 
+Another *VERY IMPORTANT* requirement is that ``zope.component`` hooks are in
+place. Install the hooks now:
+
+  >>> import zope.component.hooks
+  >>> zope.component.hooks.setHooks()
+
+
 Since this registry does not implement any of the ``IComponents`` API itself,
 it is not necessary to demonstrate those features here. Please see the
 corresponding documentation in the ``zope.component`` package.
@@ -545,7 +552,14 @@
   ZopeXMLConfigurationError: File "<string>", line 5...
     ConfigurationError: Nested ``registerIn`` directives are not permitted.
 
+Cleanup
+~~~~~~~
 
+Just unregister the ``zope.component`` hooks:
+
+  >>> zope.component.hooks.resetHooks()
+
+
 Global Non-Component-Registration Actions
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Modified: z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/zcml.py
===================================================================
--- z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/zcml.py	2010-10-28 12:46:07 UTC (rev 117999)
+++ z3c.baseregistry/branches/adamg-fix-with-ztk1.0/src/z3c/baseregistry/zcml.py	2010-10-28 12:53:33 UTC (rev 118000)
@@ -18,6 +18,7 @@
 __docformat__ = "reStructuredText"
 import zope.interface
 import zope.component.globalregistry
+import zope.component.hooks
 import zope.configuration.config
 import zope.configuration.fields
 from zope.configuration.exceptions import ConfigurationError
@@ -73,13 +74,25 @@
         return getattr(self.original, name)
 
 
+class FakeBaseRegistrySite(object):
+    """This a minimal fake Site, the only responsibility it has
+    is to store our registry as a SiteManager and return it later.
+    This is needed to fool siteinfo via setSite, zope.component.zcml.handler
+    will grab the registry via zope.component.getSiteManager() then."""
+
+    def __init__(self, sm):
+        self.sm = sm
+
+    def getSiteManager(self):
+        return self.sm
+
 def setActiveRegistry(context, registry):
-    context.original = zope.component.globalregistry.globalSiteManager
-    # Set the temporary, base registry
-    zope.component.globalregistry.globalSiteManager = registry
+    context.original = zope.component.hooks.getSite()
+    fakeSite = FakeBaseRegistrySite(registry)
+    zope.component.hooks.setSite(fakeSite)
 
 def resetOriginalRegistry(context):
-    zope.component.globalregistry.globalSiteManager = context.original
+    zope.component.hooks.setSite(context.original)
 
 
 class RegisterIn(zope.configuration.config.GroupingContextDecorator):



More information about the checkins mailing list