Tools for run commands in framework environment using simple manage.py script
Package contains settings management functions
Get settings for class
Get configuration parameter from sections
Class implements base functor operations
Monaidic functions and classes
Bases: lighty.monads.NoneMonad
ErrorMonad class represents errors
Bases: lighty.monads.ValueMonad
NoneMonad class represents empty list, dicts, NoneType or False
Bases: lighty.functor.BaseFunctor
Base monad class. All the operations except comparisions and few others returns monads.
Function that checks an argument and raises exception stored in argument
Handle an exception and return ErrorMonad for this exception
Decorator wraps all methods can be used for comparision. Return’s True if boolean operation returns True, or False when boolean operation return’s False or something goes wrong
Decorator that wraps function with arguments, check all the values and catch all the exceptions
This module describes a class for sending and dispatching signals and event.
For example create a signal dispatcher at first:
dispatcher = SignalDispatcher()
To create new handler function we need to create a channes and add function as handler to this channel:
def handler(objects):
print 'Handle', objects
dispatcher.channel('/test/', handler)
Then we can send a signal to channel:
dispatcher.signal('/test/')
This prints ‘Handle []’. As you can see we can attach objects into signal to send messages between different modules:
dispatcher.signal('/test/', [0, 1, 2, 3])
It prints ‘Handle [0, 1, 2, 3]’. To add additional options for interactions between functions we can use filters. Filter provides a way to subscribe multiply handlers to one channel and pass different objects from signal to different handler functions:
def filtered(objects):
print 'Filtered', objects
dispatcher.channel('/test/', filtered, filters=[lambda x: x > 0])
dispatcher.signal('/test/', [0, 1, 2, 3])
This code prints:
Handle [0, 1, 2, 3]
Filtered [1, 2, 3]
Filtering can be usefull for impementing the services that derives changes in entities for different subscribers. As example, Peter and John subscribed for changes in project. This project has few tickets included. Peter watches for changes in tickets #1, #2 and #3, and John watches for changes in tickets #2 and #4. Simple code to implement it:
def send_changes(user, changes):
pass # some code to sent changes to user as example vie email
dispatcher.channel('project', functools.partial(send_changes, 'Peter'),
filters=[lambda t: t.ticket_id in [1, 2, 3]])
dispatcher.channel('project', functools.partial(send_changes, 'John'),
filters=[lambda t: t.ticket_id in [2, 4]])
Some utilitary classes usually used to make working with different python versions and different environment easier:
Create a new class with base class base and metaclass metaclass. This is designed to be used in class declarations like this:
from lighty.utils import with_metaclass
Module contains base validators that can be used to check the data
Bases: object
Validator used to validate choices list
Raises a ValidationError with a code of ‘max_length’ if length of value is greater than max_value.
Raises a ValidationError with a code of ‘max_value’ if value is greater than max_value.
Raises a ValidationError with a code of ‘min_length’ if length of value is less than min_length.
Raises a ValidationError with a code of ‘min_value’ if value is less than min_value.
Bases: object
Validator used to check is value matches regular expression
Bases: lighty.validators.RegexValidator
A RegexValidator that ensures a value looks like a URL and optionally verifies that the URL actually exists (i.e., doesn’t return a 404 status code). Raises an error code of ‘invalid’ if it doesn’t look like a URL, and a code of ‘invalid_link’ if it doesn’t exist.