comparison src/memory/disco.py @ 1189:7d640c303140

core (disco): added a timeout to get items
author Goffi <goffi@goffi.org>
date Mon, 08 Sep 2014 21:23:21 +0200
parents 301b342c697a
children 8ad37c3d58a9
comparison
equal deleted inserted replaced
1188:bf2927e6a0f5 1189:7d640c303140
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
25 from twisted.words.protocols.jabber.error import StanzaError 25 from twisted.words.protocols.jabber.error import StanzaError
26 from twisted.internet import defer 26 from twisted.internet import defer
27 from twisted.internet import reactor
27 from sat.core.constants import Const as C 28 from sat.core.constants import Const as C
28 from wokkel import disco 29 from wokkel import disco
29 from base64 import b64encode 30 from base64 import b64encode
30 from hashlib import sha1 31 from hashlib import sha1
31 32
32 33
33 PRESENCE = '/presence' 34 PRESENCE = '/presence'
34 NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps' 35 NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps'
35 CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]' 36 CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]'
37 TIMEOUT = 15
36 38
37 class HashGenerationError(Exception): 39 class HashGenerationError(Exception):
38 pass 40 pass
39 41
40 42
167 return defer.DeferredList(defers_list) 169 return defer.DeferredList(defers_list)
168 170
169 d = self.getItems(jid_, profile_key) 171 d = self.getItems(jid_, profile_key)
170 d.addCallback(gotItems) 172 d.addCallback(gotItems)
171 d.addCallback(lambda dummy: found_entities) 173 d.addCallback(lambda dummy: found_entities)
174 reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout
172 return d 175 return d
173 176
174 def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=C.PROF_KEY_NONE): 177 def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=C.PROF_KEY_NONE):
175 """Return entities (including jid_ and its items) offering features 178 """Return entities (including jid_ and its items) offering features
176 179
211 return defer.DeferredList(defer_list) 214 return defer.DeferredList(defer_list)
212 215
213 d = self.getItems(jid_, profile_key) 216 d = self.getItems(jid_, profile_key)
214 d.addCallback(gotItems) 217 d.addCallback(gotItems)
215 d.addCallback(lambda dummy: found_entities) 218 d.addCallback(lambda dummy: found_entities)
219 reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout
216 return d 220 return d
217 221
218 def generateHash(self, services): 222 def generateHash(self, services):
219 """ Generate a unique hash for given service 223 """ Generate a unique hash for given service
220 224