Module hooks :: Class Hook
[show private | hide private]
[frames | no frames]

Class Hook


Represents a (possibly empty) sequence of user-defined functions. Provides users with the opportunity of reacting to events internal to Lyntin. All functions take a single argument which is a tuple.

Read through the hooks.py file for more information on the hooks that come with Lyntin as well as which arguments they take in the arg tuple.
Method Summary
  __init__(self, mapper, empty, done)
Initializes.
  clear(self)
Clears the functionlist.
int count(self)
Returns how many functions are registered with this hook.
  createOrderedList(self)
Goes through the functionlist and generates the orderedlist.
  register(self, func, place)
Registers a function with a hook.
  setFilterMapper(self, newmapper)
Sets the filter mapper to a new mapper.
tuple of arguments spamhook(self, arglist, mappingFunction, emptyFunction, doneFunction)
Sends out input to all the registrants of a hook.
  unregister(self, func)
Tries to remove a registrant from a hook--does pretty well.

Method Details

__init__(self, mapper=<function <lambda> at 0x8220e4c>, empty=<function <lambda> at 0x8220e84>, done=<function <lambda> at 0x8220ebc>)
(Constructor)

Initializes.
Parameters:
mapper - function whose output will be passed to the next function in the hook. Must take two arguments: the previous arglist and the return from the previous function.
           (type=function)
empty - function to be called when there are no functions in the hook
           (type=function)
done - function to be called when spamming finished normally
           (type=function)

clear(self)

Clears the functionlist.

count(self)

Returns how many functions are registered with this hook.
Returns:
the number of functions registered
           (type=int)

createOrderedList(self)

Goes through the functionlist and generates the orderedlist. This helps save some cycles every time we spam the hook.

register(self, func, place=99)

Registers a function with a hook.

hook should be one of the hook constants. func should be a callable function. place is optional--it allows you to put yourself earlier in the hook lineup.
Parameters:
func - the function to call when the hook is spammed
           (type=function)
place - the function will get this place in the call order. functions with the same place specified will get arbitrary ordering. defaults to LAST.
           (type=int)

setFilterMapper(self, newmapper)

Sets the filter mapper to a new mapper.
Parameters:
newmapper - the function whose output will be passed to the next function in the hook. Takes two arguments: the previous arglist and the return from the previous function.
           (type=function)

spamhook(self, arglist=(), mappingFunction=None, emptyFunction=None, doneFunction=None)

Sends out input to all the registrants of a hook.
Parameters:
arglist - the list of arguments that gets passed to each function in the hook. the actual arguments differs from hook to hook.
           (type=tuple of arguments)
mappingFunction - function whose output will be passed to the next function in the hook. Must take two arguments: the previous arglist and the return from the previous function.
           (type=function)
emptyFunction - Function to be called with arglist if there are no objects registered with this hook. Must take 1 argument, the arglist tuple, and return what spamhook should return.
           (type=function)
doneFunction - Functino to be called when spamming finishes normally. Should take 1 argument and return what spamhook should return.
           (type=function)
Returns:
arglist
           (type=tuple of arguments)

unregister(self, func)

Tries to remove a registrant from a hook--does pretty well.
Parameters:
func - the function to unregister
           (type=function)

Generated by Epydoc 1.1 on Mon Apr 28 21:11:25 2003 http://epydoc.sf.net