Back to index

python-cliapp  1.20120630
Public Member Functions | Public Attributes
cliapp.hook.FilterHook Class Reference
Inheritance diagram for cliapp.hook.FilterHook:
Inheritance graph
[legend]
Collaboration diagram for cliapp.hook.FilterHook:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def call_callbacks
def add_callback
def call_callbacks
def remove_callback

Public Attributes

 callbacks

Detailed Description

A hook which filters data through callbacks.

Every hook of this type accepts a piece of data as its first argument
Each callback gets the return value of the previous one as its
argument. The caller gets the value of the final callback.

Other arguments (with or without keywords) are passed as-is to
each callback.

Definition at line 59 of file hook.py.


Member Function Documentation

def cliapp.hook.Hook.add_callback (   self,
  callback 
) [inherited]
Add a callback to this hook.

Return an identifier that can be used to remove this callback.

Definition at line 37 of file hook.py.

00037 
00038     def add_callback(self, callback):
00039         '''Add a callback to this hook.
00040         
00041         Return an identifier that can be used to remove this callback.
00042 
00043         '''
00044 
00045         if callback not in self.callbacks:
00046             self.callbacks.append(callback)
00047         return callback
        
def cliapp.hook.Hook.call_callbacks (   self,
  args,
  kwargs 
) [inherited]
Call all callbacks with the given arguments.

Definition at line 48 of file hook.py.

00048 
00049     def call_callbacks(self, *args, **kwargs):
00050         '''Call all callbacks with the given arguments.'''
00051         for callback in self.callbacks:
00052             callback(*args, **kwargs)
        
def cliapp.hook.FilterHook.call_callbacks (   self,
  data,
  args,
  kwargs 
)

Definition at line 72 of file hook.py.

00072 
00073     def call_callbacks(self, data, *args, **kwargs):
00074         for callback in self.callbacks:
00075             data = callback(data, *args, **kwargs)
00076         return data
00077 
def cliapp.hook.Hook.remove_callback (   self,
  callback_id 
) [inherited]
Remove a specific callback.

Definition at line 53 of file hook.py.

00053 
00054     def remove_callback(self, callback_id):
00055         '''Remove a specific callback.'''
00056         if callback_id in self.callbacks:
00057             self.callbacks.remove(callback_id)
00058 


Member Data Documentation

Definition at line 35 of file hook.py.


The documentation for this class was generated from the following file: