comparison src/tmp/wokkel/rsm.py @ 1432:60c41422ee48

tmp (rsm): better use of domish.Element.elements() + minor fixes
author Goffi <goffi@goffi.org>
date Wed, 27 May 2015 19:12:38 +0200
parents 2d8fccec84e8
children ea48663b2605
comparison
equal deleted inserted replaced
1431:70abe871eac3 1432:60c41422ee48
92 92
93 @return: RSMRequest instance. 93 @return: RSMRequest instance.
94 @rtype: L{RSMRequest} 94 @rtype: L{RSMRequest}
95 """ 95 """
96 try: 96 try:
97 set_elt = domish.generateElementsQNamed(element.elements(), 97 set_elt = element.elements(NS_RSM, 'set').next()
98 name="set",
99 uri=NS_RSM).next()
100 except StopIteration: 98 except StopIteration:
101 raise RSMNotFoundError() 99 raise RSMNotFoundError()
102 100
103 request = RSMRequest() 101 request = RSMRequest()
104 for elt in list(set_elt.elements()): 102 for elt in list(set_elt.elements()):
192 190
193 @return: RSMResponse instance. 191 @return: RSMResponse instance.
194 @rtype: L{RSMResponse} 192 @rtype: L{RSMResponse}
195 """ 193 """
196 try: 194 try:
197 set_elt = domish.generateElementsQNamed(element.elements(), 195 set_elt = element.elements(NS_RSM, 'set').next()
198 name="set",
199 uri=NS_RSM).next()
200 except StopIteration: 196 except StopIteration:
201 return RSMNotFoundError() 197 return RSMNotFoundError()
202 198
203 response = RSMResponse() 199 response = RSMResponse()
204 for elt in list(set_elt.elements()): 200 for elt in list(set_elt.elements()):
329 request.rsm = ext_data['rsm'] 325 request.rsm = ext_data['rsm']
330 326
331 def cb(iq): 327 def cb(iq):
332 items = [] 328 items = []
333 if iq.pubsub.items: 329 if iq.pubsub.items:
334 for element in iq.pubsub.items.elements(): 330 for element in iq.pubsub.items.elements(pubsub.NS_PUBSUB, 'item'):
335 if element.uri == pubsub.NS_PUBSUB and element.name == 'item': 331 items.append(element)
336 items.append(element)
337 332
338 if request.rsm: 333 if request.rsm:
339 response = RSMResponse.parse(iq.pubsub) 334 response = RSMResponse.parse(iq.pubsub)
340 if response is not None: 335 if response is not None:
341 self._rsm_responses[ext_data['id']] = response 336 self._rsm_responses[ext_data['id']] = response
343 338
344 d = request.send(self.xmlstream) 339 d = request.send(self.xmlstream)
345 d.addCallback(cb) 340 d.addCallback(cb)
346 return d 341 return d
347 342
348 def getRSMResponse(self, id): 343 def getRSMResponse(self, id_):
349 """ 344 """Post-retrieve the RSM response data after items retrieval is done.
350 Post-retrieve the RSM response data after items retrieval is done. 345
351 346 @param id_: extension data ID
352 @param id: extension data ID 347 @type id_: C{unicode}
353 @type id: C{unicode}
354 348
355 @return: dict representation of the RSM response. 349 @return: dict representation of the RSM response.
356 @rtype: C{dict} of C{unicode} 350 @rtype: C{dict} of C{unicode}
357 """ 351 """
358 # This method exists to not modify the return value of self.items. 352 # This method exists to not modify the return value of self.items.
359 if id not in self._rsm_responses: 353 if id_ not in self._rsm_responses:
360 return {} 354 return {}
361 result = self._rsm_responses[id].toDict() 355 result = self._rsm_responses[id_].toDict()
362 del self._rsm_responses[id] 356 del self._rsm_responses[id_]
363 return result 357 return result
364 358
365 359
366 class PubSubService(pubsub.PubSubService): 360 class PubSubService(pubsub.PubSubService):
367 """PubSubService extension to handle RSM.""" 361 """PubSubService extension to handle RSM."""