The dispatcher module is accessible via the sqlobject.include.pydispatch module.
dispatcher is the core of the PyDispatcher system, providing the primary API and the core logic for the system.
Module attributes of note:
- Any -- Singleton used to signal either "Any Sender" or
- "Any Signal". See documentation of the _Any class.
- Anonymous -- Singleton used to signal "Anonymous Sender"
- See documentation of the _Anonymous class.
connections -- { senderkey (id) : { signal : [receivers...]}} senders -- { senderkey (id) : weakref(sender) }
used for cleaning up sender references on sender deletion
{167497036: {<class 'sqlobject.events.ClassCreateSignal'>: [<weakref at 0x9fbb6bc; to 'function' at 0x9fb9f44 (_makeSubclassConnections)>]}}
(<type 'weakref'>, <class 'sqlobject.include.pydispatch.saferef.BoundMethodWeakref'>)
Connect receiver to sender for signal
messages/signals/events. Receivers must be hashable objects.
if weak is True, then receiver must be weak-referencable (more precisely saferef.safeRef() must be able to create a reference to the receiver).
Receivers are fairly flexible in their specification, as the machinery in the robustApply module takes care of most of the details regarding figuring out appropriate subsets of the sent arguments to apply to a given receiver.
signal -- the signal to which the receiver should respond
if Any, receiver will receive any signal from the indicated sender (which might also be Any, but is not necessarily Any).
Otherwise must be a hashable Python object other than None (DispatcherError raised on None).
sender -- the sender to which the receiver should respond
if Any, receiver will receive the indicated signals from any sender.
if Anonymous, receiver will only receive indicated signals from send/sendExact which do not specify a sender, or specify Anonymous explicitly as the sender.
Otherwise can be any python object.
returns None, may raise DispatcherTypeError
Disconnect receiver from sender for signal
receiver -- the registered receiver to disconnect signal -- the registered signal to disconnect sender -- the registered sender to disconnect weak -- the weakref state to disconnect
disconnect reverses the process of connect, the semantics for the individual elements are logically equivalent to a tuple of (receiver, signal, sender, weak) used as a key to be deleted from the internal routing tables. (The actual process is slightly more complex but the semantics are basically the same).
Get list of receivers from global tables
This utility function allows you to retrieve the raw list of receivers from the connections table for the given sender and signal pair.
Normally you would use liveReceivers( getReceivers( ...)) to retrieve the actual receiver objects as an iterable object.
Filter sequence of receivers to get resolved, live receivers
This is a generator which will iterate over the passed sequence, checking for weak references and resolving them, then returning all live receivers.
Get list of all receivers from global tables
This gets all receivers which should receive the given signal from sender, each receiver should be produced only once by the resulting generator
Send signal from sender to all connected receivers.
signal -- (hashable) signal value, see connect for details
sender -- the sender of the signal
if Any, only receivers registered for Any will receive the message.
if Anonymous, only receivers registered to receive messages from Anonymous or Any will receive the message
Otherwise can be any python object (normally one registered with a connect if you actually want something to occur).
Return a list of tuple pairs [(receiver, response), ... ]
if any receiver raises an error, the error propagates back through send, terminating the dispatch loop, so it is quite possible to not have all receivers called if a raises an error.
Send signal only to those receivers registered for exact message
sendExact allows for avoiding Any/Anonymous registered handlers, sending only to those receivers explicitly registered for a particular signal on a particular sender.
See the source for more information.