1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15   
16  """ 
17  Classes to handle subscriptions to event streams. 
18   
19  This will eventually (in the 0.9.x timeframe) be replaced with an 
20  implementation based on message passing.  Users should be aware they will need 
21  to rewrite any custom code that touches this module! 
22  """ 
23   
24  from twisted.python import failure, log 
25   
27      """ 
28      Something that can be subscribed to. 
29      """ 
31          self.name = name 
32          self.subscriptions = set() 
 33   
35          return "<SubscriptionPoint '%s'>" % self.name 
 36   
38          """Add C{callback} to the subscriptions; returns a L{Subscription} 
39          instance.""" 
40          sub = Subscription(self, callback) 
41          self.subscriptions.add(sub) 
42          return sub 
 43   
44 -    def deliver(self, *args, **kwargs): 
 45          """ 
46          Deliver the given args and keyword args to all of the current 
47          subscribers. 
48          """ 
49          for sub in list(self.subscriptions): 
50              try: 
51                  sub.callback(*args, **kwargs) 
52              except: 
53                  log.err(failure.Failure(), 
54                          'while invoking callback %s to %s' % (sub.callback, self)) 
 55   
 58   
60      """ 
61      Represents a subscription to a L{SubscriptionPoint}; use 
62      L{SubscriptionPoint.subscribe} to get an instance. 
63      """ 
65          self.subpt = subpt 
66          self.callback = callback 
 67   
69          "Cancel the subscription" 
70          self.subpt._unsubscribe(self) 
  71