Mercurial > libervia-backend
comparison src/memory/disco.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | 4a8903021fda |
children | 7d640c303140 |
comparison
equal
deleted
inserted
replaced
992:f51a1895275c | 993:301b342c697a |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core import exceptions | 21 from sat.core import exceptions |
22 from logging import debug, info, warning, error | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | |
23 from twisted.words.protocols.jabber import jid | 24 from twisted.words.protocols.jabber import jid |
24 from twisted.words.protocols.jabber.error import StanzaError | 25 from twisted.words.protocols.jabber.error import StanzaError |
25 from twisted.internet import defer | 26 from twisted.internet import defer |
26 from sat.core.constants import Const as C | 27 from sat.core.constants import Const as C |
27 from wokkel import disco | 28 from wokkel import disco |
124 if jid_ is None: | 125 if jid_ is None: |
125 jid_ = jid.JID(client.jid.host) | 126 jid_ = jid.JID(client.jid.host) |
126 # we cache items only for our own server | 127 # we cache items only for our own server |
127 try: | 128 try: |
128 items = self.host.memory.getEntityData(jid_, ["DISCO_ITEMS"], client.profile)["DISCO_ITEMS"] | 129 items = self.host.memory.getEntityData(jid_, ["DISCO_ITEMS"], client.profile)["DISCO_ITEMS"] |
129 debug("[%s] disco items are in cache" % jid_.full()) | 130 log.debug("[%s] disco items are in cache" % jid_.full()) |
130 except KeyError: | 131 except KeyError: |
131 debug("Caching [%s] disco items" % jid_.full()) | 132 log.debug("Caching [%s] disco items" % jid_.full()) |
132 items = yield client.disco.requestItems(jid_) | 133 items = yield client.disco.requestItems(jid_) |
133 self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile) | 134 self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile) |
134 else: | 135 else: |
135 items = yield client.disco.requestItems(jid_) | 136 items = yield client.disco.requestItems(jid_) |
136 | 137 |
137 defer.returnValue(items) | 138 defer.returnValue(items) |
138 | 139 |
139 | 140 |
140 def _infosEb(self, failure, entity_jid): | 141 def _infosEb(self, failure, entity_jid): |
141 failure.trap(StanzaError) | 142 failure.trap(StanzaError) |
142 warning(_("Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(), | 143 log.warning(_("Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(), |
143 'error': failure.getErrorMessage()}) | 144 'error': failure.getErrorMessage()}) |
144 | 145 |
145 def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE): | 146 def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE): |
146 """Return all available items of an entity which correspond to (category, type_) | 147 """Return all available items of an entity which correspond to (category, type_) |
147 | 148 |
234 for feature in byte_features: | 235 for feature in byte_features: |
235 s.append(feature) | 236 s.append(feature) |
236 s.append('<') | 237 s.append('<') |
237 #TODO: manage XEP-0128 data form here | 238 #TODO: manage XEP-0128 data form here |
238 cap_hash = b64encode(sha1(''.join(s)).digest()) | 239 cap_hash = b64encode(sha1(''.join(s)).digest()) |
239 debug(_('Capability hash generated: [%s]') % cap_hash) | 240 log.debug(_('Capability hash generated: [%s]') % cap_hash) |
240 return cap_hash | 241 return cap_hash |
241 | 242 |
242 @defer.inlineCallbacks | 243 @defer.inlineCallbacks |
243 def _discoInfos(self, entity_jid_s, profile_key=C.PROF_KEY_NONE): | 244 def _discoInfos(self, entity_jid_s, profile_key=C.PROF_KEY_NONE): |
244 """ Discovery method for the bridge | 245 """ Discovery method for the bridge |