[Checkins] SVN: grok/trunk/ Merged the philikon-methodgrokker branch.

Philipp von Weitershausen philikon at philikon.de
Thu May 29 06:48:19 EDT 2008


Log message for revision 87018:
  Merged the philikon-methodgrokker branch.
  

Changed:
  U   grok/trunk/src/grok/ftests/rest/rest.py
  U   grok/trunk/src/grok/meta.py
  U   grok/trunk/src/grok/rest.py
  U   grok/trunk/src/grok/tests/json/nocontext.py
  A   grok/trunk/src/grok/tests/json/nomethods.py
  U   grok/trunk/src/grok/tests/json/view_lookup.py
  U   grok/trunk/src/grok/tests/security/missing_permission_json3.py
  U   grok/trunk/src/grok/tests/security/missing_permission_xmlrpc3.py
  U   grok/trunk/src/grok/tests/test_grok.py
  D   grok/trunk/src/grok/tests/util/
  U   grok/trunk/src/grok/tests/xmlrpc/nocontext.py
  A   grok/trunk/src/grok/tests/xmlrpc/nomethods.py
  U   grok/trunk/src/grok/util.py
  U   grok/trunk/versions.cfg

-=-
Modified: grok/trunk/src/grok/ftests/rest/rest.py
===================================================================
--- grok/trunk/src/grok/ftests/rest/rest.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/ftests/rest/rest.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -371,6 +371,9 @@
     grok.layer(LayerC)
     grok.context(MyApp)
 
+    def some_method_thats_not_in_HTTP(self):
+        pass
+
 class DRest(grok.REST):
     grok.context(MyContent)
 

Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/meta.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -50,7 +50,6 @@
 import grok
 from grok import components, formlib, templatereg
 from grok.util import check_permission, make_checker
-from grok.util import public_methods_from_class
 from grok.interfaces import IRESTSkinType
 from grok.interfaces import IViewletManager as IGrokViewletManager
 
@@ -86,103 +85,64 @@
         return True
 
 
-class XMLRPCGrokker(martian.ClassGrokker):
+class XMLRPCGrokker(martian.MethodGrokker):
     component_class = grok.XMLRPC
     directives = [
         grok.context.bind(),
-        grok.require.bind(name='class_permission'),
+        grok.require.bind(name='permission'),
         ]
 
-    def execute(self, factory, config, class_permission, context, **kw):
-        methods = public_methods_from_class(factory)
+    def execute(self, factory, method, config, context, permission, **kw):
+        name = method.__name__
 
-        # make sure we issue an action to check whether this permission
-        # exists. That's the only thing that action does
-        if class_permission is not None:
-            config.action(
-                discriminator=None,
-                callable=check_permission,
-                args=(factory, class_permission)
-                )
+        # Make sure that the class inherits MethodPublisher, so that the
+        # views have a location
+        method_view = type(
+            factory.__name__, (factory, MethodPublisher),
+            {'__call__': method}
+            )
 
-        for method in methods:
-            name = method.__name__
-
-            # Make sure that the class inherits MethodPublisher, so that the
-            # views have a location
-            method_view = type(
-                factory.__name__, (factory, MethodPublisher),
-                {'__call__': method}
-                )
-
-            adapts = (context, IXMLRPCRequest)
-            config.action(
-                discriminator=('adapter', adapts, interface.Interface, name),
-                callable=component.provideAdapter,
-                args=(method_view, adapts, interface.Interface, name),
-                )
-
-            # Protect method_view with either the permission that was
-            # set on the method, the default permission from the class
-            # level or zope.Public.
-            permission = grok.require.bind().get(method)
-            if permission is None:
-                permission = class_permission
-
-            config.action(
-                discriminator=('protectName', method_view, '__call__'),
-                callable=make_checker,
-                args=(factory, method_view, permission),
-                )
+        adapts = (context, IXMLRPCRequest)
+        config.action(
+            discriminator=('adapter', adapts, interface.Interface, name),
+            callable=component.provideAdapter,
+            args=(method_view, adapts, interface.Interface, name),
+            )
+        config.action(
+            discriminator=('protectName', method_view, '__call__'),
+            callable=make_checker,
+            args=(factory, method_view, permission),
+            )
         return True
 
 
-class RESTGrokker(martian.ClassGrokker):
+class RESTGrokker(martian.MethodGrokker):
     component_class = grok.REST
     directives = [
         grok.context.bind(),
         grok.layer.bind(default=grok.IRESTLayer),
-        grok.require.bind(name='class_permission'),
+        grok.require.bind(name='permission'),
         ]
 
-    def execute(self, factory, config, class_permission, context, layer, **kw):
-        methods = public_methods_from_class(factory)
-        # make sure we issue an action to check whether this permission
-        # exists. That's the only thing that action does
-        if class_permission is not None:
-            config.action(
-                discriminator=None,
-                callable=check_permission,
-                args=(factory, class_permission)
-                )
+    def execute(self, factory, method, config, permission, context, layer, **kw):
+        name = method.__name__
 
-        for method in methods:
-            name = method.__name__
+        method_view = type(
+            factory.__name__, (factory,),
+            {'__call__': method }
+            )
 
-            method_view = type(
-                factory.__name__, (factory,),
-                {'__call__': method }
-                )
-
-            adapts = (context, layer)
-            config.action(
-                discriminator=('adapter', adapts, interface.Interface, name),
-                callable=component.provideAdapter,
-                args=(method_view, adapts, interface.Interface, name),
-                )
-
-            # Protect method_view with either the permission that was
-            # set on the method, the default permission from the class
-            # level or zope.Public.
-            permission = grok.require.bind().get(method)
-            if permission is None:
-                permission = class_permission
-
-            config.action(
-                discriminator=('protectName', method_view, '__call__'),
-                callable=make_checker,
-                args=(factory, method_view, permission),
-                )
+        adapts = (context, layer)
+        config.action(
+            discriminator=('adapter', adapts, interface.Interface, name),
+            callable=component.provideAdapter,
+            args=(method_view, adapts, interface.Interface, name),
+            )
+        config.action(
+            discriminator=('protectName', method_view, '__call__'),
+            callable=make_checker,
+            args=(factory, method_view, permission),
+            )
         return True
 
 
@@ -261,62 +221,35 @@
                                  has_render, has_no_render)
 
 
-class JSONGrokker(martian.ClassGrokker):
+class JSONGrokker(martian.MethodGrokker):
     component_class = grok.JSON
     directives = [
         grok.context.bind(),
-        grok.require.bind(name='class_permission'),
+        grok.require.bind(name='permission'),
         ]
 
     # TODO: this grokker doesn't support layers yet
 
-    def execute(self, factory, config, context, class_permission, **kw):
-        methods = public_methods_from_class(factory)
-        # make sure we issue an action to check whether this permission
-        # exists. That's the only thing that action does
-        if class_permission is not None:
-            config.action(
-                discriminator=None,
-                callable=check_permission,
-                args=(factory, class_permission)
-                )
+    def execute(self, factory, method, config, context, permission, **kw):
+        # Create a new class with a __view_name__ attribute so the
+        # JSON class knows what method to call.
+        method_view = type(
+            factory.__name__, (factory,),
+            {'__view_name__': method.__name__}
+            )
+        adapts = (context, IDefaultBrowserLayer)
+        name = method.__name__
 
-        for method in methods:
-            # The grok.JSON component inherits methods from its baseclass
-            # (being zope.publisher.browser.BrowserPage) with names that
-            # do not start with an underscore, but should still not
-            # be registered as views. Ignore these methods:
-            if method.__name__ in ['browserDefault', 'publishTraverse']:
-                continue
-
-            # Create a new class with a __view_name__ attribute so the
-            # JSON class knows what method to call.
-            method_view = type(
-                factory.__name__, (factory,),
-                {'__view_name__': method.__name__}
-                )
-            adapts = (context, IDefaultBrowserLayer)
-            name = method.__name__
-
-            config.action(
-                discriminator=('adapter', adapts, interface.Interface, name),
-                callable=component.provideAdapter,
-                args=(method_view, adapts, interface.Interface, name),
-                )
-
-            # Protect method_view with either the permission that was
-            # set on the method, the default permission from the class
-            # level or zope.Public.
-
-            permission = grok.require.bind().get(method)
-            if permission is None:
-                permission = class_permission
-
-            config.action(
-                discriminator=('protectName', method_view, '__call__'),
-                callable=make_checker,
-                args=(factory, method_view, permission),
-                )
+        config.action(
+            discriminator=('adapter', adapts, interface.Interface, name),
+            callable=component.provideAdapter,
+            args=(method_view, adapts, interface.Interface, name),
+            )
+        config.action(
+            discriminator=('protectName', method_view, '__call__'),
+            callable=make_checker,
+            args=(factory, method_view, permission),
+            )
         return True
 
 

Modified: grok/trunk/src/grok/rest.py
===================================================================
--- grok/trunk/src/grok/rest.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/rest.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -60,9 +60,6 @@
         applySkin(self.request, skin)
         return self.context
 
-class DefaultRest(grok.REST):
-    grok.context(Interface)
-    grok.layer(grok.IRESTLayer)
 
 class NotAllowedREST(grok.REST):
     """These are registered for everything by default to cause the correct

Modified: grok/trunk/src/grok/tests/json/nocontext.py
===================================================================
--- grok/trunk/src/grok/tests/json/nocontext.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/tests/json/nocontext.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -14,4 +14,6 @@
 import grok
 
 class TestJSON(grok.JSON):
-    pass
+
+    def foo(self):
+        pass

Copied: grok/trunk/src/grok/tests/json/nomethods.py (from rev 87017, grok/branches/philikon-methodgrokker/src/grok/tests/json/nomethods.py)
===================================================================
--- grok/trunk/src/grok/tests/json/nomethods.py	                        (rev 0)
+++ grok/trunk/src/grok/tests/json/nomethods.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -0,0 +1,16 @@
+"""
+  >>> grok.testing.grok(__name__)
+  Traceback (most recent call last):
+    ...
+  GrokError: <class 'grok.tests.json.nomethods.RemoteCaveman'> does not
+  define any public methods. Please add methods to this class to enable
+  its registration.
+
+"""
+import grok
+
+class Caveman(grok.Model):
+    pass
+
+class RemoteCaveman(grok.JSON):
+    pass

Modified: grok/trunk/src/grok/tests/json/view_lookup.py
===================================================================
--- grok/trunk/src/grok/tests/json/view_lookup.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/tests/json/view_lookup.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -31,8 +31,9 @@
   <zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>),
   <InterfaceClass zope.interface.Interface>, '_private')
 
-Even more important, special methods like __call__ are not registered as viewws
-too. This test is here to make sure a previous bug has been fixed::
+Even more important, special methods like __call__ are not registered
+as views either. This test is here to make sure a previous bug has
+been fixed::
 
   >>> view = getMultiAdapter((mammoth, request), name='__call__')
   Traceback (most recent call last):
@@ -78,3 +79,6 @@
 
     def _private(self):
         return {'should': 'not be registered'}
+
+    def public(self):
+        return {'will': 'be registered'}

Modified: grok/trunk/src/grok/tests/security/missing_permission_json3.py
===================================================================
--- grok/trunk/src/grok/tests/security/missing_permission_json3.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/tests/security/missing_permission_json3.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -1,12 +1,8 @@
 """
-Make sure we get an error for a missing permission even if that permission
-isn't actually used (as there are more specific permissions)::
+An undefined permission that's never used (because it's being shadowed
+by a method-level directive) doesn't raise an error:
 
   >>> grok.testing.grok(__name__)
-  Traceback (most recent call last):
-    ...
-  ConfigurationExecutionError: martian.error.GrokError: Undefined permission
-  'doesnt.exist' in ...
 
 """
 

Modified: grok/trunk/src/grok/tests/security/missing_permission_xmlrpc3.py
===================================================================
--- grok/trunk/src/grok/tests/security/missing_permission_xmlrpc3.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/tests/security/missing_permission_xmlrpc3.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -1,13 +1,10 @@
 """
-A permission has to be defined first (using grok.Permission for example)
-before it can be used in grok.require() in an XMLRPC class. This is even the
-case for a default permission that is never used.
+A permission has to be defined first (using grok.Permission for
+example) before it can be used in grok.require() in an XMLRPC
+class. However, this is *not* the the case for a default permission
+that is never used.
 
   >>> grok.testing.grok(__name__)
-  Traceback (most recent call last):
-   ...
-  ConfigurationExecutionError: martian.error.GrokError: Undefined permission 'doesnt.exist' in <class 'grok.tests.security.missing_permission_xmlrpc3.MissingPermission'>. Use grok.Permission first.
-  ...
 
 """
 

Modified: grok/trunk/src/grok/tests/test_grok.py
===================================================================
--- grok/trunk/src/grok/tests/test_grok.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/tests/test_grok.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -44,7 +44,7 @@
     suite = unittest.TestSuite()
     for name in ['adapter', 'error', 'view', 'event', 'security', 'catalog',
                  'zcml', 'static', 'utility', 'xmlrpc', 'json', 'container',
-                 'traversal', 'form', 'grokker', 'directive', 'util',
+                 'traversal', 'form', 'grokker', 'directive',
                  'baseclass', 'annotation', 'application', 'template',
                  'viewlet', 'testsetup', 'conflict', 'order']:
         suite.addTest(suiteFromPackage(name))

Modified: grok/trunk/src/grok/tests/xmlrpc/nocontext.py
===================================================================
--- grok/trunk/src/grok/tests/xmlrpc/nocontext.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/tests/xmlrpc/nocontext.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -14,4 +14,6 @@
 import grok
 
 class HomeRPC(grok.XMLRPC):
-    pass
+
+    def foo(self):
+        pass

Copied: grok/trunk/src/grok/tests/xmlrpc/nomethods.py (from rev 87017, grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nomethods.py)
===================================================================
--- grok/trunk/src/grok/tests/xmlrpc/nomethods.py	                        (rev 0)
+++ grok/trunk/src/grok/tests/xmlrpc/nomethods.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -0,0 +1,16 @@
+"""
+  >>> grok.testing.grok(__name__)
+  Traceback (most recent call last):
+    ...
+  GrokError: <class 'grok.tests.xmlrpc.nomethods.RemoteCaveman'> does not
+  define any public methods. Please add methods to this class to enable
+  its registration.
+
+"""
+import grok
+
+class Caveman(grok.Model):
+    pass
+
+class RemoteCaveman(grok.XMLRPC):
+    pass

Modified: grok/trunk/src/grok/util.py
===================================================================
--- grok/trunk/src/grok/util.py	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/src/grok/util.py	2008-05-29 10:48:18 UTC (rev 87018)
@@ -29,10 +29,6 @@
 from martian.error import GrokError
 from martian.util import methods_from_class
 
-def public_methods_from_class(factory):
-    return [m for m in methods_from_class(factory) if \
-            not m.__name__.startswith('_')]
-
 def make_checker(factory, view_factory, permission, method_names=None):
     """Make a checker for a view_factory associated with factory.
 

Modified: grok/trunk/versions.cfg
===================================================================
--- grok/trunk/versions.cfg	2008-05-29 10:31:35 UTC (rev 87017)
+++ grok/trunk/versions.cfg	2008-05-29 10:48:18 UTC (rev 87018)
@@ -5,7 +5,7 @@
 ZConfig = 2.5.1
 ZODB3 = 3.8
 docutils = 0.4
-martian = 0.9.6
+martian = 0.9.7
 grokcore.component = 1.3
 mechanize = 0.1.7b
 pytz = 2007k



More information about the Checkins mailing list