fastwire package¶
fastwire.signal module¶
Created on Sat Jul 27 08:56:13 2019
@author: Reuben
Signals can be connected to multiple callable receivers. The hold weak references to those callables, so that when they are garbage collected their references are removed automatically.
-
class
fastwire.signal.
Signal
(name=None, doc=None, receiver_limit=None, condition=None, attrs=None)¶ Bases:
object
A class that can emit and receive data from multiple callables.
Parameters: - name (str) – A name of the wire [optional]
- doc (str) – A documentation string for the wire [optional]
- receiver_limit (int) – Limit the number of receivers [optional]
- condition (Condition) – An optional signal Condition.
- attrs (dict) – Optional dictionary of signal attributes.
-
add_condition
(condition)¶ Add a condition that the signal must pass to be received
Parameters: condition (Condition) – A Condition instance
-
attrs
¶ The signal documentation
-
connect
(receiver, **receiver_kwargs)¶ Store weakref of receiver function or method to call
Parameters: - receiver (callable) – A callable receiver
- kwargs – Optional key word arguments
Returns: A receiver id that can be used to disconnect
Return type: float
-
disconnect
(receiver_id)¶ Disconnect a receiver
Parameters: receiver_id (int) – The id of the receiver.
-
doc
¶ The signal documentation
-
fetch
(**kwargs)¶ Get a return value from a single supplier
Parameters: **kwargs – Key word arguments.
-
fetch_all
(**kwargs)¶ Get return value from all connected callables
Parameters: **kwargs – Key word arguments. Returns: The list of return values Return type: list
-
mute
()¶ Prevent receivers from receiving signals
-
n
¶ Number of recievers
-
name
¶ The signal name
-
receivers
()¶
-
receivers_present
¶ A boolean check if receivers are present
-
remove_condition
(name)¶ Remove a condition that the signal must pass to be received
Parameters: name (str) – The name of the condition to remove.
-
reset
()¶ Reset the signal
-
unmute
()¶ Allow receivers to receive signals (after a mute)
-
class
fastwire.signal.
SignalBox
¶ Bases:
fastwire.box.Box
A collection of SignalContainers
-
signal
(name=None, doc=None, attrs=None, **kwargs)¶ Create or get a new signal instance in the active container
Parameters: - name (str) – A name of the wire/signal [optional]
- doc (str) – A documentation string for the wire/signal [optional]
- attrs (dict) – Optional diction of signal attributes.
-
-
class
fastwire.signal.
SignalContainer
(cid=None)¶ Bases:
fastwire.container.Container
A dictionary-like collection of Signal instances
-
signal
(name=None, doc=None, attrs=None, **kwargs)¶ Create or get a new signal instance
Parameters: - name (str) – A name of the wire/signal [optional]
- doc (str) – A documentation string for the wire/signal [optional]
- attrs (dict) – Optional diction of signal attributes.
-
-
fastwire.signal.
get_signal_box
(name)¶
-
fastwire.signal.
signal_box
(name)¶
-
fastwire.signal.
signal_container
(name)¶
fastwire.wire module¶
Created on Sat Jul 27 08:57:12 2019
@author: Reuben
The wire module is about simple ‘Wire’ classes. Wire instances can be connected to one, and only one, receiver (a callable). Unlike Signals, Wire instances hold normal a normal reference to the callable.
-
class
fastwire.wire.
Wire
(name=None, doc=None, attrs=None, **kwargs)¶ Bases:
object
A simple instance that can be connected to one receiver
Parameters: - name (str) – A name of the wire [optional]
- doc (str) – A documentation string for the wire [optional]
- **attributes – Optional key word arguments, which are stored as attributes of the signal.
-
attrs
¶ The wire documentation
-
connect
(receiver)¶ Connect the wire to a callable receiver
Parameters: receiver (callable) – A receiver called by the wire.
-
disconnect
()¶ Disconnect the wire from its receiver
-
doc
¶ The wire documentation
-
mute
()¶ Prevent the wire from calling the receiver
-
name
¶ The wire name
-
reset
()¶ Fully reset the wire, disconnecting it if required
-
set_default
(default)¶
-
unmute
()¶ Allow the wire to call the receiver
-
class
fastwire.wire.
WireBox
¶ Bases:
fastwire.box.Box
A collection of SignalContainers
-
wire
(name=None, doc=None, attrs=None, **kwargs)¶ Create or get a new signal instancein the active container
Parameters: - name (str) – A name of the wire/signal [optional]
- doc (str) – A documentation string for the wire/signal [optional]
- attrs (dict) – Optional diction of signal attributes.
-
-
class
fastwire.wire.
WireContainer
(cid=None)¶ Bases:
fastwire.container.Container
A dictionary-like collection of Signal instances
-
wire
(name=None, doc=None, attrs=None, **kwargs)¶ Create or get a new wire instance
Parameters: - name (str) – A name of the wire/signal [optional]
- doc (str) – A documentation string for the wire/signal [optional]
- attrs (dict) – Optional diction of signal attributes.
-
-
fastwire.wire.
get_wire_box
(name)¶
-
fastwire.wire.
wire_box
(name)¶
-
fastwire.wire.
wire_container
(name)¶
fastwire.container module¶
Created on Wed Jul 31 12:59:51 2019
@author: Reuben
-
class
fastwire.container.
Container
(signal_cls, cid=None)¶ Bases:
dict
A dictionary-like collection of Signal instances
-
get
(name=None, doc=None, attrs=None, must_exist=False, **kwargs)¶ Get or create a new Signal or Wire instance
Parameters: - name (str) – A name of the wire [optional]
- doc (str) – A documentation string for the wire [optional]
- attrs (dict) – Optional diction of signal attributes.
- must_exist (bool) – True if the signal must already exist
-
mute_all
()¶ Mute all signals in the container
-
reset_all
()¶ Reset all wires in the contain
-
unmute_all
()¶ Unmute all signals in the container
-
fastwire.box module¶
Created on Wed Jul 31 12:56:25 2019
@author: Reuben
-
class
fastwire.box.
Box
(container_cls)¶ Bases:
object
A collection of containers
It’s used to allow client classes to create sets of signals for specific instances. Other classes instantiated can call an instance of this class to get signals within the appropriate set. This can help to avoid signals getting mixed up.
-
active
¶ Return the active container id
-
add
(cid=None, activate=True, remove_with=None)¶ Add a new container referenced with cid
Parameters: - cid (int, str) – A reference for the container
- activate (bool) – Set the container as the active one
- remove_with (object) – An object to associate the container with. When the object is garbage collected, its container and all signals within it will also be removed. This can be useful to avoid objects accumulating in memory.
Returns: The container
Return type: Note
Container id is available via container.id.
-
clear
()¶ Clear all containers in the box
-
containers
¶ Return a dictionary of containers in the box
-
deactivate
(cid=None)¶ Set the active container to ‘default’
Parameters: cid (int) – An optional container id. If this id is given, the active container will only be changed if this container is currently active.
-
get
(name=None, doc=None, attrs=None, **kwargs)¶ Create or get a new wire/signal instance in the active container
Parameters: - name (str) – A name of the wire/signal [optional]
- doc (str) – A documentation string for the wire/signal [optional]
- attrs (dict) – Optional diction of signal attributes.
-
get_active
()¶ Return the currently active container
-
get_container
(cid=None)¶ Return the container given by a container id
-
remove
(cid)¶ Remove a container
Parameters: cid (int, str) – The container reference
-
remove_with
(obj, cid=None)¶ Set this box to be removed when an object is garbage collected
Parameters: - obj (object) – The object to remove the container with
- cid (int) – The optional container id to remove. Defaults to the active container.
-
reset_all
()¶ Reset all wires in all containers
-
set_active
(cid)¶ Set the active container
Parameters: cid (int, str) – The container reference
-
fastwire.condition module¶
Created on Sat Jul 27 08:58:09 2019
@author: Reuben
Conditions apply logic to whether or not particular receivers receive particular signals. They are designed to be open, so that you can add your own condition classes with your own logic.
-
class
fastwire.condition.
Condition
¶ Bases:
object
Template class for a signal condition
- Class attributes:
- name (str): A class attribute that gives their name.
-
check
(**kwargs)¶ The main check call - must return a boolean
All Condition classes must implement a method called ‘check’. The check method is passed a set of key word arguments provided by the sender and the receiver.
-
name
= 'default'¶
fastwire.decorate module¶
Created on Sat Jul 27 08:58:26 2019
@author: Reuben
The decorate module contians a number of decorators which assist with automatically connecting methods and functions.
-
fastwire.decorate.
ensure_signal_obj
(signal, box, container, receiver_limit=None)¶
-
fastwire.decorate.
fn_receive
(s, box=None, container=None, **receiver_kwargs)¶ A decorator to connect methods to Signal instances automatically
Parameters: - s (Signal) – A Signal instance, or list of Signal instances.
- box (Box) – [Optional] The box for the active container.
- container (Container) – [Optional] The container for the signal.
- **receiver_kwargs – Any number of key word arguments. These are passed to any Condition instances added to the Signal instance.
-
fastwire.decorate.
fn_supply
(s, box=None, container=None, **receiver_kwargs)¶ A decorator to set methods to be the sole source for a Signal
Parameters: - s (Signal) – A Signal instance, or list of Signal instances.
- **receiver_kwargs – Any number of key word arguments. These are passed to any Condition instances added to the Signal instance.
-
fastwire.decorate.
receive
(s, box=None, container=None, **receiver_kwargs)¶ A decorator to connect methods to Signal instances automatically
Parameters: - s (Signal) – A Signal instance, or list of Signal instances.
- box (Box) – [Optional] The box for the active container.
- container (Container) – [Optional] The container for the signal.
- **receiver_kwargs – Any number of key word arguments. These are passed to any Condition instances added to the Signal instance.
-
fastwire.decorate.
supply
(s, box=None, container=None, **receiver_kwargs)¶ A decorator to set methods to be the sole source for a Signal
Parameters: - s (Signal) – A Signal instance, or list of Signal instances.
- box (Box) – [Optional] The box for the active container.
- container (Container) – [Optional] The container for the signal.
- **receiver_kwargs – Any number of key word arguments. These are passed to any Condition instances added to the Signal instance.