Mercurial > libervia-pubsub
comparison idavoll/backend.py @ 18:7937d6fbbe2a
Small code cleanups
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Mon, 30 Aug 2004 17:41:18 +0000 |
parents | 46cd13c68ac0 |
children | eddea65d1032 |
comparison
equal
deleted
inserted
replaced
17:0861c0f2e3b5 | 18:7937d6fbbe2a |
---|---|
55 def __init__(self): | 55 def __init__(self): |
56 self.nodes = {} | 56 self.nodes = {} |
57 | 57 |
58 node = Node("ralphm/mood/ralphm@ik.nu") | 58 node = Node("ralphm/mood/ralphm@ik.nu") |
59 node.subscriptions["ralphm@doe.ik.nu"] = Subscription("subscribed") | 59 node.subscriptions["ralphm@doe.ik.nu"] = Subscription("subscribed") |
60 node.subscriptions["notify@ik.nu/mood_monitor"] = Subscription("subscribed") | |
60 node.affiliations["ralphm@ik.nu"] = "owner" | 61 node.affiliations["ralphm@ik.nu"] = "owner" |
61 node.affiliations["ralphm@doe.ik.nu"] = "publisher" | 62 node.affiliations["ralphm@doe.ik.nu"] = "publisher" |
62 node.configuration.persist_items = True | 63 node.configuration.persist_items = True |
63 node.configuration.deliver_payloads = True | 64 node.configuration.deliver_payloads = True |
64 self.nodes[node.name] = node | 65 self.nodes[node.name] = node |
75 try: | 76 try: |
76 if node.affiliations[publisher] not in ['owner', 'publisher']: | 77 if node.affiliations[publisher] not in ['owner', 'publisher']: |
77 raise NotAuthorized | 78 raise NotAuthorized |
78 except KeyError: | 79 except KeyError: |
79 raise NotAuthorized() | 80 raise NotAuthorized() |
80 | |
81 # the following is under the assumption that the publisher | |
82 # has to provide an item when the node is persistent, but | |
83 # an empty notification is to be sent. | |
84 | 81 |
85 if items and not persist_items and not deliver_payloads: | 82 if items and not persist_items and not deliver_payloads: |
86 raise NoPayloadAllowed | 83 raise NoPayloadAllowed |
87 elif not items and (persist_items or deliver_payloads): | 84 elif not items and (persist_items or deliver_payloads): |
88 raise PayloadExpected | 85 raise PayloadExpected |
105 recipients.addCallback(self.magic_filter, node_id, items) | 102 recipients.addCallback(self.magic_filter, node_id, items) |
106 recipients.addCallback(self.pubsub_service.do_notification, node_id) | 103 recipients.addCallback(self.pubsub_service.do_notification, node_id) |
107 | 104 |
108 return defer.succeed(None) | 105 return defer.succeed(None) |
109 except: | 106 except: |
110 f = failure.Failure() | 107 return defer.fail(failure.Failure()) |
111 return defer.fail(f) | |
112 | 108 |
113 def do_subscribe(self, node_id, subscriber, requestor): | 109 def do_subscribe(self, node_id, subscriber, requestor): |
114 # expect subscriber and requestor to be a jid.JID | 110 # expect subscriber and requestor to be a jid.JID |
115 try: | 111 try: |
116 try: | 112 try: |
142 'affiliation': affiliation, | 138 'affiliation': affiliation, |
143 'node': node_id, | 139 'node': node_id, |
144 'jid': subscriber, | 140 'jid': subscriber, |
145 'subscription': subscription.state}) | 141 'subscription': subscription.state}) |
146 except: | 142 except: |
147 f = failure.Failure() | 143 return defer.fail(failure.Failure) |
148 return defer.fail(f) | |
149 | 144 |
150 | 145 |
151 def magic_filter(self, subscribers, node_id, items): | 146 def magic_filter(self, subscribers, node_id, items): |
152 list = {} | 147 list = {} |
153 for subscriber in subscribers: | 148 for subscriber in subscribers: |