Package zope :: Package interface :: Module interface :: Class Specification
[show private | hide private]
[frames | no frames]

Type Specification

         object --+    
                  |    
SpecificationBasePy --+
                      |
                     Specification

Known Subclasses:
Declaration, InterfaceClass

Specifications

An interface specification is used to track interface declarations and component registrations.

This class is a base class for both interfaces themselves and for interface specifications (declarations).

Specifications are mutable. If you reassign their cases, their relations with other specifications are adjusted accordingly.

For example:
>>> from zope.interface import Interface
>>> class I1(Interface):
...     pass
>>> class I2(I1):
...     pass
>>> class I3(I2):
...     pass
>>> [i.__name__ for i in I1.__bases__]
['Interface']
>>> [i.__name__ for i in I2.__bases__]
['I1']
>>> I3.extends(I1)
1
>>> I2.__bases__ = (Interface, )
>>> [i.__name__ for i in I2.__bases__]
['Interface']
>>> I3.extends(I1)
0

Method Summary
  __init__(self, bases)
  __setBases(self, bases)
  changed(self)
We, or something we depend on, have changed
  extends(self, interface, strict)
Does the specification extend the given interface?
  get(self, name, default)
Query for an attribute description
  interfaces(self)
Return an iterator for the interfaces in the specification
  isImplementedBy(self, ob)
  isImplementedByInstancesOf(self, cls)
  isOrExtends(self, interface)
Is the interface the same as or extend the given interface
  providedBy(self, ob)
Is the interface implemented by an object
  subscribe(self, dependent)
  unsubscribe(self, dependent)
  weakref(self, callback)
    Inherited from SpecificationBasePy
  implementedBy(self, cls)
Do instances of the given class implement the interface?
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Property Summary
  __bases__

Class Variable Summary
Implements __implemented__ = <implementedBy zope.interface.interfac...
ClassProvides __provides__ = <zope.interface.declarations.ClassProvide...
    Inherited from SpecificationBasePy
ClassProvides __providedBy__ = <zope.interface.declarations.ClassProvi...

Method Details

changed(self)

We, or something we depend on, have changed

extends(self, interface, strict=True)

Does the specification extend the given interface?

Test whether an interface in the specification extends the given interface

Examples:
 >>> from zope.interface import Interface
 >>> from zope.interface.declarations import Declaration
 >>> class I1(Interface): pass
 ...
 >>> class I2(I1): pass
 ...
 >>> class I3(Interface): pass
 ...
 >>> class I4(I3): pass
 ...
 >>> spec = Declaration()
 >>> int(spec.extends(Interface))
 0
 >>> spec = Declaration(I2)
 >>> int(spec.extends(Interface))
 1
 >>> int(spec.extends(I1))
 1
 >>> int(spec.extends(I2))
 1
 >>> int(spec.extends(I3))
 0
 >>> int(spec.extends(I4))
 0
 >>> I2.extends(I2)
 0
 >>> I2.extends(I2, False)
 1
 >>> I2.extends(I2, strict=False)
 1

get(self, name, default=None)

Query for an attribute description

interfaces(self)

Return an iterator for the interfaces in the specification

for example:
 >>> from zope.interface import Interface
 >>> class I1(Interface): pass
 ...
 >>> class I2(I1): pass
 ...
 >>> class I3(Interface): pass
 ...
 >>> class I4(I3): pass
 ...
 >>> spec = Specification((I2, I3))
 >>> spec = Specification((I4, spec))
 >>> i = spec.interfaces()
 >>> i.next().getName()
 'I4'
 >>> i.next().getName()
 'I2'
 >>> i.next().getName()
 'I3'
 >>> list(i)
 []

isOrExtends(self, interface)

Is the interface the same as or extend the given interface

Examples:
 >>> from zope.interface import Interface
 >>> from zope.interface.declarations import Declaration
 >>> class I1(Interface): pass
 ...
 >>> class I2(I1): pass
 ...
 >>> class I3(Interface): pass
 ...
 >>> class I4(I3): pass
 ...
 >>> spec = Declaration()
 >>> int(spec.extends(Interface))
 0
 >>> spec = Declaration(I2)
 >>> int(spec.extends(Interface))
 1
 >>> int(spec.extends(I1))
 1
 >>> int(spec.extends(I2))
 1
 >>> int(spec.extends(I3))
 0
 >>> int(spec.extends(I4))
 0

providedBy(self, ob)

Is the interface implemented by an object
>>> from zope.interface import *
>>> class I1(Interface):
...     pass
>>> class C(object):
...     implements(I1)
>>> c = C()
>>> class X(object):
...     pass
>>> x = X()
>>> I1.providedBy(x)
False

>>> I1.providedBy(C)
False

>>> I1.providedBy(c)
True

>>> directlyProvides(x, I1)
>>> I1.providedBy(x)
True

>>> directlyProvides(C, I1)
>>> I1.providedBy(C)
True

Property Details

__bases__

Get Method:
unknown--1209948988(...)
Set Method:
__setBases(self, bases)

Class Variable Details

__implemented__

Type:
Implements
Value:
<implementedBy zope.interface.interface.Specification>                 

__provides__

Type:
ClassProvides
Value:
<zope.interface.declarations.ClassProvides object at 0xb7e2208c>       

Generated by Epydoc 2.1 on Fri Jun 24 12:01:25 2005 http://epydoc.sf.net