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

Class route

source code


The @route decorator is attached to state handlers to configure them in the Router so they handle messages for them. The way this works is, rather than just routing working on only messages being sent to a state handler, it also uses the state of the sender. It's like having routing in a web application use both the URL and an internal state setting to determine which method to run.

However, if you'd rather than this state handler process all messages matching the @route then tag it @stateless. This will run the handler no matter what and not change the user's state.

Instance Methods [hide private]
 
__init__(self, format, **captures)
Sets up the pattern used for the Router configuration.
source code
 
__call__(self, func)
Returns either a decorator that does a stateless routing or a normal routing.
source code
 
__get__(self, obj, of_type=None)
This is NOT SUPPORTED.
source code
 
parse_format(self, format, captures)
Does the grunt work of convertion format+captures into the regex.
source code
 
setup_accounting(self, func)
Sets up an accounting map attached to the func for routing decorators.
source code

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, format, **captures)
(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__

__call__(self, func)
(Call operator)

source code 

Returns either a decorator that does a stateless routing or a normal routing.

__get__(self, obj, of_type=None)

source code 

This is NOT SUPPORTED. It is here just so that if you try to apply this decorator to a class's method it will barf on you.

parse_format(self, format, captures)

source code 

Does the grunt work of convertion format+captures into the regex.

setup_accounting(self, func)

source code 

Sets up an accounting map attached to the func for routing decorators.