Hash: SHA1

On 10 Sep 2006, at 16:08, Tres Seaver wrote:

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.

I am experimenting with that right now, but my z3/Five-Fu ran low again ;) My problem: calls to zope.component.getUtility (interface_class) never return anything. Here's the top part (the bottom is just the old way) of my CMFCore.utils.getToolByName:

def getToolByName(obj, name, default=_marker):

    """ Get the tool, 'toolname', by acquiring it.
    tool_iface = _tool_iface_registry.get(name)

    if tool_iface is not None:
warn('getToolByName is deprecated, please use "getUtility(% s)"' % (
               tool_iface.__name__), DeprecationWarning, stacklevel=2)

            tool = getUtility(tool_iface, context=obj)
            return tool
        except ComponentLookupError:
            # behave in backwards-compatible way
            if default is _marker:
                raise AttributeError, name

I have a simple registration going and have one ID -> interface registered (in "_tool_iface_registry"), 'portal_actions' is mapped to interface class CMFCore.interfaces._tools.IActionsTool. No matter how I try to call getUtility, I always get a ComponentLookupError.

I am probably missing some kind of component registration - I have not made any ZCML changes or changes to the code in CMFCore.ActionsTool, except for one line that causes the tool to be registered in the internal "_tool_iface_registry".

Help! :)


Version: GnuPG v1.4.1 (Darwin)

Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to