[Checkins] SVN: grok/trunk/src/grok/ Rename 'hidden' to 'public' and add a test for it, as well as a test for

Martijn Faassen faassen at infrae.com
Sun Jan 7 11:01:24 EST 2007


Log message for revision 71776:
  Rename 'hidden' to 'public' and add a test for it, as well as a test for
  name_in_container. Do not test everything yet though.
  

Changed:
  U   grok/trunk/src/grok/directive.py
  A   grok/trunk/src/grok/ftests/utility/public.py
  U   grok/trunk/src/grok/interfaces.py
  U   grok/trunk/src/grok/meta.py

-=-
Modified: grok/trunk/src/grok/directive.py
===================================================================
--- grok/trunk/src/grok/directive.py	2007-01-07 15:50:16 UTC (rev 71775)
+++ grok/trunk/src/grok/directive.py	2007-01-07 16:01:23 UTC (rev 71776)
@@ -199,7 +199,7 @@
 
 class LocalUtilityDirective(MultipleTimesDirective):
     def check_arguments(self, factory, provides=None, name=u'',
-                        setup=None, hidden=True, name_in_container=None):
+                        setup=None, public=False, name_in_container=None):
         if provides is not None and not IInterface.providedBy(provides):
             raise GrokImportError("You can only pass an interface to the "
                                   "provides argument of %s." % self.name)
@@ -209,14 +209,14 @@
 
 class LocalUtilityInfo(object):
     def __init__(self, factory, provides=None, name=u'',
-                 setup=None, hidden=True, name_in_container=None):
+                 setup=None, public=False, name_in_container=None):
         self.factory = factory
         if provides is None:
             provides = util.class_annotation(factory, 'grok.provides', None)
         self.provides = provides
         self.name = name
         self.setup = setup
-        self.hidden = hidden
+        self.public = public
         self.name_in_container = name_in_container
 
 class RequireDirective(BaseTextDirective, SingleValue, MultipleTimesDirective):

Added: grok/trunk/src/grok/ftests/utility/public.py
===================================================================
--- grok/trunk/src/grok/ftests/utility/public.py	2007-01-07 15:50:16 UTC (rev 71775)
+++ grok/trunk/src/grok/ftests/utility/public.py	2007-01-07 16:01:23 UTC (rev 71776)
@@ -0,0 +1,46 @@
+"""
+By default, a utility is not in the public site; it's in ++etc++site. We can
+also specify the utility to be public. It will then be created in the container
+that is the site. The name the utility should have in the container can
+be controlled using name_in_container:
+
+  >>> import grok
+  >>> from zope import component
+  >>> from grok.ftests.utility.public import *
+  >>> grok.grok('grok.ftests.utility.public')
+
+  >>> cave = Cave()
+  >>> getRootFolder()["cave"] = cave
+
+  >>> from zope.app.component.hooks import getSite, setSite
+  >>> setSite(cave)
+  >>> cave['fireplace'] is component.getUtility(IFireplace)
+  True
+
+name_in_container can also be used for objects stored under the site manager
+(that is in ++etc++site):
+
+   >>> cave2 = Cave2()
+   >>> getRootFolder()['cave2'] = cave2
+   >>> setSite(cave2)
+   >>> (cave2.getSiteManager()['default']['fireplace'] is
+   ...  component.getUtility(IFireplace))
+   True
+
+"""
+
+import grok
+from zope import interface
+
+class IFireplace(interface.Interface):
+    pass
+
+class Fireplace(grok.LocalUtility):
+    grok.implements(IFireplace)
+    
+class Cave(grok.Container, grok.Site):
+    grok.local_utility(Fireplace, public=True, name_in_container='fireplace')
+
+class Cave2(grok.Container, grok.Site):
+    grok.local_utility(Fireplace, public=False, name_in_container='fireplace')
+

Modified: grok/trunk/src/grok/interfaces.py
===================================================================
--- grok/trunk/src/grok/interfaces.py	2007-01-07 15:50:16 UTC (rev 71775)
+++ grok/trunk/src/grok/interfaces.py	2007-01-07 16:01:23 UTC (rev 71776)
@@ -93,7 +93,7 @@
         """
 
     def local_utility(factory, provides=None, name=u'',
-                      setup=None, hidden=True, name_in_container=None):
+                      setup=None, public=False, name_in_container=None):
         """Register a local utility.
 
         factory - the factory that creates the local utility
@@ -101,8 +101,9 @@
         name - the name of the utility
         setup - a callable that receives the utility as its single argument,
                 it is called after the utility has been created and stored
-        hidden - if True, the utility will be stored below ++etc++site
-                 if False, the utility will be stored directly in the site
+        public - if False, the utility will be stored below ++etc++site
+                 if True, the utility will be stored directly in the site.
+                 The site should in this case be a container.
         name_in_container - the name to use for storing the utility
         """
 

Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2007-01-07 15:50:16 UTC (rev 71775)
+++ grok/trunk/src/grok/meta.py	2007-01-07 16:01:23 UTC (rev 71776)
@@ -353,7 +353,7 @@
             site_manager = site.getSiteManager()
             
             # store utility
-            if info.hidden:
+            if not info.public:
                 container = site_manager['default']
             else:
                 container = site



More information about the Checkins mailing list