Package pytilities :: Package delegation :: Module delegatorfactory :: Class DelegatorFactory
[hide private]
[frames] | no frames]

Class DelegatorFactory

source code

object --+
         |
        DelegatorFactory


Allows easy creation of delegators with `Profile`s.

It also supports a form of inheritance. By specifying base
factories, a factory extends its bases' profiles (it takes the union of all
base profiles and its own). Using the inheritance you can add new profiles
and add attributes to existing profiles; you cannot, however, override
attributes.

Instance methods:

    - `add_delegator_profile`: Add a `Profile`
    - `Delegator`: Construct a `Delegator` from a stored profile
    - `has_profile`: See if we have a particular profile
    - `get_profile`: Get profile by name

Class invariants:

    - Every profile has a unique name

Instance Methods [hide private]
 
__init__(self, bases=())
Construct a `DelegatorFactory`, optionally with bases to inherit from.
source code
 
add_delegator_profile(self, name, profile)
Add a new delegator factory `Profile` to the factory.
source code
 
Delegator(self, profile_name='default', target=None)
Construct a delegator with a stored `Profile`.
source code
 
has_profile(self, name)
See if profile with given name exists.
source code
 
get_profile(self, name)
Get profile by name.
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, bases=())
(Constructor)

source code 

Construct a `DelegatorFactory`, optionally with bases to inherit from.

Parameters:

    `bases` :: (::DelegatorFactory...)
        base factories for the created factory

Overrides: object.__init__

add_delegator_profile(self, name, profile)

source code 

Add a new delegator factory `Profile` to the factory.

Parameters:

    `name` :: string
        name of the profile

    `profile` :: Profile
        the profile to add

Delegator(self, profile_name='default', target=None)

source code 

Construct a delegator with a stored `Profile`.

Parameters:

    `profile_name` :: string
        name of the `Profile` to use to set up the delegator with

    `target` = None
        target of the newly created delegator

Returns newly created delegator :: Delegator

Raises:

    - `ValueError` when no profile with name `profile_name` exists

has_profile(self, name)

source code 

See if profile with given name exists.

Parameters:

    `name` :: string
        name of the profile to look for

Returns True if the factory can find a profile by that name, False
otherwise

get_profile(self, name)

source code 

Get profile by name.

Parameters:

    `name` :: string
        name of the profile

Returns profile by name, taking into account base factories' profiles 
:: Profile

Raises:
    - `ValueError` when profile isn't found