[Zope-CMF] Re: Tools as local utilities
tseaver at palladion.com
Sun Sep 10 10:08:09 EDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Rocky Burt wrote:
> On Sat, 2006-09-09 at 21:57 +0100, Martin Aspeli wrote:
>> Hi guys,
>> philiKON pointed out something interesting to me the other day - we
>> could actually register the existing tools as local utilities as of Zope
>> 2.10. That way, you could do this:
>> actions = getUtility(IActionsTool)
>> as another spelling for
>> actions = getToolByName(context, 'portal_actions')
>> But now we're being more consistent with Zope 3, we are using a proper
>> interface and not just a string to check, we don't have to worry about
>> passing a context parameter (though tests have to do a setSite() call),
>> and we can let the registration be overridden with the component
>> registry operations.
> +10 on this idea from me.
+1 here, too. In fact, being able to make this switch is the *reason*
'getToolByName' was introduced in the first placey.
> The important thing would be to make sure the
> getToolByName deprecation message is smart enough to describe the exact
> necessary getUtility call. In other words use "getToolByName(context,
> 'portal_properties') has been deprecated, please use
> getUtility(IPropertiesTool) instead" rather than the confusing
> "getToolByName has been deprecated, please use getUtility instead".
I think we are likely to modify 'getToolByName' to use a registry of
names to utility interfaces for all the "known" names, falling back to
getattr only for unknown ones. In that case, the deprecation message
can supply either the name of the interface, or at least say that the
name is not a "known" tool name.
Tres Seaver +1 202-558-7113 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v22.214.171.124 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the Zope-CMF