angelos.common.misc

Module docstring.

class angelos.common.misc.AsyncCallable(callback: Callable)

Bases: angelos.common.misc.SyncCallable

Async network callable.

class angelos.common.misc.BaseData

Bases: abc.ABC

class angelos.common.misc.EventState(states: list)

Bases: angelos.common.misc.SingleState

A state machine that triggers an event at state change.

goto(state: unicode)

Go to another state and trigger an event.

wait_for(predicate)

Wait for a state to happen.

class angelos.common.misc.Fiber

Bases: abc.ABC

Fiber that execute micro tasks (polymers) synchronously in an executor.

Subclass the Fiber class and implement your action or operation in the run method. All the sub-tasks should be implemented i separate methods decorated with @polymer. Those are tasks that will be executed in the executor in parallel with a huge number of other fibers maximizing the use of processor capacity.

class polymer(exe)

Bases: object

Decorator that makes a method run within the pool executor

classmethod pool() → concurrent.futures.thread.ThreadPoolExecutor

Global instance of Loop.

abstract run()

Implement action calling polymers in the fiber.

start()

Start the run method of the fiber.

class angelos.common.misc.LazyAttribute(loader: Callable)

Bases: object

Attribute class that allows lazy loading using a lambda.

class angelos.common.misc.Loop(name='')

Bases: object

Isolated asynchronous loop inside a thread.

property loop
classmethod main()angelos.common.misc.Loop

Global instance of Loop.

run(coro: Awaitable, callback: Optional[Callable[[concurrent.futures._base.Future], None]] = None, wait=False) → Any
class angelos.common.misc.Misc

Bases: object

Namespace for miscellanious functions and methods.

REGEX = '(?:(?P<username>[\\w\\-\\.]+)(?::(?P<password>[\\w\\-\\.]+))?@)?(?P<hostname>[\\w\\-\\.]+)(?::(?P<port>\\d+))?'
static from_ini(value: unicode) → Any

Convert INI string to python value.

Parameters

value (str) – INI string to pythonize.

Returns (Any):

Python value.

static get_loop() → asyncio.events.AbstractEventLoop

Get running loop or Loop main instance.

Returns (asyncio.AbstractEventLoop):

A running loop.

static ip() → List[Union[ipaddress.IPv4Address, ipaddress.IPv6Address]]

Get external, internal and loopback ip address.

static location(url: unicode) → Tuple[str, int]

domain and port from url.

static lookup(netloc: unicode) → Tuple[ipaddress.IPv4Address, ipaddress.IPv6Address]

IP addresses from domain.

static recurse_env(obj: Any, suffix: unicode = '', level: int = 0) → list

Recurse over the environment.

static sleep()

Sleep one async tick.

static to_ini(value: Any) → unicode

Convert python value to INI string.

Parameters

value (Any) – Value to stringify.

Returns(str):

INI string.

static unique() → unicode

Get the hardware ID.

Tries to find the unique id of the hardware, otherwise returns MAC address.

Returns

Unique hardware id.

Return type

string

static urlparse(urlstring: unicode) → dict

Parse an angelos url.

Parameters

urlstring

Returns:

static urlunparse(parts: dict) → unicode

Build url from parts

Returns (str):

Built angelos url.

class angelos.common.misc.SharedResource

Bases: object

Shared resource is a class that must be shared between threads but must be guaranteed synchronous execution. This class is a mixin and all sensitive methods in the main class should be private to the outside world, then be called via a public proxy function that calls the _run method. All calls via the _run method is handled in a thread pool executor linearly.

property pool

Expose the pool queue.

class angelos.common.misc.SharedResourceMixin

Bases: object

Shared resource is a class that must be shared between threads but must be guaranteed synchronous execution. This class is a mixin and all sensitive methods in the main class should be private to the outside world, then be called via a public proxy function that calls the _run method. All calls via the _run method is handled in a thread pool executor linearly.

execute(callback: Callable, *args, **kwargs) → Any

Execute a callable method within a thread pool executor.

Parameters
  • callback (Callable) – A callable method.

  • *args – Passes on whatever arguments.

  • *kwargs – Passes on whatever keyword arguments.

Returns (Any):

Whatever the callback returns.

property pool

Expose the pool queue.

class angelos.common.misc.SingleState(states: tuple)

Bases: angelos.common.misc.StateMachine

A state machine that allows switching between states.

property available

Expose available options.

goto(state: unicode)

Go to another state that is available.

class angelos.common.misc.StateMachine

Bases: object

A class that can hold a single state at a time.

property available

Expose available options.

goto(state: unicode)

Switch to another state.

property state

Get state.

class angelos.common.misc.SyncCallable(callback: Callable)

Bases: object

Network callable to get around cython callables.

class angelos.common.misc.ThresholdCounter(threshold=3)

Bases: object

ThresholdCounter is a helper class that counts ticks and alarms when the threshold is reached.

limit()

Returns True when the threshold is met.

reset()

Resets the counter.

tick()

Counts one tick.

class angelos.common.misc.shared(exe)

Bases: object

Decorator that makes a method run within the pool executor