[Zope3-dev] Re: set of interfaces?

Tres Seaver tseaver at palladion.com
Wed Mar 22 10:54:31 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jean-Marc Orliaguet wrote:

> what is the best way in zope3 to create a collection of interfaces
> without using classes, lists, etc.?
> 
> I have a number of interfaces that I'd like to group into a same
> interface category.
> 
> e.g. ISomeCollection  = I1, I2, I3, I4 ....
>
> and I'd like to be able to query which interfaces ISomeCollection
> "contains". However I'd like not to instanciate a registry just to
> hold that type of information.

You can create a Specification object from a sequence of interfaces:

 >>> from zope.interface import Interface
 >>> class I1(Interface): pass
 ...
 >>> class I2(Interface): pass
 ...
 >>> class I3(Interface): pass
 ...
 >>> from zope.interface.interface import Specification
 >>> spec = Specification((I1, I2, I3))
 >>> I3.providedBy(spec)
 False
 >>> I3.implementedBy(spec)
 False
 >>> spec.extends(I3)
 True
 >>> [x for x in spec.interfaces()]
 [<InterfaceClass __main__.I1>, <InterfaceClass __main__.I2>,
<InterfaceClass __main__.I3>]


Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEIXM3+gerLs4ltQ4RAjL0AKClFxW5r9tl5dy2AL8uuzsjrNLVWgCeP75E
tHJVvc6iWhhfkDTYOEag2ic=
=hAiX
-----END PGP SIGNATURE-----



More information about the Zope3-dev mailing list