Package gnue :: Package navigator :: Package external :: Package zope :: Package interface :: Module interface :: Class InterfaceClass
[show private | hide private]

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)
Test whether the specification is implemented by a class or factory.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
Return hash(x)...
  __new__(T, S, ...)
Return 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)
Return str(x)...

Property Summary
    Inherited from Specification
  __bases__

Class Variable Summary
Implements __implemented__ = <implementedBy gnue.navigator.external...
ClassProvides __provides__ = <gnue.navigator.external.zope.interface.d...
    Inherited from Element
ClassProvides __providedBy__ = <gnue.navigator.external.zope.interface...

Method Details

__init__(self, name, bases=(), attrs=None, __doc__=None, __module__=None)
(Constructor)

Overrides:
gnue.navigator.external.zope.interface.interface.Element.__init__

__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:
 >>> from gnue.navigator.external 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 gnue.navigator.external.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 0xb7dde450>)
(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:
 >>> from gnue.navigator.external 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 gnue.navigator.external.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.

__contains__(self, name)
(In operator)

__d(self, dict)

__getitem__(self, name)
(Indexing operator)

Return the attribute description for the given name.

__gt__(self, other)
(Greater-than operator)

__iter__(self)
(Iteration protocol support)

__lt__(self, other)
(Less-than operator)

__reduce__(self)

Overrides:
__builtin__.object.__reduce__

__repr__(self)
(Representation operator)

Overrides:
__builtin__.object.__repr__

_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

for example:
 >>> from gnue.navigator.external.zope.interface import Interface
 >>> class I1(Interface): pass
 ...
 >>>
 >>> i = I1.interfaces()
 >>> i.next().getName()
 'I1'
 >>> list(i)
 []
Overrides:
gnue.navigator.external.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.

queryDescriptionFor(self, name, default=None)

validateInvariants(self, obj, errors=None)

validate object to defined invariants.

Class Variable Details

__implemented__

Type:
Implements
Value:
<implementedBy gnue.navigator.external.zope.interface.interface.Interf\
aceClass>                                                              

__provides__

Type:
ClassProvides
Value:
<gnue.navigator.external.zope.interface.declarations.ClassProvides obj\
ect at 0xb7b00a6c>                                                     


GNUe Home

Private API

Developer's Corner