The interface module provides a base class which provides a function to decorate functions in order to label specific functions as interface functions.
The PassThrough' class is an implementation of the :class:`Interface class which provides the ability to connect a child PassThrough object to a parent PassThrough object so that any time the child’s interface functions are called, the call is instead redirected to the parent’s function of the same name.
The Interface class provides to ability to identify specific class functions to be ‘interface’ functions.
This class contains a class property called InterfaceProperty which defines the name of the property used to identify interface functions.
This class provides a interface() function which uses the InterfaceProperty property to create an implementation specific decorator which can be used to decorate functions that should identified as interface functions.
Example:
class Example(Interface):
InterfaceProperty = "ExampleInterfaceProperty"
@Example.interface
def testPrint(self, message):
print "Message:", message
This the above example the testPrint() function has been decorated and is thus an interface function.
Connect to a parent’s interface methods.
Note: This should be overriden by concrete Interfaces
Get a dictionary of the interface function names mapped to the actual functions.
The PassThrough Interface provides the ability for a child PassThrough object to connect functions of the same name to the parent’s Interface functions.
When a child class connects to the parent’s interface functions, all calls to the child’s interface functions are instead redirected to the parent’s functions of the same name.
Example:
class Parent(PassThrough):
@PassThrough.interface
def testPrint(self, message):
print "Parent message:", message
class Child(PassThrough):
pass
parent = Parent()
child = Child()
child.connect(parent)
# Prints:
# "Parent message:", this is a message
child.testPrint("this is a message")