Mercurial > libervia-pubsub
annotate idavoll/pubsub.py @ 25:256dcda26752
Bugfix: use 'event' element instead of 'x' for notifications.
Changed adapter registration to reflect name change of backend.IService.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 17 Oct 2004 13:53:01 +0000 |
parents | 884268687229 |
children | fa866793075d |
rev | line source |
---|---|
1 | 1 from twisted.protocols.jabber import component,jid |
2 | 2 from twisted.xish import utility, domish |
1 | 3 from twisted.python import components |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
4 from twisted.internet import defer |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
5 |
1 | 6 import backend |
7 import xmpp_error | |
8 | |
2 | 9 NS_COMPONENT = 'jabber:component:accept' |
10 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | |
11 NS_PUBSUB_EVENT = NS_PUBSUB + '#event' | |
16 | 12 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors' |
2 | 13 |
1 | 14 IQ_GET = '/iq[@type="get"]' |
15 IQ_SET = '/iq[@type="set"]' | |
2 | 16 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]' |
17 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT | |
18 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT | |
1 | 19 PUBSUB_CREATE = PUBSUB_SET + '/create' |
20 PUBSUB_PUBLISH = PUBSUB_SET + '/publish' | |
16 | 21 PUBSUB_SUBSCRIBE = PUBSUB_SET + '/subscribe' |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
22 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options' |
21 | 23 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options' |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
24 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure' |
21 | 25 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure' |
1 | 26 |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
27 class PubSubError(Exception): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
28 pubsub_error = None |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
29 msg = '' |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
30 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
31 class NotImplemented(PubSubError): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
32 pass |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
33 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
34 class OptionsUnavailable(PubSubError): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
35 pubsub_error = 'subscription-options-unavailable' |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
36 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
37 class SubscriptionOptionsUnavailable(PubSubError): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
38 pubsub_error = 'subscription-options-unavailable' |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
39 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
40 class NodeNotConfigurable(PubSubError): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
41 pubsub_error = 'node-not-configurable' |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
42 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
43 class CreateNodeNotConfigurable(PubSubError): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
44 pubsub_error = 'node-not-configurable' |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
45 |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
46 error_map = { |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
47 backend.NotAuthorized: 'not-authorized', |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
48 backend.NodeNotFound: 'item-not-found', |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
49 backend.NoPayloadAllowed: 'bad-request', |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
50 backend.PayloadExpected: 'bad-request', |
21 | 51 backend.NoInstantNodes: 'not-acceptable', |
52 backend.NodeExists: 'conflict', | |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
53 NotImplemented: 'feature-not-implemented', |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
54 OptionsUnavailable: 'feature-not-implemented', |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
55 SubscriptionOptionsUnavailable: 'not-acceptable', |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
56 NodeNotConfigurable: 'feature-not-implemented', |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
57 CreateNodeNotConfigurable: 'not-acceptable', |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
58 } |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
59 |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
60 class ComponentServiceFromBackend(component.Service): |
1 | 61 |
62 def __init__(self, backend): | |
63 self.backend = backend | |
2 | 64 self.backend.pubsub_service = self |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
65 |
1 | 66 def componentConnected(self, xmlstream): |
67 xmlstream.addObserver(PUBSUB_SET, self.onPubSub) | |
68 xmlstream.addObserver(PUBSUB_GET, self.onPubSub) | |
69 | |
9 | 70 def getIdentities(self, node): |
71 results = [] | |
72 if not node: | |
73 results.append({ | |
74 'category': 'pubsub', | |
75 'type': 'generic', | |
76 'name': 'Generic Pubsub Service' | |
77 }) | |
78 return results | |
79 | |
12 | 80 def getFeatures(self, node): |
81 return [ | |
82 "http://jabber.org/protocol/pubsub#outcast-affil", | |
83 "http://jabber.org/protocol/pubsub#publisher-affil", | |
16 | 84 "http://jabber.org/protocol/pubsub#persistent-items", |
12 | 85 ] |
86 | |
1 | 87 def error(self, failure, iq): |
16 | 88 try: |
89 r = failure.trap(*error_map.keys()) | |
90 xmpp_error.error_from_iq(iq, error_map[r], failure.value.msg) | |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
91 if isinstance(failure.value, PubSubError) and \ |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
92 failure.value.pubsub_error is not None: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
93 iq.error.addElement((NS_PUBSUB_ERRORS, |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
94 failure.value.pubsub_error), |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
95 NS_PUBSUB_ERRORS) |
16 | 96 return iq |
97 except: | |
98 xmpp_error.error_from_iq(iq, 'internal-server-error') | |
99 self.send(iq) | |
100 raise | |
1 | 101 |
102 def success(self, result, iq): | |
103 iq.swapAttributeValues("to", "from") | |
104 iq["type"] = 'result' | |
18 | 105 iq.children = result or [] |
1 | 106 return iq |
107 | |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
108 def onPubSub(self, iq): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
109 for elem in iq.pubsub.elements(): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
110 if not elem.hasAttribute('xmlns'): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
111 action = elem.name |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
112 break |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
113 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
114 if not action: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
115 return |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
116 |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
117 try: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
118 try: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
119 handler = getattr(self, 'on%s%s' % (action.capitalize(), |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
120 iq["type"].capitalize())) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
121 except KeyError: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
122 raise NotImplemented |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
123 else: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
124 d = handler(iq) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
125 except: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
126 d = defer.fail() |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
127 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
128 d.addCallback(self.success, iq) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
129 d.addErrback(self.error, iq) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
130 d.addCallback(self.send) |
1 | 131 iq.handled = True |
132 | |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
133 # action handlers |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
134 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
135 def onPublishSet(self, iq): |
1 | 136 node = iq.pubsub.publish["node"] |
137 | |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
138 items = [] |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
139 for child in iq.pubsub.publish.children: |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
140 if child.__class__ == domish.Element and child.name == 'item': |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
141 items.append(child) |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
142 |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
143 print items |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
144 |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
145 return self.backend.do_publish(node, |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
146 jid.JID(iq["from"]).userhost(), |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
147 items) |
1 | 148 |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
149 def onOptionsGet(self, iq): |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
150 raise OptionsUnavailable |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
151 |
21 | 152 def onOptionsSet(self, iq): |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
153 raise OptionsUnavailable |
21 | 154 |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
155 def onConfigureGet(self, iq): |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
156 raise NodeNotConfigurable |
16 | 157 |
21 | 158 def onConfigureSet(self, iq): |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
159 raise NodeNotConfigurable |
21 | 160 |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
161 def onSubscribeSet(self, iq): |
21 | 162 if iq.pubsub.options: |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
163 raise SubscribeOptionsUnavailable |
21 | 164 |
16 | 165 node_id = iq.pubsub.subscribe["node"] |
166 subscriber = jid.JID(iq.pubsub.subscribe["jid"]) | |
167 requestor = jid.JID(iq["from"]).userhostJID() | |
168 d = self.backend.do_subscribe(node_id, subscriber, requestor) | |
18 | 169 d.addCallback(self.return_subscription) |
170 d.addCallback(self.succeed, iq) | |
16 | 171 d.addErrback(self.error, iq) |
172 d.addCallback(self.send) | |
173 | |
18 | 174 def return_subscription(self, result): |
175 reply = domish.Element("pubsub", NS_PUBSUB) | |
16 | 176 entity = reply.addElement("entity") |
177 entity["node"] = result["node"] | |
178 entity["jid"] = result["jid"].full() | |
179 entity["affiliation"] = result["affiliation"] | |
180 entity["subscription"] = result["subscription"] | |
18 | 181 return reply |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
182 |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
183 def onCreateSet(self, iq): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
184 if iq.pubsub.options: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
185 raise CreateNodeNotConfigurable |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
186 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
187 node = iq.pubsub.create["node"] |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
188 owner = jid.JID(iq["from"]).userhostJID() |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
189 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
190 d = self.backend.create_node(node, owner) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
191 d.addCallback(self.return_create_response, iq) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
192 return d |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
193 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
194 def return_create_response(self, result, iq): |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
195 if iq.pubsub.create["node"] is None: |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
196 reply = domish.Element('pubsub', NS_PUBSUB) |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
197 entity = reply.addElement('create') |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
198 entity['node'] = result['node_id'] |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
199 return reply |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
200 |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
201 # other methods |
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
202 |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
203 def do_notification(self, list, node): |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
204 for recipient, items in list.items(): |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
205 self.notify(node, items, recipient) |
2 | 206 |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
207 def notify(self, node, itemlist, recipient): |
2 | 208 message = domish.Element((NS_COMPONENT, "message")) |
209 message["from"] = self.parent.jabberId | |
210 message["to"] = recipient | |
25
256dcda26752
Bugfix: use 'event' element instead of 'x' for notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
211 event = message.addElement((NS_PUBSUB_EVENT, "event"), NS_PUBSUB_EVENT) |
256dcda26752
Bugfix: use 'event' element instead of 'x' for notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
212 items = event.addElement("items") |
2 | 213 items["node"] = node |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
214 items.children.extend(itemlist) |
2 | 215 self.send(message) |
216 | |
25
256dcda26752
Bugfix: use 'event' element instead of 'x' for notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
23
diff
changeset
|
217 components.registerAdapter(ComponentServiceFromBackend, backend.IService, component.IService) |
1 | 218 |