[Checkins] SVN: zc.resourcelibrary/trunk/ Register adapters with getSiteManager rather than getGlobalSiteManager. This

Brian Sutherland jinty at web.de
Thu Dec 22 16:44:22 UTC 2011


Log message for revision 123857:
  Register adapters with getSiteManager rather than getGlobalSiteManager. This
  allows registering resource libraries in non-global sites. For detais see:
   - https://mail.zope.org/pipermail/zope-dev/2010-March/039657.html
   - http://docs.pylonsproject.org/projects/pyramid_zcml/en/latest/narr.html#using-broken-zcml-directives
  

Changed:
  U   zc.resourcelibrary/trunk/CHANGES.txt
  A   zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/localsite.txt
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py

-=-
Modified: zc.resourcelibrary/trunk/CHANGES.txt
===================================================================
--- zc.resourcelibrary/trunk/CHANGES.txt	2011-12-22 16:23:01 UTC (rev 123856)
+++ zc.resourcelibrary/trunk/CHANGES.txt	2011-12-22 16:44:22 UTC (rev 123857)
@@ -5,6 +5,11 @@
 1.3.3 (unreleased)
 ------------------
 
+- Register adapters with getSiteManager rather than getGlobalSiteManager. This
+  allows registering resource libraries in non-global sites. For detais see:
+   - https://mail.zope.org/pipermail/zope-dev/2010-March/039657.html
+   - http://docs.pylonsproject.org/projects/pyramid_zcml/en/latest/narr.html#using-broken-zcml-directives
+
 - Raise NotImplementedError if we find that a second ZCML declaration would
   change the global library_info dict in a way that may (depending on ZCML
   ordering) break applications at runtime. These errors were pretty hard to

Added: zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/localsite.txt
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/localsite.txt	                        (rev 0)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/localsite.txt	2011-12-22 16:44:22 UTC (rev 123857)
@@ -0,0 +1,27 @@
+Like most zope.component declarations, resource libraries are registered
+against the current, not global site manager:
+
+    >>> class DummySiteManager:
+    ...     def registerAdapter(self, *args, **kw):
+    ...         print 'registering our adapter'
+    >>> class DummySite:
+    ...     def getSiteManager(self):
+    ...         return DummySiteManager()
+
+    >>> zcml("""
+    ... <configure
+    ...     xmlns="http://namespaces.zope.org/zope"
+    ...     package="zc.resourcelibrary">
+    ...
+    ...   <resourceLibrary name="some-other-library">
+    ...     <directory source="tests/example"/>
+    ...   </resourceLibrary>
+    ...
+    ... </configure>
+    ... """, site=DummySite())
+    registering our adapter
+
+Clean Up:
+
+    >>> import zope.component.hooks
+    >>> zope.component.hooks.setSite(None)


Property changes on: zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/localsite.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py	2011-12-22 16:23:01 UTC (rev 123856)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py	2011-12-22 16:44:22 UTC (rev 123857)
@@ -20,6 +20,7 @@
 from zc.resourcelibrary import tal
 from zope.app.testing import functional
 from zope.configuration import xmlconfig
+from zope.component import getGlobalSiteManager
 import zope.interface
 from zope.pagetemplate import pagetemplate
 import zope.publisher.interfaces.browser
@@ -55,7 +56,8 @@
 
 #### testing framework ####
 
-def zcml(s, execute=True, clear=()):
+def zcml(s, execute=True, clear=(), site=None):
+    zope.component.hooks.setSite(site)
     for i in clear:
         del resourcelibrary.library_info[i]
     from zope.app.appsetup.appsetup import __config_context as context
@@ -125,7 +127,9 @@
 
 def test_suite():
     suite = functional.FunctionalDocFileSuite(
-        '../README.txt', 'duplicate_declarations.txt',
+        '../README.txt',
+        'duplicate_declarations.txt',
+        'localsite.txt',
         globs={'zcml': zcml, 'zpt': zpt},
         optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS,
         )

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py	2011-12-22 16:23:01 UTC (rev 123856)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py	2011-12-22 16:44:22 UTC (rev 123857)
@@ -16,7 +16,7 @@
 from zope.browserresource.directory import DirectoryResourceFactory
 from zope.browserresource.metadirectives import IBasicResourceInformation
 from zope.browserresource.metaconfigure import allowed_names
-from zope.component import getGlobalSiteManager
+from zope.component import getSiteManager
 from zope.configuration.exceptions import ConfigurationError
 from zope.interface import Interface
 from zope.publisher.interfaces.browser import IBrowserRequest
@@ -80,7 +80,7 @@
                 raise ConfigurationError(
                     'Resource library "%s" has unsatisfied dependency on "%s".'
                     % (name, dep))
-    getGlobalSiteManager().registerAdapter(
+    getSiteManager().registerAdapter(
         factory, required, provided, adapter_name, info)
 
 



More information about the checkins mailing list