Module Reference

class jute.InterfaceConformanceError

Object does not conform to interface specification.

Exception indicating that an object claims to provide an interface, but does not match the interface specification.

This is almost a TypeError, but an object provides two parts to its interface implementation: a claim to provide the interface, and the attributes that match the interface specification. This exception indicates the partial match of claiming to provide the interface, but not actually providing all the attributes required by an interface.

It could also be considered an AttributeError, as when validation is off, that is the alternative exception (that might be) raised. However, future versions of this module may perform additional validation to catch TypeError’s (e.g. function paramete matching).

class jute.Interface(provider)
classmethod register_implementation(cls)

Check if a class implements the interface, and register it.

classmethod implemented_by(cls)

Check if class claims to provide the interface.

Returns:True if interface is implemented by the class, else False.
classmethod register_provider(cls)

Register a provider class to the interface.

classmethod provided_by(obj)

Check if object claims to provide the interface.

Returns:True if the object claims to provide the interface, or False otherwise.

Note

The remaining functions break the abstraction provided by interfaces, allowing the caller to obtain more information about the wrapped object.

classmethod supported_by(obj)

Check if underlying object claims to provide the interface.

Although it allows the caller to see if the underlying object supports any interface, since it does not provide access to the interface, its main use is to perform feature checks for marker interfaces (interfaces that have the same syntax, but different semantics to the supplied interface).

Returns:True if the underlying object claims to provide the interface, or False otherwise.
classmethod cast(source)

Attempt to cast one interface to another.

The cast method allows the caller to access another supported interface. Whether this works depends on whether the underlying object supports this interface. Use of cast should be avoided, since it breaks the model of interface-based programming.

@jute.implements(*interfaces)

Decorator to mark a class as implementing the supplied interfaces.

To implement an interface, the class must define all attributes in the interface.

@jute.provides(*interfaces)

Decorator to mark a class as providing the supplied interfaces.

To provide an interface, the class instances must define all attributes in the interface.

class jute.Dynamic(provider)

Interface to dynamically provide other interfaces.

provides_interface(self, interface)

Check whether this instance provides an interface.

This method returns True when the interface class is provided, or False when the interface is not provided.

jute.underlying_object(interface)

Obtain the non-interface object wrapped by this interface.

Use of the underlying_object function should be avoided, since it breaks the model of interface-based programming. It is primarily useful for debugging.