[Grok-dev] Grokker actions branch merged!
Philipp von Weitershausen
philipp at weitershausen.de
Tue Oct 30 17:49:03 EDT 2007
I've now merged the gotcha-configuration-actions branch to the trunk.
This has the following implications for applications running against the
trunk (or for applications that will eventually be ported to grok 0.11) [1]:
* ``grok.grok`` and ``grok.grok_component`` have been deprecated. If
you need them for tests (which is their only legimitate use), you
should import them both from ``grok.testing``.
* Grokkers should now emit configuration actions instead of
registering components right away. For that they now get a new
keyword argument called ``config``, the configuration context. For
example, a grokker that used to do this::
registerSomeComponent(foo, name)
should now be doing this::
config.action(
descriminator=('somecomponent', name),
callable=registerSomeComponent,
args=(name,)
)
The descriminator should be chosen so that registrations with the
same descriminator conflict (in the above example, if somebody tried
to register two different components under the same name, you'd get
a conflict).
* Grokkers no longer get the ``context`` and ``templates`` keyword
arguments. If they need access to these values, they can now get
them as module annotations from the ``module_info`` object like
this::
context = module_info.getAnnotation('grok.context')
templates = module_info.getAnnotation('grok.templates')
* Note that grokkers must always take arbitrary keyword arguments
(``**kw``), as specified by the ``martian.interfaces.IGrokker``
interface. A minimal specification of the ``grok()`` method is
therefore::
def grok(self, name, obj, **kw):
...
though grokkers will likely want to take ``module_info`` as well as
``config`` explicitly::
def grok(self, name, obj, module_info, config, **kw):
...
If your application defines custom grokkers and you're getting a
``TypeError`` about unexpected arguments to ``grok``, you likely
need to update the signature of the ``grok()`` method like described
above.
[1] http://svn.zope.org/*checkout*/grok/trunk/doc/upgrade.txt
--
http://worldcookery.com -- Professional Zope documentation and training
More information about the Grok-dev
mailing list