plugin XEP-0060, tmp(wokkel.rsm): small refactoring:

- don't use getRSMResponse anymore: rsm.PubSubClient use a different signature which return items and RSMResponse, this is better than the previous method as if the requested don't call getRSMResponse, there is no memory leak anymore.
    - use RSMResponse directly instead of using ext_data, as other extension (like MAM) will be probably be managed with an other workflow
    - don't do a useless deep copy of pubsub.PubSubRequest._parameters on each instance anymore
    - RSMResponse.parse do now manage parsing of <set/> element directly
This commit is contained in:
Goffi 2016-01-05 23:20:22 +01:00
commit cdac9644db

View file

@ -34,7 +34,7 @@ from wokkel import pubsub
from wokkel import rsm
from zope.interface import implements
from collections import namedtuple
import uuid
UNSPECIFIED = "unspecified error"
@ -234,12 +234,11 @@ class XEP_0060(object):
- rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse
"""
if rsm_request and item_ids:
raise ValueError("items_id can't be used with rsm")
raise ValueError(u"items_id can't be used with rsm")
if extra is None:
extra = {}
client = self.host.getClient(profile_key)
ext_data = {'id': unicode(uuid.uuid4()), 'rsm': rsm_request} if rsm_request is not None else None
d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, client.pubsub_client.parent.jid, ext_data)
d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, client.pubsub_client.parent.jid, rsm_request)
try:
subscribe = C.bool(extra['subscribe'])
@ -248,7 +247,7 @@ class XEP_0060(object):
def subscribeEb(failure, service, node):
failure.trap(error.StanzaError)
log.warning("Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value)))
log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value)))
def doSubscribe(items):
self.subscribe(service, node, profile_key=profile_key).addErrback(subscribeEb, service, node)
@ -257,11 +256,12 @@ class XEP_0060(object):
if subscribe:
d.addCallback(doSubscribe)
def addMetadata(items):
metadata = {}
if rsm_request is not None:
rsm_data = client.pubsub_client.getRSMResponse(ext_data['id'])
metadata.update({'rsm_{}'.format(key): value for key, value in rsm_data.iteritems()})
def addMetadata(result):
items, rsm_response = result
if rsm_request is not None and rsm_response is not None:
metadata = {'rsm_{}'.format(key): value for key, value in rsm_response.toDict().iteritems()}
else:
metadata = {}
return (items, metadata)
d.addCallback(addMetadata)