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

Type InterfaceClass

             object --+    
                      |    
                Element --+
                          |
         object --+       |
                  |       |
SpecificationBasePy --+   |
                      |   |
          Specification --+
                          |
                         InterfaceClass


Prototype (scarecrow) Interfaces Implementation.
Method Summary
  __init__(self, name, bases, attrs, __doc__, __module__)
  __adapt__(self, obj)
Adapt an object to the reciever
  __call__(self, obj, alternate)
Adapt an object to the interface
  __cmp(self, o1, o2)
Make interfaces sortable TODO: It would ne nice if: More specific interfaces should sort before less specific ones.
  __contains__(self, name)
  __d(self, dict)
  __getitem__(self, name)
Return the attribute description for the given name.
  __gt__(self, other)
  __iter__(self)
  __lt__(self, other)
  __reduce__(self)
  __repr__(self)
  _getInterface(self, ob, name)
Retrieve a named interface.
  deferred(self)
Return a defered class corresponding to the interface.
  direct(self, name)
  getBases(self)
  getDescriptionFor(self, name)
Return the attribute description for the given name.
  interfaces(self)
Return an iterator for the interfaces in the specification
  isEqualOrExtendedBy(self, other)
Same interface or extends?
  names(self, all)
Return the attribute names defined by the interface.
  namesAndDescriptions(self, all)
Return attribute names and descriptions defined by interface.
  queryDescriptionFor(self, name, default)
  validateInvariants(self, obj, errors)
validate object to defined invariants.
    Inherited from Element
  getDoc(self)
Returns the documentation for the object.
  getName(self)
Returns the name of the object.
  getTaggedValue(self, tag)
Returns the value associated with 'tag'.
  getTaggedValueTags(self)
Returns a list of all tags.
  queryTaggedValue(self, tag, default)
Returns the value associated with 'tag'.
  setTaggedValue(self, tag, value)
Associates 'value' with 'key'.
    Inherited from Specification
  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
  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_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Property Summary
    Inherited from Specification
  __bases__

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

Method Details

__adapt__(self, obj)

Adapt an object to the reciever

This method is normally not called directly. It is called by the PEP 246 adapt framework and by the interface __call__ operator.

The adapt method is responsible for adapting an object to the reciever.

The default version returns None:
 >>> import zope.interface
 >>> class I(zope.interface.Interface):
 ...     pass

 >>> I.__adapt__(0)
unless the object given provides the interface:
 >>> class C(object):
 ...     zope.interface.implements(I)

 >>> obj = C()
 >>> I.__adapt__(obj) is obj
 True
Adapter hooks can be provided (or removed) to provide custom adaptation. We'll install a silly hook that adapts 0 to 42. We install a hook by simply adding it to the adapter_hooks list:
 >>> from zope.interface.interface import adapter_hooks
 >>> def adapt_0_to_42(iface, obj):
 ...     if obj == 0:
 ...         return 42

 >>> adapter_hooks.append(adapt_0_to_42)
 >>> I.__adapt__(0)
 42

Hooks must either return an adapter, or None if no adapter can be found.

Hooks can be uninstalled by removing them from the list:
 >>> adapter_hooks.remove(adapt_0_to_42)
 >>> I.__adapt__(0)

__call__(self, obj, alternate=<object object at 0xb7e6e440>)
(Call operator)

Adapt an object to the interface

The sematics based on those of the PEP 246 adapt function.

If an object cannot be adapted, then a TypeError is raised:
 >>> import zope.interface
 >>> class I(zope.interface.Interface):
 ...     pass

 >>> I(0)
 Traceback (most recent call last):
 ...
 TypeError: ('Could not adapt', 0, <InterfaceClass zope.interface.interface.I>)
unless an alternate value is provided as a second positional argument:
 >>> I(0, 'bob')
 'bob'
If an object already implements the interface, then it will be returned:
 >>> class C(object):
 ...     zope.interface.implements(I)

 >>> obj = C()
 >>> I(obj) is obj
 True
If an object implements __conform__, then it will be used:
 >>> class C(object):
 ...     zope.interface.implements(I)
 ...     def __conform__(self, proto):
 ...          return 0

 >>> I(C())
 0
Adapter hooks (see __adapt__) will also be used, if present:
>>> from zope.interface.interface import adapter_hooks
>>> def adapt_0_to_42(iface, obj):
...     if obj == 0:
...         return 42
>>> adapter_hooks.append(adapt_0_to_42)
>>> I(0)
42
>>> adapter_hooks.remove(adapt_0_to_42)
>>> I(0)
Traceback (most recent call last):

...

TypeError: ('Could not adapt', 0, <InterfaceClass zope.interface.interface.I>)

__cmp(self, o1, o2)

Make interfaces sortable

TODO: It would ne nice if:

   More specific interfaces should sort before less specific ones.
   Otherwise, sort on name and module.

   But this is too complicated, and we're going to punt on it
   for now.

For now, sort on interface and module name.

None is treated as a pseudo interface that implies the loosest
contact possible, no contract. For that reason, all interfaces
sort before None.

__getitem__(self, name)
(Indexing operator)

Return the attribute description for the given name.

_getInterface(self, ob, name)

Retrieve a named interface.

deferred(self)

Return a defered class corresponding to the interface.

getDescriptionFor(self, name)

Return the attribute description for the given name.

interfaces(self)

Return an iterator for the interfaces in the specification

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

isEqualOrExtendedBy(self, other)

Same interface or extends?

names(self, all=False)

Return the attribute names defined by the interface.

namesAndDescriptions(self, all=False)

Return attribute names and descriptions defined by interface.

validateInvariants(self, obj, errors=None)

validate object to defined invariants.

Class Variable Details

__implemented__

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

__provides__

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

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