Package lamson :: Module routing :: Class route_like
[hide private]
[frames] | no frames]

Class route_like

source code


Many times you want your state handler to just accept mail like another handler. Use this, passing in the other function. It even works across modules.

Instance Methods [hide private]
 
__init__(self, func)
Sets up the pattern used for the Router configuration.
source code

Inherited from route: __call__, __get__, parse_format, setup_accounting

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, func)
(Constructor)

source code 

Sets up the pattern used for the Router configuration.  The format
parameter is a simple pattern of words, captures, and anything you
want to ignore.  The captures parameter is a mapping of the words in
the format to regex that get put into the format.  When the pattern is
matched, the captures are handed to your state handler as keyword
arguments.

For example, if you have:

    @route("(list_name)-(action)@(host)",
        list_name='[a-z]+',
        action='[a-z]+', host='test\.com')
    def STATE(message, list_name=None, action=None, host=None):
        ....

Then this will be translated so that list_name is replaced with [a-z]+,
action with [a-z]+, and host with 'test.com' to produce a regex with the
right format and named captures to that your state handler is called
with the proper keyword parameters.

You should also use the Router.defaults() to set default things like the
host so that you are not putting it into your code.

Overrides: object.__init__
(inherited documentation)