[Checkins]
SVN: grok/branches/gotcha-configuration-actions/src/grok/
Move all the grokking stuff from _grok.py to zcml.py,
it's tightly integrated
Philipp von Weitershausen
philikon at philikon.de
Sat Oct 27 11:45:01 EDT 2007
Log message for revision 81129:
Move all the grokking stuff from _grok.py to zcml.py, it's tightly integrated
anyway.
Changed:
D grok/branches/gotcha-configuration-actions/src/grok/_grok.py
U grok/branches/gotcha-configuration-actions/src/grok/zcml.py
-=-
Deleted: grok/branches/gotcha-configuration-actions/src/grok/_grok.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/_grok.py 2007-10-27 09:51:10 UTC (rev 81128)
+++ grok/branches/gotcha-configuration-actions/src/grok/_grok.py 2007-10-27 15:45:01 UTC (rev 81129)
@@ -1,105 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Grok
-"""
-import os
-
-from zope import component
-from zope import interface
-
-from zope.component.interfaces import IDefaultViewName
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.configuration.config import ConfigurationMachine
-from zope.app.component.site import LocalSiteManager
-
-import martian
-from martian import scan
-from martian.error import GrokError
-
-import grok
-from grok import components, meta
-
-_bootstrapped = False
-def bootstrap():
- component.provideAdapter(components.ModelTraverser)
- component.provideAdapter(components.ContainerTraverser)
-
- # register the name 'index' as the default view name
- component.provideAdapter('index',
- adapts=(grok.Model, IBrowserRequest),
- provides=IDefaultViewName)
- component.provideAdapter('index',
- adapts=(grok.Container, IBrowserRequest),
- provides=IDefaultViewName)
- # register a subscriber for when grok.Sites are added to make them
- # into Zope 3 sites
- component.provideHandler(
- addSiteHandler, adapts=(grok.Site, grok.IObjectAddedEvent))
-
- # now grok the grokkers
- martian.grok_module(scan.module_info_from_module(meta), the_module_grokker)
-
-def addSiteHandler(site, event):
- 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)
-
-# add a cleanup hook so that grok will bootstrap itself again whenever
-# the Component Architecture is torn down.
-def resetBootstrap():
- global _bootstrapped
- # we need to make sure that the grokker registry is clean again
- the_module_grokker.clear()
- _bootstrapped = False
-from zope.testing.cleanup import addCleanUp
-addCleanUp(resetBootstrap)
-
-def skip_tests(name):
- return name in ['tests', 'ftests']
-
-def do_grok(dotted_name, config):
- global _bootstrapped
- if not _bootstrapped:
- bootstrap()
- _bootstrapped = True
- martian.grok_dotted_name(
- dotted_name, the_module_grokker, exclude_filter=skip_tests,
- config=config
- )
-
-def grok_component(name, component,
- context=None, module_info=None, templates=None):
- if module_info is None:
- obj_module = getattr(component, '__grok_module__', None)
- if obj_module is None:
- obj_module = getattr(component, '__module__', None)
- module_info = scan.module_info_from_dotted_name(obj_module)
-
- module = module_info.getModule()
- if context is not None:
- module.__grok_context__ = context
- if templates is not None:
- module.__grok_templates__ = templates
- config = ConfigurationMachine()
- result = the_multi_grokker.grok(name, component,
- module_info=module_info,
- config=config)
- config.execute_actions()
- return result
-
-the_multi_grokker = martian.MetaMultiGrokker()
-the_module_grokker = martian.ModuleGrokker(the_multi_grokker)
Modified: grok/branches/gotcha-configuration-actions/src/grok/zcml.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/zcml.py 2007-10-27 09:51:10 UTC (rev 81128)
+++ grok/branches/gotcha-configuration-actions/src/grok/zcml.py 2007-10-27 15:45:01 UTC (rev 81129)
@@ -16,7 +16,22 @@
from zope import interface
import zope.configuration.fields
+import os
+
+from zope import component
+from zope import interface
+
+from zope.component.interfaces import IDefaultViewName
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.configuration.config import ConfigurationMachine
+from zope.app.component.site import LocalSiteManager
+
+import martian
+from martian import scan
+from martian.error import GrokError
+
import grok
+from grok import components, meta
class IGrokDirective(interface.Interface):
@@ -28,7 +43,59 @@
required=False,
)
+_bootstrapped = False
+def bootstrap():
+ component.provideAdapter(components.ModelTraverser)
+ component.provideAdapter(components.ContainerTraverser)
+ # register the name 'index' as the default view name
+ component.provideAdapter('index',
+ adapts=(grok.Model, IBrowserRequest),
+ provides=IDefaultViewName)
+ component.provideAdapter('index',
+ adapts=(grok.Container, IBrowserRequest),
+ provides=IDefaultViewName)
+ # register a subscriber for when grok.Sites are added to make them
+ # into Zope 3 sites
+ component.provideHandler(
+ addSiteHandler, adapts=(grok.Site, grok.IObjectAddedEvent))
+
+ # now grok the grokkers
+ martian.grok_module(scan.module_info_from_module(meta), the_module_grokker)
+
+def addSiteHandler(site, event):
+ 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)
+
+# add a cleanup hook so that grok will bootstrap itself again whenever
+# the Component Architecture is torn down.
+def resetBootstrap():
+ global _bootstrapped
+ # we need to make sure that the grokker registry is clean again
+ the_module_grokker.clear()
+ _bootstrapped = False
+from zope.testing.cleanup import addCleanUp
+addCleanUp(resetBootstrap)
+
+the_multi_grokker = martian.MetaMultiGrokker()
+the_module_grokker = martian.ModuleGrokker(the_multi_grokker)
+
+def skip_tests(name):
+ return name in ['tests', 'ftests']
+
def grokDirective(_context, package):
- grok.grok(package.__name__, config=_context)
+ do_grok(package.__name__, _context)
+def do_grok(dotted_name, config):
+ global _bootstrapped
+ if not _bootstrapped:
+ bootstrap()
+ _bootstrapped = True
+ martian.grok_dotted_name(
+ dotted_name, the_module_grokker, exclude_filter=skip_tests,
+ config=config
+ )
More information about the Checkins
mailing list