Package buildbot :: Package util :: Module subscription
[frames] | no frames]

Source Code for Module buildbot.util.subscription

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  from twisted.python import failure, log 
17   
18 -class SubscriptionPoint(object):
19 - def __init__(self, name):
20 self.name = name 21 self.subscriptions = set()
22
23 - def __str__(self):
24 return "<SubscriptionPoint '%s'>" % self.name
25
26 - def subscribe(self, callback):
27 sub = Subscription(self, callback) 28 self.subscriptions.add(sub) 29 return sub
30
31 - def deliver(self, *args, **kwargs):
32 for sub in list(self.subscriptions): 33 try: 34 sub.callback(*args, **kwargs) 35 except: 36 log.err(failure.Failure(), 37 'while invoking callback %s to %s' % (sub.callback, self))
38
39 - def _unsubscribe(self, subscription):
40 self.subscriptions.remove(subscription)
41
42 -class Subscription(object):
43 - def __init__(self, subpt, callback):
44 self.subpt = subpt 45 self.callback = callback
46
47 - def unsubscribe(self):
48 self.subpt._unsubscribe(self)
49