[Checkins] SVN: grok/trunk/ Grok now use grokcore.site instead of its own local site implementation.
Sylvain Viollon
sylvain at infrae.com
Fri Sep 18 07:51:16 EDT 2009
Log message for revision 104306:
Grok now use grokcore.site instead of its own local site implementation.
Changed:
U grok/trunk/setup.py
U grok/trunk/src/grok/__init__.py
U grok/trunk/src/grok/components.py
U grok/trunk/src/grok/configure.zcml
U grok/trunk/src/grok/directive.py
U grok/trunk/src/grok/interfaces.py
U grok/trunk/src/grok/meta.py
U grok/trunk/src/grok/meta.zcml
U grok/trunk/src/grok/testing.py
U grok/trunk/versions.cfg
-=-
Modified: grok/trunk/setup.py
===================================================================
--- grok/trunk/setup.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/setup.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -40,6 +40,7 @@
'grokcore.component >= 1.5, < 2.0',
'grokcore.formlib >= 1.4',
'grokcore.security >= 1.1',
+ 'grokcore.site',
'grokcore.view >= 1.12',
'grokcore.viewlet >= 1.3',
'simplejson',
Modified: grok/trunk/src/grok/__init__.py
===================================================================
--- grok/trunk/src/grok/__init__.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/__init__.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -51,6 +51,10 @@
from grokcore.annotation import Annotation
+from grokcore.site import LocalUtility
+from grokcore.site import Site
+from grokcore.site import local_utility
+
from zope.event import notify
from zope.app.component.hooks import getSite
from zope.lifecycleevent import (
@@ -77,14 +81,13 @@
from grok.components import XMLRPC, REST, JSON
from grok.components import Traverser
from grok.components import Container, OrderedContainer
-from grok.components import Site, LocalUtility
from grok.components import Application, Form, AddForm, EditForm, DisplayForm
from grok.components import Indexes
from grok.components import Role
from grok.interfaces import IRESTSkinType, IRESTLayer
from grok.directive import (
- local_utility, permissions, site, restskin, traversable)
+ permissions, site, restskin, traversable)
# BBB These two functions are meant for test fixtures and should be
# imported from grok.testing, not from grok.
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/components.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -35,18 +35,17 @@
from zope.app.publisher.browser import getDefaultViewName
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
-from zope.app.container.interfaces import IReadContainer, IObjectAddedEvent
+from zope.app.container.interfaces import IReadContainer
from zope.app.container.interfaces import IOrderedContainer
from zope.app.container.contained import notifyContainerModified
from persistent.list import PersistentList
-from zope.app.component.site import SiteManagerContainer
-from zope.app.component.site import LocalSiteManager
import grok
import z3c.flashmessage.interfaces
import martian.util
import grokcore.view
+import grokcore.site
from grok import interfaces, util
@@ -150,35 +149,7 @@
notifyContainerModified(self)
-class Site(SiteManagerContainer):
- """Mixin for creating sites in Grok applications.
-
- When an application `grok.Model` or `grok.Container` also inherits
- from `grok.Site`, then it can additionally support the registration
- of local Component Architecture entities like `grok.LocalUtility`
- and `grok.Indexes` objects; see those classes for more information.
-
- """
-
-
- at component.adapter(Site, IObjectAddedEvent)
-def addSiteHandler(site, event):
- """Add a local site manager to a Grok site object upon its creation.
-
- Grok registers this function so that it gets called each time a
- `grok.Site` instance is added to a container. It creates a local
- site manager and installs it on the newly created site.
-
- """
- sitemanager = LocalSiteManager(site)
- # LocalSiteManager creates the 'default' folder in its __init__.
- # It's not needed anymore in new versions of Zope 3, therefore we
- # remove it
- del sitemanager['default']
- site.setSiteManager(sitemanager)
-
-
-class Application(Site):
+class Application(grokcore.site.Site):
"""Mixin for creating Grok application objects.
When a `grok.Container` (or a `grok.Model`, though most developers
@@ -192,25 +163,6 @@
interface.implements(interfaces.IApplication)
-class LocalUtility(Model):
- """The base class for local utilities in Grok applications.
-
- Although application developers can create local utilies without
- actually subclassing `grok.LocalUtility`, they gain three benefits
- from doing so. First, their code is more readable because their
- classes "look like" local utilities to casual readers. Second,
- their utility will know how to persist itself to the Zope database,
- which means that they can set its object attributes and know that
- the values are getting automatically saved. Third, they can omit
- the `grok.provides()` directive naming the interface that the
- utility provides, if their class only `grok.implements()` a single
- interface (unless the interface is one that the `grok.LocalUtility`
- already implements, in which case Grok cannot tell them apart, and
- `grok.provides()` must be used explicitly anyway).
-
- """
-
-
class View(grokcore.view.View):
"""The base class for views with templates in Grok applications.
Modified: grok/trunk/src/grok/configure.zcml
===================================================================
--- grok/trunk/src/grok/configure.zcml 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/configure.zcml 2009-09-18 11:51:15 UTC (rev 104306)
@@ -30,6 +30,7 @@
<include package="grokcore.viewlet" />
<include package="grokcore.formlib" />
<include package="grokcore.annotation" />
+ <include package="grokcore.site" />
<securityPolicy
component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
@@ -42,8 +43,6 @@
name="index"
/>
- <subscriber handler=".components.addSiteHandler" />
-
<!-- we register a ++rest++ traversal namespace -->
<adapter
factory=".rest.rest_skin"
Modified: grok/trunk/src/grok/directive.py
===================================================================
--- grok/trunk/src/grok/directive.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/directive.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -13,14 +13,14 @@
##############################################################################
"""Grok directives.
-This module defines Grok directives: the markers that users place inside
-of their classes (and sometimes in their modules, too) to direct how
-Grok registers their components. For example, the first directive
-defined below is `local_utility`, which people programming Grok
+This module defines Grok directives: the markers that users place
+inside of their classes (and sometimes in their modules, too) to
+direct how Grok registers their components. For example, the first
+directive defined below is `site`, which people programming Grok
applications normally use like this::
- class MyUtility(grok.Utility):
- grok.local_utility()
+ class MyIndex(grok.Indexes):
+ grok.site(MySite)
...
If the set of directives in this module looks rather small, remember
@@ -29,124 +29,11 @@
that other projects can use them without having to pull in all of Grok.
"""
-import grok
-from zope import interface
-from zope.interface.interfaces import IInterface
import martian
-from martian import util
-from martian.error import GrokImportError
from grokcore.view.directive import TaggedValueStoreOnce
-class local_utility(martian.Directive):
- """The `grok.local_utility()` directive.
- Place this directive inside of a `grok.Application` or `grok.Site`
- subclass, and provide the name of a utility you want activated
- inside of that site::
-
- class MySite(grok.Site):
- grok.local_utility(MyMammothUtility)
- ...
-
- This directive can be supplied several times within the same site.
- Thanks to the presence of this directive, any time an instance of
- your class is created in the Zope database it will have a copy of
- the given local utility installed along with it.
-
- This directive accepts several normal Component-registration keyword
- arguments, like `provides` and `name`, and uses them each time it
- registers your local utility.
-
- If you do not supply a `provides` keyword, then Grok attempts to
- guess a sensible default. Its first choice is to use any
- interface(s) that you listed with the grok.provides() directive when
- defining your utility. Otherwise, if your utility is a subclass of
- `grok.localUtility`, then Grok will use any interfaces that your
- utility supplies beyond those are supplied because of its
- inheritance from `grok.localUtility`. Else, as a final fallback, it
- checks to see whether the class you are registering supplies one,
- and only one, interface; if so, then it can register the utility
- unambiguously as providing that one interface.
-
- """
- scope = martian.CLASS
- store = martian.DICT
-
- def factory(self, factory, provides=None, name=u'',
- 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)
-
- if provides is None:
- provides = grok.provides.bind().get(factory)
-
- if provides is None:
- if util.check_subclass(factory, grok.LocalUtility):
- baseInterfaces = interface.implementedBy(grok.LocalUtility)
- utilityInterfaces = interface.implementedBy(factory)
- provides = list(utilityInterfaces - baseInterfaces)
-
- if len(provides) == 0 and len(list(utilityInterfaces)) > 0:
- raise GrokImportError(
- "Cannot determine which interface to use "
- "for utility registration of %r. "
- "It implements an interface that is a specialization "
- "of an interface implemented by grok.LocalUtility. "
- "Specify the interface by either using grok.provides "
- "on the utility or passing 'provides' to "
- "grok.local_utility." % factory, factory)
- else:
- provides = list(interface.implementedBy(factory))
-
- util.check_implements_one_from_list(provides, factory)
- provides = provides[0]
-
- if (provides, name) in self.frame.f_locals.get(self.dotted_name(), {}):
- raise GrokImportError(
- "Conflicting local utility registration %r. "
- "Local utilities are registered multiple "
- "times for interface %r and name %r." %
- (factory, provides, name), factory)
-
- info = LocalUtilityInfo(factory, provides, name, setup, public,
- name_in_container)
- return (provides, name), info
-
-
-class LocalUtilityInfo(object):
- """The information about how to register a local utility.
-
- An instance of this class is created for each `grok.local_utility()`
- in a Grok application's code, to remember how the user wants their
- local utility registered. Later, whenever the application creates
- new instances of the site or application for which the local utility
- directive was supplied, this block of information is used as the
- parameters to the creation of the local utility which is created
- along with the new site in the Zope database.
-
- """
- _order = 0
-
- def __init__(self, factory, provides, name=u'',
- setup=None, public=False, name_in_container=None):
- self.factory = factory
- self.provides = provides
- self.name = name
- self.setup = setup
- self.public = public
- self.name_in_container = name_in_container
-
- self.order = LocalUtilityInfo._order
- LocalUtilityInfo._order += 1
-
- def __cmp__(self, other):
- # LocalUtilityInfos have an inherit sort order by which the
- # registrations take place.
- return cmp(self.order, other.order)
-
-
class site(martian.Directive):
"""The `grok.site()` directive.
Modified: grok/trunk/src/grok/interfaces.py
===================================================================
--- grok/trunk/src/grok/interfaces.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/interfaces.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -23,6 +23,7 @@
import grokcore.component.interfaces
import grokcore.formlib.interfaces
import grokcore.security.interfaces
+import grokcore.site.interfaces
import grokcore.view.interfaces
import grokcore.viewlet.interfaces
@@ -33,14 +34,13 @@
class IGrokBaseClasses(grokcore.annotation.interfaces.IBaseClasses,
grokcore.component.interfaces.IBaseClasses,
grokcore.security.interfaces.IBaseClasses,
+ grokcore.site.interfaces.IBaseClasses,
grokcore.view.interfaces.IBaseClasses):
Model = interface.Attribute("Base class for persistent content objects "
"(models).")
Container = interface.Attribute("Base class for containers.")
OrderedContainer = interface.Attribute("Base class for ordered containers.")
- Site = interface.Attribute("Mixin class for sites.")
Application = interface.Attribute("Base class for applications.")
- LocalUtility = interface.Attribute("Base class for local utilities.")
XMLRPC = interface.Attribute("Base class for XML-RPC methods.")
JSON = interface.Attribute("Base class for JSON methods.")
REST = interface.Attribute("Base class for REST views.")
@@ -51,23 +51,9 @@
class IGrokDirectives(grokcore.component.interfaces.IDirectives,
grokcore.security.interfaces.IDirectives,
+ grokcore.site.interfaces.IDirectives,
grokcore.view.interfaces.IDirectives):
- def local_utility(factory, provides=None, name=u'',
- setup=None, public=False, name_in_container=None):
- """Register a local utility.
-
- factory - the factory that creates the local utility
- provides - the interface the utility should be looked up with
- 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
- 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
- """
-
def permissions(permissions):
"""Specify the permissions that comprise a role.
"""
@@ -112,10 +98,11 @@
IBeforeTraverseEvent = interface.Attribute("")
-class IGrokAPI(grokcore.security.interfaces.IGrokcoreSecurityAPI,
+class IGrokAPI(grokcore.formlib.interfaces.IGrokcoreFormlibAPI,
+ grokcore.security.interfaces.IGrokcoreSecurityAPI,
+ grokcore.site.interfaces.IGrokcoreSiteAPI,
grokcore.view.interfaces.IGrokcoreViewAPI,
grokcore.viewlet.interfaces.IGrokcoreViewletAPI,
- grokcore.formlib.interfaces.IGrokcoreFormlibAPI,
IGrokBaseClasses, IGrokDirectives,
IGrokEvents, IGrokErrors):
Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/meta.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -33,8 +33,6 @@
from zope.securitypolicy.rolepermission import rolePermissionManager
from zope.app.publisher.xmlrpc import MethodPublisher
-from zope.app.container.interfaces import IContainer
-from zope.app.container.interfaces import INameChooser
from zope.app.intid import IntIds
from zope.app.intid.interfaces import IIntIds
@@ -45,13 +43,13 @@
import martian
from martian.error import GrokError
-from martian import util
import grok
from grok import components
from grok.util import make_checker
from grok.interfaces import IRESTSkinType
+import grokcore.site.interfaces
from grokcore.security.meta import PermissionGrokker
from grokcore.view.meta.views import default_fallback_to_name
@@ -246,92 +244,6 @@
return True
-class SiteGrokker(martian.ClassGrokker):
- """Grokker for subclasses of `grok.Site`."""
- martian.component(grok.Site)
- martian.priority(500)
- martian.directive(grok.local_utility, name='infos')
-
- def execute(self, factory, config, infos, **kw):
- if not infos:
- return False
-
- infos = infos.values()
- for info in infos:
- if info.public and not IContainer.implementedBy(factory):
- raise GrokError(
- "Cannot set public to True with grok.local_utility as "
- "the site (%r) is not a container." %
- factory, factory)
-
- # Store the list of info objects in their "natural" order on the
- # site class. They will be picked up by a subscriber doing the
- # actual registrations in definition order.
- factory.__grok_utilities_to_install__ = sorted(infos)
- adapts = (factory, grok.IObjectAddedEvent)
-
- config.action(
- discriminator=None,
- callable=component.provideHandler,
- args=(localUtilityRegistrationSubscriber, adapts),
- )
- return True
-
-
-def localUtilityRegistrationSubscriber(site, event):
- """A subscriber that fires to set up local utilities.
- """
- installed = getattr(site, '__grok_utilities_installed__', False)
- if installed:
- return
-
- for info in getattr(site.__class__, '__grok_utilities_to_install__', []):
- setupUtility(site, info.factory(), info.provides, name=info.name,
- name_in_container=info.name_in_container,
- public=info.public, setup=info.setup)
-
- # we are done. If this subscriber gets fired again, we therefore
- # do not register utilities anymore
- site.__grok_utilities_installed__ = True
-
-
-def setupUtility(site, utility, provides, name=u'',
- name_in_container=None, public=False, setup=None):
- """Set up a utility in a site.
-
- site - the site to set up the utility in
- utility - the utility to set up
- provides - the interface the utility should be registered with
- name - the name the utility should be registered under, default
- the empty string (no name)
- name_in_container - if given it will be used to add the utility
- object to its container. Otherwise a name will be made up
- public - if False, the utility will be stored in the site manager. If
- True, the utility will be storedin the site (it is assumed the
- site is a container)
- setup - if not None, it will be called with the utility as its first
- argument. This function can then be used to further set up the
- utility.
- """
- site_manager = site.getSiteManager()
-
- if not public:
- container = site_manager
- else:
- container = site
-
- if name_in_container is None:
- name_in_container = INameChooser(container).chooseName(
- utility.__class__.__name__, utility)
- container[name_in_container] = utility
-
- if setup is not None:
- setup(utility)
-
- site_manager.registerUtility(utility, provided=provides,
- name=name)
-
-
class RoleGrokker(martian.ClassGrokker):
"""Grokker for components subclassed from `grok.Role`.
@@ -469,6 +381,8 @@
if catalog is not None:
return catalog
catalog = Catalog()
+ setupUtility = component.getUtility(
+ grokcore.site.interfaces.IUtilityInstaller)
setupUtility(site, catalog, ICatalog, name=self.catalog_name)
return catalog
@@ -480,6 +394,8 @@
if intids is not None:
return intids
intids = IntIds()
+ setupUtility = component.getUtility(
+ grokcore.site.interfaces.IUtilityInstaller)
setupUtility(site, intids, IIntIds)
return intids
Modified: grok/trunk/src/grok/meta.zcml
===================================================================
--- grok/trunk/src/grok/meta.zcml 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/meta.zcml 2009-09-18 11:51:15 UTC (rev 104306)
@@ -12,6 +12,7 @@
<include package="grokcore.view" file="meta.zcml" />
<include package="grokcore.viewlet" file="meta.zcml" />
<include package="grokcore.annotation" file="meta.zcml" />
+ <include package="grokcore.site" file="meta.zcml" />
<grok:grok package=".meta" />
</configure>
Modified: grok/trunk/src/grok/testing.py
===================================================================
--- grok/trunk/src/grok/testing.py 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/src/grok/testing.py 2009-09-18 11:51:15 UTC (rev 104306)
@@ -48,6 +48,7 @@
zcml.do_grok('grokcore.viewlet.meta', config)
zcml.do_grok('grokcore.formlib.meta', config)
zcml.do_grok('grokcore.annotation.meta', config)
+ zcml.do_grok('grokcore.site.meta', config)
zcml.do_grok('grok.meta', config)
zcml.do_grok(module_name, config)
config.execute_actions()
Modified: grok/trunk/versions.cfg
===================================================================
--- grok/trunk/versions.cfg 2009-09-18 11:50:08 UTC (rev 104305)
+++ grok/trunk/versions.cfg 2009-09-18 11:51:15 UTC (rev 104306)
@@ -4,6 +4,7 @@
grokcore.component = 1.7
grokcore.formlib = 1.4
grokcore.security = 1.2
+grokcore.site = 1.1
grokcore.view = 1.12.2
grokcore.viewlet = 1.3
grokui.admin = 0.3.2
More information about the checkins
mailing list