annotate idavoll/pubsub.py @ 56:55fa890ef60b

Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService. Add getFeatures() to ComponentServiceFromNodeCreationService. Fix small error in ComponentServiceFromNodeCreationService to handle not specifying the node attribute.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 05 Nov 2004 17:14:42 +0000
parents 671ead538758
children 3e2e0040e3e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 from twisted.protocols.jabber import component,jid
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
2 from twisted.xish import utility, domish
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6 import backend
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 import xmpp_error
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
9 NS_COMPONENT = 'jabber:component:accept'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
10 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
11 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
12 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
13
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 IQ_SET = '/iq[@type="set"]'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
16 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
17 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
18 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19 PUBSUB_CREATE = PUBSUB_SET + '/create'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20 PUBSUB_PUBLISH = PUBSUB_SET + '/publish'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
21 PUBSUB_SUBSCRIBE = PUBSUB_SET + '/subscribe'
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
22 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
23 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
24 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
25 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
26 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
27
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
28 class Error(Exception):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
29 pubsub_error = None
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
30 stanza_error = None
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
31 msg = ''
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
32
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
33 class NotImplemented(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
34 stanza_error = 'feature-not-implemented'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
35
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
36 class BadRequest(Error):
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
37 stanza_error = 'bad-request'
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
38
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
39 class OptionsUnavailable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
40 stanza_error = 'feature-not-implemented'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
41 pubsub_error = 'subscription-options-unavailable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
42
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
43 class SubscriptionOptionsUnavailable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
44 stanza_error = 'not-acceptable'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
45 pubsub_error = 'subscription-options-unavailable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
46
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
47 class NodeNotConfigurable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
48 stanza_error = 'feature-not-implemented'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
49 pubsub_error = 'node-not-configurable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
50
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
51 class CreateNodeNotConfigurable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
52 stanza_error = 'not-acceptable'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
53 pubsub_error = 'node-not-configurable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
54
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
55
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
56
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
57 error_map = {
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
58 backend.NotAuthorized: ('not-authorized', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
59 backend.NodeNotFound: ('item-not-found', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
60 backend.NoPayloadAllowed: ('bad-request', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
61 backend.PayloadExpected: ('bad-request', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
62 backend.NoInstantNodes: ('not-acceptable', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
63 backend.NodeExists: ('conflict', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
64 backend.NotImplemented: ('feature-not-implemented', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
65 backend.NotSubscribed: ('not-authorized', 'requestor-not-subscribed'),
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
66 }
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
67
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
68 class Service(component.Service):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
69
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
70 __implements__ = component.IService
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
71
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
72 def __init__(self, backend):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
73 self.backend = backend
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
74
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
75 def error(self, failure, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
76 try:
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
77 e = failure.trap(Error, *error_map.keys())
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
78
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
79 if e == Error:
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
80 stanza_error = failure.value.stanza_error
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
81 pubsub_error = failure.value.pubsub_error
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
82 msg = ''
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
83 else:
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
84 stanza_error, pubsub_error = error_map[e]
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
85 msg = failure.value.msg
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
86
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
87 xmpp_error.error_from_iq(iq, stanza_error, msg)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
88 if pubsub_error:
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
89 iq.error.addElement((NS_PUBSUB_ERRORS, pubsub_error))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
90 return iq
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
91 except:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
92 xmpp_error.error_from_iq(iq, 'internal-server-error')
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
93 self.send(iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
94 raise
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
95
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
96 def success(self, result, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
97 iq.swapAttributeValues("to", "from")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
98 iq["type"] = 'result'
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
99 iq.children = result or []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
100 return iq
9
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
101
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
102 def handler_wrapper(self, handler, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
103 try:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
104 d = handler(iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
105 except:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
106 d = defer.fail()
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
107
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
108 d.addCallback(self.success, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
109 d.addErrback(self.error, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
110 d.addCallback(self.send)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
111 iq.handled = True
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
112
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
113 class ComponentServiceFromService(Service):
12
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
114
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
115 def getIdentities(self, node):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
116 results = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
117 if not node:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
118 results.append({
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
119 'category': 'pubsub',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
120 'type': 'generic',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
121 'name': 'Generic Pubsub Service'
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
122 })
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
123 return results
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
124
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
125 def getFeatures(self, node):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
126 features = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
127
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
128 if not node:
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
129 if self.backend.supports_publisher_affiliation():
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
130 features.append(NS_PUBSUB + "#publisher-affiliation")
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
131
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
132 if self.backend.supports_outcast_affiliation():
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
133 features.append(NS_PUBSUB + "#outcast-affiliation")
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
134
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
135 if self.backend.supports_persistent_items():
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
136 features.append(NS_PUBSUB + "#persistent-items")
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
137
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
138 return features
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
139
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
140 components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
141
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
142 class ComponentServiceFromNotificationService(Service):
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
143
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
144 def componentConnected(self, xmlstream):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
145 self.backend.register_notifier(self.notify)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
146
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
147 def notify(self, object):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
148 node_id = object["node_id"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
149 items = object["items"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
150 d = self.backend.get_notification_list(node_id, items)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
151 d.addCallback(self._notify, node_id)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
152
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
153 def _notify(self, list, node_id):
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
154 print list
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
155 for recipient, items in list.items():
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
156 self._notify_recipient(recipient, node_id, items)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
157
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
158 def _notify_recipient(self, recipient, node_id, itemlist):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
159 message = domish.Element((NS_COMPONENT, "message"))
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
160 message["from"] = self.parent.jabberId
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
161 message["to"] = recipient
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
162 event = message.addElement((NS_PUBSUB_EVENT, "event"))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
163 items = event.addElement("items")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
164 items["node"] = node_id
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
165 items.children.extend(itemlist)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
166 self.send(message)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
167
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
168 components.registerAdapter(ComponentServiceFromNotificationService, backend.INotificationService, component.IService)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
169
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
170 class ComponentServiceFromPublishService(Service):
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
171
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
172 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
173 xmlstream.addObserver(PUBSUB_PUBLISH, self.onPublish)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
174
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
175 def onPublish(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
176 self.handler_wrapper(self._onPublish, iq)
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
177
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
178 def _onPublish(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
179 node = iq.pubsub.publish["node"]
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
180
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
181 items = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
182 for child in iq.pubsub.publish.children:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
183 if child.__class__ == domish.Element and child.name == 'item':
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
184 items.append(child)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
185
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
186 print items
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
187
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
188 return self.backend.publish(node, items,
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
189 jid.JID(iq["from"]).userhostJID())
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
190
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
191 components.registerAdapter(ComponentServiceFromPublishService, backend.IPublishService, component.IService)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
192
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
193 class ComponentServiceFromSubscriptionService(Service):
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
194
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
195 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
196 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe)
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
197 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
198 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
199 xmlstream.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
200
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
201 def onSubscribe(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
202 self.handler_wrapper(self._onSubscribe, iq)
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
203
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
204 def _onSubscribe(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
205 if iq.pubsub.options:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
206 raise SubscribeOptionsUnavailable
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
207
48
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
208 try:
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
209 node_id = iq.pubsub.subscribe["node"]
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
210 subscriber = jid.JID(iq.pubsub.subscribe["jid"])
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
211 except KeyError:
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
212 raise BadRequest
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
213
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
214 requestor = jid.JID(iq["from"]).userhostJID()
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
215 d = self.backend.subscribe(node_id, subscriber, requestor)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
216 d.addCallback(self.return_subscription)
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
217 return d
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
218
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
219 def return_subscription(self, result):
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
220 reply = domish.Element((NS_PUBSUB, "pubsub"), NS_PUBSUB)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
221 entity = reply.addElement("entity")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
222 entity["node"] = result["node"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
223 entity["jid"] = result["jid"].full()
48
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
224 entity["affiliation"] = result["affiliation"] or 'none'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
225 entity["subscription"] = result["subscription"]
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
226 return [reply]
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
227
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
228 def onUnsubscribe(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
229 self.handler_wrapper(self._onUnsubscribe, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
230
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
231 def _onUnsubscribe(self, iq):
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
232 try:
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
233 node_id = iq.pubsub.unsubscribe["node"]
48
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
234 subscriber = jid.JID(iq.pubsub.unsubscribe["jid"])
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
235 except KeyError:
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
236 raise BadRequest
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
237
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
238 requestor = jid.JID(iq["from"]).userhostJID()
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
239 return self.backend.unsubscribe(node_id, subscriber, requestor)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
240
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
241 def onOptionsGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
242 self.handler_wrapper(self._onOptionsGet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
243
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
244 def _onOptionsGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
245 raise OptionsUnavailable
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
246
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
247 def onOptionsSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
248 self.handler_wrapper(self._onOptionsSet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
249
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
250 def _onOptionsSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
251 raise OptionsUnavailable
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
252
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
253 components.registerAdapter(ComponentServiceFromSubscriptionService, backend.ISubscriptionService, component.IService)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
254
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
255 class ComponentServiceFromNodeCreationService(Service):
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
256
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
257 def getFeatures(self, node):
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
258 features = []
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
259
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
260 if not node:
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
261 features.append(NS_PUBSUB + "#create-nodes")
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
262
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
263 if self.backend.supports_instant_nodes():
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
264 features.append(NS_PUBSUB + "#instant-nodes")
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
265
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
266 return features
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
267
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
268 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
269 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate)
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
270 xmlstream.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
271 xmlstream.addObserver(PUBSUB_CONFIGURE_SET, self.onConfigureSet)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
272
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
273 def onCreate(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
274 self.handler_wrapper(self._onCreate, iq)
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
275
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
276 def _onCreate(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
277 if iq.pubsub.options:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
278 raise CreateNodeNotConfigurable
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
279
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
280 node = iq.pubsub.create.getAttribute("node")
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
281
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
282 owner = jid.JID(iq["from"]).userhostJID()
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
283
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
284 d = self.backend.create_node(node, owner)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
285 d.addCallback(self.return_create_response, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
286 return d
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
287
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
288 def return_create_response(self, result, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
289 if iq.pubsub.create["node"] is None:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
290 reply = domish.Element('pubsub', NS_PUBSUB)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
291 entity = reply.addElement('create')
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
292 entity['node'] = result['node_id']
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
293 return reply
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
294
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
295 def onConfigureGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
296 self.handler_wrapper(self._onConfigureGet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
297
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
298 def _onConfigureGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
299 raise NodeNotConfigurable
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
300
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
301 def onConfigureSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
302 self.handler_wrapper(self._onConfigureSet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
303
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
304 def _onConfigureSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
305 raise NodeNotConfigurable
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
306
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
307 components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService)