[Checkins] SVN: grok/branches/philikon-grokcore.component/ Move the grokking facility (grok.grok() and <grok:grok />) out of grok into

Philipp von Weitershausen philikon at philikon.de
Sat Aug 25 09:27:59 EDT 2007


Log message for revision 79254:
  Move the grokking facility (grok.grok() and <grok:grok />) out of grok into
  grokcore.grok.  This is so that other packages that want to grok stuff from
  Python or ZCML can use this functioanlity too, without having to depend on
  grok.
  

Changed:
  _U  grok/branches/philikon-grokcore.component/grokcore.grok/
  A   grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/__init__.py
  A   grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/meta.zcml
  A   grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/zcml.py
  U   grok/branches/philikon-grokcore.component/grokcore.grok/setup.py
  U   grok/branches/philikon-grokcore.component/src/grok/__init__.py
  D   grok/branches/philikon-grokcore.component/src/grok/_grok.py
  U   grok/branches/philikon-grokcore.component/src/grok/meta.py
  D   grok/branches/philikon-grokcore.component/src/grok/meta.zcml
  A   grok/branches/philikon-grokcore.component/src/grok/meta.zcml
  D   grok/branches/philikon-grokcore.component/src/grok/zcml.py

-=-

Property changes on: grok/branches/philikon-grokcore.component/grokcore.grok
___________________________________________________________________
Name: svn:ignore
   + grokcore.grok.egg-info


Copied: grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/__init__.py (from rev 79200, grok/branches/philikon-grokcore.component/src/grok/_grok.py)
===================================================================
--- grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/__init__.py	                        (rev 0)
+++ grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/__init__.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# 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 sys
+import martian.scan
+
+from zope import component
+from zope.component.interfaces import IDefaultViewName
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.testing.cleanup import addCleanUp
+
+
+def grok(dotted_name):
+    martian.grok_dotted_name(dotted_name, the_module_grokker)
+
+def grok_component(name, component,
+                   context=None, module_info=None, templates=None):
+    return the_multi_grokker.grok(name, component,
+                                  context=context,
+                                  module_info=module_info,
+                                  templates=templates)
+
+
+# The prepare hooks are executed before a module is grokked.
+# Likewise, the finalize hooks are executed when a module has been
+# grokked.
+
+_prepare_hooks = set()
+_finalize_hooks = set()
+
+addPrepareHook = _prepare_hooks.add
+addFinalizeHook = _finalize_hooks.add
+
+def prepare(name, module, kw):
+    module_info = martian.scan.module_info_from_module(module)
+    kw['module_info'] = module_info
+
+    for hook in _prepare_hooks:
+        hook(name, module, kw)
+
+def finalize(name, module, kw):
+    for hook in _finalize_hooks:
+        hook(name, module, kw)
+
+# global grokkers
+the_multi_grokker = martian.MetaMultiGrokker()
+the_module_grokker = martian.ModuleGrokker(the_multi_grokker,
+                                           prepare=prepare,
+                                           finalize=finalize)
+
+ at addCleanUp
+def resetGrokker():
+    the_module_grokker.clear()

Copied: grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/meta.zcml (from rev 79126, grok/branches/philikon-grokcore.component/src/grok/meta.zcml)
===================================================================
--- grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/meta.zcml	                        (rev 0)
+++ grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/meta.zcml	2007-08-25 13:27:59 UTC (rev 79254)
@@ -0,0 +1,12 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directives namespace="http://namespaces.zope.org/grok">
+    <meta:directive
+        name="grok"
+        schema=".zcml.IGrokDirective"
+        handler=".zcml.grokDirective"
+        />
+  </meta:directives>
+</configure>

Copied: grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/zcml.py (from rev 79126, grok/branches/philikon-grokcore.component/src/grok/zcml.py)
===================================================================
--- grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/zcml.py	                        (rev 0)
+++ grok/branches/philikon-grokcore.component/grokcore.grok/grokcore/grok/zcml.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# Copyright (c) 2006-2007 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 ZCML directives."""
+
+from zope import interface
+import zope.configuration.fields
+
+import grokcore.grok
+
+class IGrokDirective(interface.Interface):
+    """Grok a package or module."""
+
+    package = zope.configuration.fields.GlobalObject(
+        title=u"Package",
+        description=u"The package or module to be analyzed by grok.",
+        required=False,
+        )
+
+
+def grokDirective(_context, package):
+    _context.action(
+        discriminator=('grok', package.__name__),
+        callable=grokcore.grok.grok,
+        args=(package.__name__,)
+        )

Modified: grok/branches/philikon-grokcore.component/grokcore.grok/setup.py
===================================================================
--- grok/branches/philikon-grokcore.component/grokcore.grok/setup.py	2007-08-25 13:16:10 UTC (rev 79253)
+++ grok/branches/philikon-grokcore.component/grokcore.grok/setup.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -32,5 +32,6 @@
     install_requires=['setuptools',
                       'martian',
                       'zope.configuration',
+                      'zope.testing',
                       ],
 )

Modified: grok/branches/philikon-grokcore.component/src/grok/__init__.py
===================================================================
--- grok/branches/philikon-grokcore.component/src/grok/__init__.py	2007-08-25 13:16:10 UTC (rev 79253)
+++ grok/branches/philikon-grokcore.component/src/grok/__init__.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -39,11 +39,10 @@
 from grok.directive import (context, name, title, template, templatedir,
                             provides, baseclass, global_utility, local_utility,
                             permissions, require, site)
-from grok._grok import do_grok as grok  # Avoid name clash within _grok
-from grok._grok import grok_component
 from grok.formlib import action, AutoFields, Fields
 from grok.util import url
 
+from grokcore.grok import grok, grok_component
 from grokcore.component import Adapter, MultiAdapter, GlobalUtility
 from grokcore.component import subscribe, adapter, implementer
 from martian.error import GrokError, GrokImportError

Deleted: grok/branches/philikon-grokcore.component/src/grok/_grok.py
===================================================================
--- grok/branches/philikon-grokcore.component/src/grok/_grok.py	2007-08-25 13:16:10 UTC (rev 79253)
+++ grok/branches/philikon-grokcore.component/src/grok/_grok.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -1,88 +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
-"""
-from zope import component
-from zope.component.interfaces import IDefaultViewName
-from zope.publisher.interfaces.browser import IBrowserRequest
-
-import martian
-from martian import scan
-from martian.error import GrokError
-from martian.util import determine_module_context
-
-import grok
-import grokcore.component.grokkers
-from grok import components, meta, templatereg
-
-_bootstrapped = False
-def bootstrap():
-    # now grok the grokkers
-    martian.grok_module(scan.module_info_from_module(meta), the_module_grokker)
-    martian.grok_module(scan.module_info_from_module(grokcore.component.grokkers),
-                        the_module_grokker)
-
-# 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 do_grok(dotted_name):
-    global _bootstrapped
-    if not _bootstrapped:
-        bootstrap()
-        _bootstrapped = True
-    martian.grok_dotted_name(dotted_name, the_module_grokker)
-
-def grok_component(name, component,
-                   context=None, module_info=None, templates=None):
-    return the_multi_grokker.grok(name, component,
-                                  context=context,
-                                  module_info=module_info,
-                                  templates=templates)
-
-def prepare_grok(name, module, kw):
-    module_info = scan.module_info_from_module(module)
-
-    # XXX hardcoded in here which base classes are possible contexts
-    # this should be made extensible
-    possible_contexts = martian.scan_for_classes(module, [grok.Model,
-                                                          grok.Container])
-    context = determine_module_context(module_info, possible_contexts)
-
-    kw['context'] = context
-    kw['module_info'] = module_info
-    kw['templates'] = templatereg.TemplateRegistry()
-
-def finalize_grok(name, module, kw):
-    module_info = kw['module_info']
-    templates = kw['templates']
-    unassociated = list(templates.listUnassociated())
-    if unassociated:
-        raise GrokError("Found the following unassociated template(s) when "
-                        "grokking %r: %s.  Define view classes inheriting "
-                        "from grok.View to enable the template(s)."
-                        % (module_info.dotted_name,
-                           ', '.join(unassociated)), module_info)
-
-the_multi_grokker = martian.MetaMultiGrokker()
-the_module_grokker = martian.ModuleGrokker(the_multi_grokker,
-                                           prepare=prepare_grok,
-                                           finalize=finalize_grok)

Modified: grok/branches/philikon-grokcore.component/src/grok/meta.py
===================================================================
--- grok/branches/philikon-grokcore.component/src/grok/meta.py	2007-08-25 13:16:10 UTC (rev 79253)
+++ grok/branches/philikon-grokcore.component/src/grok/meta.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -40,15 +40,41 @@
 
 from zope.exceptions.interfaces import DuplicationError
 
-import martian
+import martian.scan
 from martian.error import GrokError
 from martian import util
 
 import grok
-from grok import components, formlib
+from grok import components, formlib, templatereg
 from grok.util import get_default_permission, make_checker
 
+import grokcore.grok
 
+ at grokcore.grok.addPrepareHook
+def prepare_grok(name, module, kw):
+    # XXX hardcoded in here which base classes are possible contexts
+    # this should be made extensible
+    possible_contexts = martian.scan_for_classes(module, [grok.Model,
+                                                          grok.Container])
+    module_info = martian.scan.module_info_from_module(module)
+    context = util.determine_module_context(module_info, possible_contexts)
+    kw['context'] = context
+
+    kw['templates'] = templatereg.TemplateRegistry()
+
+ at grokcore.grok.addFinalizeHook
+def finalize_grok(name, module, kw):
+    module_info = kw['module_info']
+    templates = kw['templates']
+    unassociated = list(templates.listUnassociated())
+    if unassociated:
+        raise GrokError("Found the following unassociated template(s) when "
+                        "grokking %r: %s.  Define view classes inheriting "
+                        "from grok.View to enable the template(s)."
+                        % (module_info.dotted_name,
+                           ', '.join(unassociated)), module_info)
+
+
 class ModelGrokker(martian.ClassGrokker):
     component_class = grok.Model
 

Deleted: grok/branches/philikon-grokcore.component/src/grok/meta.zcml
===================================================================
--- grok/branches/philikon-grokcore.component/src/grok/meta.zcml	2007-08-25 13:16:10 UTC (rev 79253)
+++ grok/branches/philikon-grokcore.component/src/grok/meta.zcml	2007-08-25 13:27:59 UTC (rev 79254)
@@ -1,13 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    xmlns:meta="http://namespaces.zope.org/meta">
-
-  <meta:directives namespace="http://namespaces.zope.org/grok">
-    <meta:directive
-        name="grok"
-        schema=".zcml.IGrokDirective"
-        handler=".zcml.grokDirective"
-        />
-  </meta:directives>
-</configure>
-  
\ No newline at end of file

Added: grok/branches/philikon-grokcore.component/src/grok/meta.zcml
===================================================================
--- grok/branches/philikon-grokcore.component/src/grok/meta.zcml	                        (rev 0)
+++ grok/branches/philikon-grokcore.component/src/grok/meta.zcml	2007-08-25 13:27:59 UTC (rev 79254)
@@ -0,0 +1,3 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+  <include package="grokcore.grok" file="meta.zcml" />
+</configure>


Property changes on: grok/branches/philikon-grokcore.component/src/grok/meta.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: grok/branches/philikon-grokcore.component/src/grok/zcml.py
===================================================================
--- grok/branches/philikon-grokcore.component/src/grok/zcml.py	2007-08-25 13:16:10 UTC (rev 79253)
+++ grok/branches/philikon-grokcore.component/src/grok/zcml.py	2007-08-25 13:27:59 UTC (rev 79254)
@@ -1,33 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006-2007 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 ZCML directives."""
-
-from zope import interface
-import zope.configuration.fields
-
-import grok
-
-
-class IGrokDirective(interface.Interface):
-    """Grok a package or module."""
-
-    package = zope.configuration.fields.GlobalObject(
-        title=u"Package",
-        description=u"The package or module to be analyzed by grok.",
-        required=False,
-        )
-
-
-def grokDirective(_context, package):
-    grok.grok(package.__name__)



More information about the Checkins mailing list