comparison sat/plugins/plugin_xep_0060.py @ 2769:9282b289b964

plugin XEP-0060: set a 30s timeout on items get
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 19:49:01 +0100
parents 3480d4fdf83a
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2768:cb34af35af6f 2769:9282b289b964
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat.core import exceptions 25 from sat.core import exceptions
26 from sat.tools import sat_defer 26 from sat.tools import sat_defer
27 27
28 from twisted.words.protocols.jabber import jid, error 28 from twisted.words.protocols.jabber import jid, error
29 from twisted.internet import defer 29 from twisted.internet import reactor, defer
30 from wokkel import disco 30 from wokkel import disco
31 from wokkel import data_form 31 from wokkel import data_form
32 from zope.interface import implements 32 from zope.interface import implements
33 from collections import namedtuple 33 from collections import namedtuple
34 import urllib 34 import urllib
56 56
57 57
58 Extra = namedtuple("Extra", ("rsm_request", "extra")) 58 Extra = namedtuple("Extra", ("rsm_request", "extra"))
59 # rsm_request is the rsm.RSMRequest build with rsm_ prefixed keys, or None 59 # rsm_request is the rsm.RSMRequest build with rsm_ prefixed keys, or None
60 # extra is a potentially empty dict 60 # extra is a potentially empty dict
61 61 TIMEOUT = 30
62 62
63 class XEP_0060(object): 63 class XEP_0060(object):
64 OPT_ACCESS_MODEL = "pubsub#access_model" 64 OPT_ACCESS_MODEL = "pubsub#access_model"
65 OPT_PERSIST_ITEMS = "pubsub#persist_items" 65 OPT_PERSIST_ITEMS = "pubsub#persist_items"
66 OPT_MAX_ITEMS = "pubsub#max_items" 66 OPT_MAX_ITEMS = "pubsub#max_items"
554 orderBy = extra.get(C.KEY_ORDER_BY), 554 orderBy = extra.get(C.KEY_ORDER_BY),
555 rsm_request = rsm_request 555 rsm_request = rsm_request
556 ) 556 )
557 # we have no MAM data here, so we add None 557 # we have no MAM data here, so we add None
558 d.addCallback(lambda data: data + (None,)) 558 d.addCallback(lambda data: data + (None,))
559 d.addTimeout(TIMEOUT, reactor)
559 else: 560 else:
560 # if mam is requested, we have to do a totally different query 561 # if mam is requested, we have to do a totally different query
561 if self._mam is None: 562 if self._mam is None:
562 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available") 563 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available")
563 if max_items is not None: 564 if max_items is not None: