ouimeaux.pysignals package

Submodules

ouimeaux.pysignals.dispatcher module

class ouimeaux.pysignals.dispatcher.Signal(providing_args=None, use_caching=False)[source]

Bases: object

Base class for all signals

Internal attributes:

receivers
{ receiverkey (id) : weakref(receiver) }
connect(receiver, sender=None, weak=True, dispatch_uid=None)[source]

Connect receiver to sender for signal.

Arguments:

receiver

A function or an instance method which is to receive signals. Receivers must be hashable objects.

If weak is True, then receiver must be weak referenceable.

Receivers must be able to accept keyword arguments.

If a receiver is connected with a dispatch_uid argument, it will not be added if another receiver was already connected with that dispatch_uid.

sender
The sender to which the receiver should respond. Must either be of type Signal, or None to receive events from any sender.
weak
Whether to use weak references to the receiver. By default, the module will attempt to use weak references to the receiver objects. If this parameter is false, then strong references will be used.
dispatch_uid
An identifier used to uniquely identify a particular instance of a receiver. This will usually be a string, though it may be anything hashable.
disconnect(receiver=None, sender=None, weak=None, dispatch_uid=None)[source]

Disconnect receiver from sender for signal.

If weak references are used, disconnect need not be called. The receiver will be remove from dispatch automatically.

Arguments:

receiver
The registered receiver to disconnect. May be none if dispatch_uid is specified.
sender
The registered sender to disconnect
dispatch_uid
the unique identifier of the receiver to disconnect
has_listeners(sender=None)[source]
receive(**kwargs)[source]

A decorator for connecting receivers to this signal. Used by passing in the keyword arguments to connect:

@post_save.receive(sender=MyModel)
def signal_receiver(sender, **kwargs):
    ...
send(sender, **named)[source]

Send signal from sender to all connected receivers.

If any receiver raises an error, the error propagates back through send, terminating the dispatch loop. So it’s possible that all receivers won’t be called if an error is raised.

Arguments:

sender
The sender of the signal. Either a specific object or None.
named
Named arguments which will be passed to receivers.

Returns a list of tuple pairs [(receiver, response), … ].

send_robust(sender, **named)[source]

Send signal from sender to all connected receivers catching errors.

Arguments:

sender
The sender of the signal. Can be any python object (normally one registered with a connect if you actually want something to occur).
named
Named arguments which will be passed to receivers. These arguments must be a subset of the argument names defined in providing_args.

Return a list of tuple pairs [(receiver, response), … ]. May raise DispatcherKeyError.

If any receiver raises an error (specifically any subclass of Exception), the error instance is returned as the result for that receiver. The traceback is always attached to the error at __traceback__.

class ouimeaux.pysignals.dispatcher.StateChange(providing_args=None)[source]

Bases: ouimeaux.pysignals.dispatcher.Signal

send(sender, **named)[source]

Send signal from sender to all connected receivers only if the signal’s contents has changed.

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.

Arguments:

sender
The sender of the signal Either a specific object or None.
named
Named arguments which will be passed to receivers.

Returns a list of tuple pairs [(receiver, response), … ].

ouimeaux.pysignals.dispatcher.receiver(signal, **kwargs)[source]

A decorator for connecting receivers to signals. Used by passing in the signal (or list of signals) and keyword arguments to connect:

@receiver(post_save, sender=MyModel)
def signal_receiver(sender, **kwargs):
    ...

@receiver([post_save, post_delete], sender=MyModel)
def signals_receiver(sender, **kwargs):
    ...
ouimeaux.pysignals.dispatcher.set_debug(val)[source]

ouimeaux.pysignals.inspect module

ouimeaux.pysignals.inspect.func_accepts_kwargs(func)[source]
ouimeaux.pysignals.inspect.func_accepts_var_args(func)[source]

Return True if function ‘func’ accepts positional arguments *args.

ouimeaux.pysignals.inspect.func_has_no_args(func)[source]
ouimeaux.pysignals.inspect.func_supports_parameter(func, parameter)[source]
ouimeaux.pysignals.inspect.get_func_args(func)[source]
ouimeaux.pysignals.inspect.get_func_full_args(func)[source]

Return a list of (argument name, default value) tuples. If the argument does not have a default value, omit it in the tuple. Arguments such as *args and **kwargs are also included.

ouimeaux.pysignals.inspect.getargspec(func)[source]

ouimeaux.pysignals.weakref_backports module

weakref_backports is a partial backport of the weakref module for python versions below 3.4.

Copyright (C) 2013 Python Software Foundation, see license.python.txt for details.

The following changes were made to the original sources during backporting:

  • Added self to super calls.
  • Removed from None when raising exceptions.
class ouimeaux.pysignals.weakref_backports.WeakMethod[source]

Bases: weakref

A custom weakref.ref subclass which simulates a weak reference to a bound method, working around the lifetime problem of bound methods.

Module contents

Multi-consumer multi-producer dispatching mechanism

Originally based on pydispatch (BSD) http://pypi.python.org/pypi/PyDispatcher/2.0.1 See license.txt for original license.

Heavily modified for Django’s purposes.