Tools for run commands in framework environment using simple manage.py script
Load commands from applications lists
Load commands from application with name specified
Process manage command. Load all the commands from applications in configuration files and add them into autocompletition
Package contains settings management functions
Get settings for class
Get configuration parameter from sections
Check is section in configuration exists
Get unique configuration options names
Get all keys from section
Get all the configuration options values
Class implements base functor operations
Base lazy object class
Create object’s copy
Metaclass used to create a classes includes method to generate lazy methods to access
Create operator function
Monaidic functions and classes
ErrorMonad class represents errors
NoneMonad class represents empty list, dicts, NoneType or False
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
Wrap method with exception catching and creating ErrorMonad if there was an exception
Decorator that wraps function with one arugment type checking and exception catching
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:
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]])
Class that routes signals from one from producer to consumer
Register new channel for listerning
Proccess a signal for a number of objects
Check object with all the filters
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
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.
Validator used to check is value matches regular expression
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.
Error on validation