29 "registry_decisions": [], |
29 "registry_decisions": [], |
30 } |
30 } |
31 |
31 |
32 |
32 |
33 def subscribe_to_debug_channel(channel, subscriber): |
33 def subscribe_to_debug_channel(channel, subscriber): |
|
34 """ |
|
35 Allow to subscribe a callable to one of the debug channels. |
|
36 |
|
37 The channel must be one of: %s |
|
38 |
|
39 And the callable need to accept one argument. |
|
40 |
|
41 It will raise Exception if the channel doesn't exist. |
|
42 """ % SUBSCRIBERS.keys() |
34 if channel not in SUBSCRIBERS.keys(): |
43 if channel not in SUBSCRIBERS.keys(): |
35 raise Exception("debug channel '%s' doesn't exist" % channel) |
44 raise Exception("debug channel '%s' doesn't exist" % channel) |
36 |
45 |
37 SUBSCRIBERS[channel].append(subscriber) |
46 SUBSCRIBERS[channel].append(subscriber) |
38 |
47 |
39 |
48 |
40 def unsubscribe_to_debug_channel(channel, subscriber): |
49 def unsubscribe_to_debug_channel(channel, subscriber): |
|
50 """ |
|
51 Unsubscribe a callable from a channel. It will raise Exception if the |
|
52 channel doesn't exist nor |
|
53 """ |
41 if channel not in SUBSCRIBERS.keys(): |
54 if channel not in SUBSCRIBERS.keys(): |
42 raise Exception("debug channel '%s' doesn't exist" % channel) |
55 raise Exception("debug channel '%s' doesn't exist" % channel) |
43 |
56 |
44 if subscriber not in SUBSCRIBERS[channel]: |
57 if subscriber not in SUBSCRIBERS[channel]: |
45 raise Exception("subscriber '%s' is not in debug channel '%s'" % (subscriber, channel)) |
58 raise Exception("subscriber '%s' is not in debug channel '%s'" % (subscriber, channel)) |
46 |
59 |
47 SUBSCRIBERS[channel].remove(subscriber) |
60 SUBSCRIBERS[channel].remove(subscriber) |
48 |
61 |
49 |
62 |
50 def emit_to_debug_channel(channel, message): |
63 def emit_to_debug_channel(channel, message): |
|
64 """ |
|
65 Send a message to a specified debug channel that will call all its |
|
66 subscribers. |
|
67 |
|
68 It will raise Exception if the channel doesn't exist. |
|
69 """ |
51 if channel not in SUBSCRIBERS.keys(): |
70 if channel not in SUBSCRIBERS.keys(): |
52 raise Exception("debug channel '%s' doesn't exist" % channel) |
71 raise Exception("debug channel '%s' doesn't exist" % channel) |
53 |
72 |
54 for subscriber in SUBSCRIBERS[channel]: |
73 for subscriber in SUBSCRIBERS[channel]: |
55 try: |
74 try: |