imagination.entity

Author:Juti Noppornpitak

The module contains the package entity used to be an intermediate between imagination.locator.Locator and imagination.loader.Loader and simulate the singleton class on the package in the Loader.

Note

Copyright (c) 2012 Juti Noppornpitak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class imagination.entity.CallbackProxy(callback, args=[], kwargs={}, static=False)[source]

Callback Proxy

A proxy to a callback function where it executes the method with pre-defined parameters whenever it is called. The end result will be cached by the proxy.

New in version 1.6.

class imagination.entity.Entity(id, loader, *args, **kwargs)[source]

Entity represents the package, reference and instance of the reference.

Parameters:
  • id – the service identifier (string).
  • loader – a service loader which is an instance of imagination.loader.Loader.
  • args (dict) – constructor’s parameters
  • kwargs – constructor’s parameters

If the loader is not an instance of imagination.loader.Loader or any classes based on imagination.loader.Loader, the exception imagination.exception.UnknownLoaderError will be thrown.

Note

This class is to similar to the decorator tori.decorator.common.singleton and tori.decorator.common.singleton_with from Tori Framework, except that it is not a singleton class and so any arbitrary class referenced by the loader only lasts as long as the entity lives.

Note

In version 1.5, the entity has the ability to fork an non-supervised instance of the reference.

activated

Check if the entity is already activated.

This will also inspects if the entity already loads a singleton instance into the memory.

argument_dictionary

Get the argument dictionary.

argument_list

Get the argument list.

fork()[source]
Version:1.5

Fork an instance of the class defined for the loader.

id

Entity ID

Return type:strint or unicode or integer
instance

Get the singleton instance of the class defined for the loader.

loader

Package loader

Return type:imagination.loader.Loader
tags

Retrieve the entity tags.

Return type:list
class imagination.entity.ReferenceProxy(reference)[source]

Reference Proxy

New in version 1.20.

Warning

experimental feature