[Grok-dev] what grok.JSON methods to publish?

Jan-Jaap Driessen jdriessen at thehealthagency.com
Fri Jan 4 09:52:06 EST 2008


When I tried to figure out how to work with grok.JSON, I found the  
following:

*All* methods of a grok.JSON are published (including those defined in  
the grok.JSON baseclasses, i.e. BrowserPage), with the following  
consequences:

1. The __*__ methods are registered as views. This is particular nasty  
for the __call__ method, because traversing to the '__call__ view'  
will lead to infinite recursion, crashing the Zope server process.

2. If you have more than one class deriving from grok.JSON for a  
particular context class, you will get configuration conflict errors,  
because grok tries to register views for methods 'publishTraverse' and  
'browserDefault' multiple times.

On top of that, ignore the 'publishTraverse' and 'browserDefault'  
methods.

My original goal was to find a way to exclude particular methods (of  
my class deriving from grok.JSON) from being published. Here are some  
ideas:

* Ignore methods that start with one or more underscore. This sounds  
very pythonic (PEP8), but maybe we want something more explicit:
* We could use a decorator to indicate a (non-)publishable method.
* Abstain from publishing methods altogether, but have each json call  
have it's own class, similar to grok.View. This requires an API change.

How do you feel about this? Am I missing something?



More information about the Grok-dev mailing list