~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/python/pydispatch/robust.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Module implementing error-catching version of send (sendRobust)"""
 
2
from grass.pydispatch.dispatcher import Any, Anonymous, liveReceivers, getAllReceivers
 
3
from grass.pydispatch.robustapply import robustApply
 
4
 
 
5
 
 
6
def sendRobust(
 
7
    signal=Any,
 
8
    sender=Anonymous,
 
9
    *arguments, **named
 
10
):
 
11
    """Send signal from sender to all connected receivers catching errors
 
12
 
 
13
    signal -- (hashable) signal value, see connect for details
 
14
 
 
15
    sender -- the sender of the signal
 
16
 
 
17
        if Any, only receivers registered for Any will receive
 
18
        the message.
 
19
 
 
20
        if Anonymous, only receivers registered to receive
 
21
        messages from Anonymous or Any will receive the message
 
22
 
 
23
        Otherwise can be any python object (normally one
 
24
        registered with a connect if you actually want
 
25
        something to occur).
 
26
 
 
27
    arguments -- positional arguments which will be passed to
 
28
        *all* receivers. Note that this may raise TypeErrors
 
29
        if the receivers do not allow the particular arguments.
 
30
        Note also that arguments are applied before named
 
31
        arguments, so they should be used with care.
 
32
 
 
33
    named -- named arguments which will be filtered according
 
34
        to the parameters of the receivers to only provide those
 
35
        acceptable to the receiver.
 
36
 
 
37
    Return a list of tuple pairs [(receiver, response), ... ]
 
38
 
 
39
    if any receiver raises an error (specifically any subclass of Exception),
 
40
    the error instance is returned as the result for that receiver.
 
41
    """
 
42
    # Call each receiver with whatever arguments it can accept.
 
43
    # Return a list of tuple pairs [(receiver, response), ... ].
 
44
    responses = []
 
45
    for receiver in liveReceivers(getAllReceivers(sender, signal)):
 
46
        try:
 
47
            response = robustApply(
 
48
                receiver,
 
49
                signal=signal,
 
50
                sender=sender,
 
51
                *arguments,
 
52
                **named
 
53
            )
 
54
        except Exception as err:
 
55
            responses.append((receiver, err))
 
56
        else:
 
57
            responses.append((receiver, response))
 
58
    return responses