[Checkins] SVN: grok/branches/gotcha-configuration-actions/src/grok/ Split decorators away from _grok, making _grok smaller.

Philipp von Weitershausen philikon at philikon.de
Tue Oct 9 10:28:39 EDT 2007


Log message for revision 80741:
  Split decorators away from _grok, making _grok smaller.
  

Changed:
  U   grok/branches/gotcha-configuration-actions/src/grok/__init__.py
  U   grok/branches/gotcha-configuration-actions/src/grok/_grok.py
  A   grok/branches/gotcha-configuration-actions/src/grok/decorators.py

-=-
Modified: grok/branches/gotcha-configuration-actions/src/grok/__init__.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/__init__.py	2007-10-09 14:04:42 UTC (rev 80740)
+++ grok/branches/gotcha-configuration-actions/src/grok/__init__.py	2007-10-09 14:28:38 UTC (rev 80741)
@@ -42,8 +42,7 @@
                             permissions, require, site, layer)
 from grok._grok import do_grok as grok  # Avoid name clash within _grok
 from grok._grok import grok_component
-from grok._grok import SubscribeDecorator as subscribe
-from grok._grok import adapter, implementer
+from grok.decorators import subscribe, adapter, implementer
 from martian.error import GrokError, GrokImportError
 
 from grok.formlib import action, AutoFields, Fields

Modified: grok/branches/gotcha-configuration-actions/src/grok/_grok.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/_grok.py	2007-10-09 14:04:42 UTC (rev 80740)
+++ grok/branches/gotcha-configuration-actions/src/grok/_grok.py	2007-10-09 14:28:38 UTC (rev 80741)
@@ -14,8 +14,6 @@
 """Grok
 """
 import os
-import sys
-import types
 
 from zope import component
 from zope import interface
@@ -26,8 +24,8 @@
 
 import martian
 from martian import scan
-from martian.error import GrokError, GrokImportError
-from martian.util import frame_is_module, determine_module_context
+from martian.error import GrokError
+from martian.util import determine_module_context
 
 import grok
 
@@ -128,52 +126,3 @@
 the_module_grokker = martian.ModuleGrokker(the_multi_grokker,
                                            prepare=prepare_grok,
                                            finalize=finalize_grok)
-
-# decorators
-class SubscribeDecorator:
-
-    def __init__(self, *args):
-        self.subscribed = args
-
-    def __call__(self, function):
-        frame = sys._getframe(1)
-        if not frame_is_module(frame):
-            raise GrokImportError("@grok.subscribe can only be used on module "
-                                  "level.")
-
-        if not self.subscribed:
-            raise GrokImportError("@grok.subscribe requires at least one "
-                                  "argument.")
-
-        subscribers = frame.f_locals.get('__grok_subscribers__', None)
-        if subscribers is None:
-            frame.f_locals['__grok_subscribers__'] = subscribers = []
-        subscribers.append((function, self.subscribed))
-        return function
-
-from zope.component._declaration import adapter as _adapter
-class adapter(_adapter):
-
-    def __init__(self, *interfaces):
-        # Override the z.c.adapter decorator to force sanity checking
-        # and have better error reporting.
-        if not interfaces:
-            raise GrokImportError(
-                "@grok.adapter requires at least one argument.")
-        if type(interfaces[0]) is types.FunctionType:
-            raise GrokImportError(
-                "@grok.adapter requires at least one argument.")
-        self.interfaces = interfaces
-
-from zope.interface.declarations import implementer as _implementer
-class implementer(_implementer):
-
-    def __call__(self, ob):
-        # XXX we do not have function grokkers (yet) so we put the annotation
-        # on the module.
-        frame = sys._getframe(1)
-        implementers = frame.f_locals.get('__implementers__', None)
-        if implementers is None:
-            frame.f_locals['__implementers__'] = implementers = []
-        implementers.append(ob)
-        return _implementer.__call__(self, ob)

Copied: grok/branches/gotcha-configuration-actions/src/grok/decorators.py (from rev 80737, grok/branches/gotcha-configuration-actions/src/grok/_grok.py)
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/decorators.py	                        (rev 0)
+++ grok/branches/gotcha-configuration-actions/src/grok/decorators.py	2007-10-09 14:28:38 UTC (rev 80741)
@@ -0,0 +1,67 @@
+##############################################################################
+#
+# 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 types
+from zope.component._declaration import adapter as _adapter
+from zope.interface.declarations import implementer as _implementer
+from martian.util import frame_is_module
+from martian.error import GrokImportError
+
+class subscribe:
+
+    def __init__(self, *args):
+        self.subscribed = args
+
+    def __call__(self, function):
+        frame = sys._getframe(1)
+        if not frame_is_module(frame):
+            raise GrokImportError("@grok.subscribe can only be used on module "
+                                  "level.")
+
+        if not self.subscribed:
+            raise GrokImportError("@grok.subscribe requires at least one "
+                                  "argument.")
+
+        subscribers = frame.f_locals.get('__grok_subscribers__', None)
+        if subscribers is None:
+            frame.f_locals['__grok_subscribers__'] = subscribers = []
+        subscribers.append((function, self.subscribed))
+        return function
+
+class adapter(_adapter):
+
+    def __init__(self, *interfaces):
+        # Override the z.c.adapter decorator to force sanity checking
+        # and have better error reporting.
+        if not interfaces:
+            raise GrokImportError(
+                "@grok.adapter requires at least one argument.")
+        if type(interfaces[0]) is types.FunctionType:
+            raise GrokImportError(
+                "@grok.adapter requires at least one argument.")
+        self.interfaces = interfaces
+
+class implementer(_implementer):
+
+    def __call__(self, ob):
+        # XXX we do not have function grokkers (yet) so we put the annotation
+        # on the module.
+        frame = sys._getframe(1)
+        implementers = frame.f_locals.get('__implementers__', None)
+        if implementers is None:
+            frame.f_locals['__implementers__'] = implementers = []
+        implementers.append(ob)
+        return _implementer.__call__(self, ob)



More information about the Checkins mailing list