Re: [Zope3-Users] Re: Checking if an interface is provided by an object or could be adapted to
On 01.05.2006, at 01:55, Stephan Richter wrote: On Sunday 30 April 2006 19:34, Bernd Dorn wrote: component.queryMultiAdapter((bar,baz), IFoo) is not None or False this way you always get True or False ok, for this case it is ok but when you have a class that uses __conform__ None may be returned when you use this IFoo(context,False) or am i wrong? Why not just: component.queryMultiAdapter((bar,baz), IFoo, default=False) Regards, Stephan -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Re: Checking if an interface is provided by an object or could be adapted to
On 01.05.2006, at 02:17, Martin Aspeli wrote: On Mon, 01 May 2006 00:55:46 +0100, Stephan Richter [EMAIL PROTECTED] wrote: On Sunday 30 April 2006 19:34, Bernd Dorn wrote: component.queryMultiAdapter((bar,baz), IFoo) is not None or False Why not just: component.queryMultiAdapter((bar,baz), IFoo, default=False) Well, it seems that if I have: class Foo(object): .implements(IFoo) context = Foo() component.queryAdapter(foo, IFoo, default=None) None this looks for an adapter for all interfaces provided by foo to IFoo regardless if foo already implements IFoo. what should it return instead? foo? I assume it's the same with single adapters? As I said, I may well be doing something wrong, but that's what was happening to me (using Five, Zope 2.9.2). If it makes any difference, the interface in question (IFoo) was applied to the class Foo using implements in ZCML (legacy/backwards compatability issue). hm, that's odd is the interface provided by the object? IFoo.providedBy(context) if not, there may be an error in the zcml Martin -- You can just adapt yourself out of it... // Archipelago sprint 26/04/2006 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Checking if an interface is provided by an object or could be adapted to
On May 1, 2006, at 2:56 AM, Bernd Dorn wrote: On 01.05.2006, at 01:55, Stephan Richter wrote: On Sunday 30 April 2006 19:34, Bernd Dorn wrote: component.queryMultiAdapter((bar,baz), IFoo) is not None or False this way you always get True or False ok, for this case it is ok but when you have a class that uses __conform__ None may be returned when you use this IFoo(context,False) or am i wrong? It might return None, which according to our semantics means that the adaptation failed. Since None has a False meaning in a boolean context, Stephan's version will work out. However... Why not just: component.queryMultiAdapter((bar,baz), IFoo, default=False) ...this assumes that the adapter evaluates to a boolean True, which is not generically (reliably) the case. As a pattern, Bernd's version is safer, although the trailing or False is superfluous. component.queryMultiAdapter((bar,baz), IFoo) is not None Gary ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] zope.thread.local == threading.local ?
Hello! I use 'zope.thread.local', but Python2.4 has 'threading.local'-class from Jim Fulton. Where diff? ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users