lighty Package

commands Module

Tools for run commands in framework environment using simple manage.py script

lighty.commands.load_commands(apps=[])[source]

Load commands from applications lists

lighty.commands.load_commands_from_app(app_name)[source]

Load commands from application with name specified

Return:
list of command functions
lighty.commands.manage()[source]

Process manage command. Load all the commands from applications in configuration files and add them into autocompletition

conf Module

Package contains settings management functions

class lighty.conf.Settings(main_config, defaults={})[source]

Get settings for class

get(name, section=None)[source]

Get configuration parameter from sections

Args:
name: item name section: section name
Returns:
value stored in configuration wit specified name
has_section(section)[source]

Check is section in configuration exists

Args:
section - section name
Returns:
True if section exists or False if not
keys()[source]

Get unique configuration options names

section(section)[source]

Get all keys from section

values()[source]

Get all the configuration options values

functor Module

Class implements base functor operations

class lighty.functor.BaseFunctor[source]

Bases: lighty.functor.NewBase

Base lazy object class

create_copy(operator, operand)[source]

Create object’s copy

class lighty.functor.FunctorBase[source]

Bases: type

Metaclass used to create a classes includes method to generate lazy methods to access

lighty.functor.create_operator(operator)[source]

Create operator function

monads Module

Monaidic functions and classes

class lighty.monads.ErrorMonad(value, traceback=None)[source]

Bases: lighty.monads.NoneMonad

ErrorMonad class represents errors

class lighty.monads.NoneMonad(value)[source]

Bases: lighty.monads.ValueMonad

NoneMonad class represents empty list, dicts, NoneType or False

EMPTY_ITER = <itertools.cycle object at 0x2f737e8>
class lighty.monads.ValueMonad(value)[source]

Bases: lighty.functor.BaseFunctor

Base monad class. All the operations except comparisions and few others returns monads.

create_copy(operator, operand)[source]
value
lighty.monads.check_argument(arg)[source]

Function that checks an argument and raises exception stored in argument

lighty.monads.handle_exception(func)[source]

Handle an exception and return ErrorMonad for this exception

lighty.monads.monad_boolean(func)[source]

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

lighty.monads.monad_function(func)[source]

Decorator that wraps function with arguments, check all the values and catch all the exceptions

lighty.monads.monad_operation(func)[source]

Wrap method with exception catching and creating ErrorMonad if there was an exception

lighty.monads.monad_operator(func)[source]

Decorator that wraps function with one arugment type checking and exception catching

signals Module

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]])
class lighty.signals.SignalDispatcher[source]

Class that routes signals from one from producer to consumer

channel(key, handler, filters=None)[source]

Register new channel for listerning

Args:
key - channel key handler - handler function filters - list of filters for hadnler specified
signal(key, objects=[])[source]

Proccess a signal for a number of objects

lighty.signals.check_filters(obj, filters)[source]

Check object with all the filters

utils Module

Some utilitary classes usually used to make working with different python versions and different environment easier:

  • string_types - basestring for python 2 and str fot python 3
  • dict_keys - convert dict keys to list
  • div_operators - operators for division
  • with_metaclass - metaclasses
lighty.utils.with_metaclass(meta, base=<type 'object'>)[source]

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

class Meta(type):
pass
class Base(object):
pass
class MyClass(with_metaclass(Meta, Base)):
pass

validators Module

Module contains base validators that can be used to check the data

class lighty.validators.ChoicesValidator(choices, message=None, code=None)[source]

Bases: object

Validator used to validate choices list

class lighty.validators.MaxLengthValidator(max_length)[source]

Raises a ValidationError with a code of ‘max_length’ if length of value is greater than max_value.

class lighty.validators.MaxValueValidator(max_value)[source]

Raises a ValidationError with a code of ‘max_value’ if value is greater than max_value.

class lighty.validators.MinLengthValidator(min_length)[source]

Raises a ValidationError with a code of ‘min_length’ if length of value is less than min_length.

class lighty.validators.MinValueValidator(min_value)[source]

Raises a ValidationError with a code of ‘min_value’ if value is less than min_value.

class lighty.validators.RegexValidator(regex, message=None, code=None)[source]

Bases: object

Validator used to check is value matches regular expression

class lighty.validators.URLValidator(verify_exists=False, validator_user_agent='')[source]

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.

exception lighty.validators.ValidationError(message, code=None)[source]

Bases: exceptions.Exception

Error on validation

Table Of Contents

Previous topic

lighty

Next topic

lighty.db Package (Lighty framework ORM layer)

This Page