[Checkins] SVN: grok/branches/philikon-methodgrokker/src/grok/ Raise an error if a class doesn't contain any public methods. A public method is

Philipp von Weitershausen philikon at philikon.de
Mon May 26 07:17:23 EDT 2008


Log message for revision 86965:
  Raise an error if a class doesn't contain any public methods.  A public method is
  something that doesn't start with an underscore AND (this is new) isn't inherited
  from the component base class.  For instance, grok.REST defines browserDefault
  and other methods which are ignored as well.
  

Changed:
  U   grok/branches/philikon-methodgrokker/src/grok/ftests/rest/rest.py
  U   grok/branches/philikon-methodgrokker/src/grok/meta.py
  U   grok/branches/philikon-methodgrokker/src/grok/tests/json/nocontext.py
  A   grok/branches/philikon-methodgrokker/src/grok/tests/json/nomethods.py
  U   grok/branches/philikon-methodgrokker/src/grok/tests/json/view_lookup.py
  U   grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nocontext.py
  A   grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nomethods.py

-=-
Modified: grok/branches/philikon-methodgrokker/src/grok/ftests/rest/rest.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/ftests/rest/rest.py	2008-05-26 10:57:25 UTC (rev 86964)
+++ grok/branches/philikon-methodgrokker/src/grok/ftests/rest/rest.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -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/branches/philikon-methodgrokker/src/grok/meta.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/meta.py	2008-05-26 10:57:25 UTC (rev 86964)
+++ grok/branches/philikon-methodgrokker/src/grok/meta.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -98,8 +98,16 @@
         for directive in self.directives:
             kw[directive.name] = directive.get(class_, module, **kw)
 
+        # Ignore methods that are present on the component baseclass.
+        basemethods = set(public_methods_from_class(self.component_class))
+        methods = set(public_methods_from_class(class_)) - basemethods
+        if not methods:
+            raise GrokError("%r does not define any public methods. "
+                            "Please add methods to this class to enable "
+                            "its registration." % class_, class_)
+
         results = []
-        for method in public_methods_from_class(class_):
+        for method in methods:
             # Directives may also be applied to methods, so let's
             # check each directive and potentially override the
             # class-level value with a value from the method *locally*.
@@ -111,8 +119,6 @@
                                                            default=class_value)
             results.append(self.execute(class_, method, **data))
 
-        if not results:
-            return False
         return max(results)
 
     def execute(self, class_, method, **data):
@@ -265,13 +271,6 @@
     # TODO: this grokker doesn't support layers yet
 
     def execute(self, factory, method, config, context, permission, **kw):
-        # 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']:
-            return False
-
         # Create a new class with a __view_name__ attribute so the
         # JSON class knows what method to call.
         method_view = type(

Modified: grok/branches/philikon-methodgrokker/src/grok/tests/json/nocontext.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/tests/json/nocontext.py	2008-05-26 10:57:25 UTC (rev 86964)
+++ grok/branches/philikon-methodgrokker/src/grok/tests/json/nocontext.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -14,4 +14,6 @@
 import grok
 
 class TestJSON(grok.JSON):
-    pass
+
+    def foo(self):
+        pass

Added: grok/branches/philikon-methodgrokker/src/grok/tests/json/nomethods.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/tests/json/nomethods.py	                        (rev 0)
+++ grok/branches/philikon-methodgrokker/src/grok/tests/json/nomethods.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -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


Property changes on: grok/branches/philikon-methodgrokker/src/grok/tests/json/nomethods.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: grok/branches/philikon-methodgrokker/src/grok/tests/json/view_lookup.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/tests/json/view_lookup.py	2008-05-26 10:57:25 UTC (rev 86964)
+++ grok/branches/philikon-methodgrokker/src/grok/tests/json/view_lookup.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -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/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nocontext.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nocontext.py	2008-05-26 10:57:25 UTC (rev 86964)
+++ grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nocontext.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -14,4 +14,6 @@
 import grok
 
 class HomeRPC(grok.XMLRPC):
-    pass
+
+    def foo(self):
+        pass

Added: grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nomethods.py
===================================================================
--- grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nomethods.py	                        (rev 0)
+++ grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nomethods.py	2008-05-26 11:17:22 UTC (rev 86965)
@@ -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


Property changes on: grok/branches/philikon-methodgrokker/src/grok/tests/xmlrpc/nomethods.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list