Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0115.py @ 941:c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 28 Mar 2014 18:07:02 +0100 |
parents | 1a759096ccbd |
children | e1842ebcb2f3 |
comparison
equal
deleted
inserted
replaced
940:92e41e7c7e00 | 941:c6d8fc63b1db |
---|---|
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from logging import debug, info, error, warning | 22 from logging import debug, info, error, warning |
23 from twisted.words.xish import domish | 23 from twisted.words.xish import domish |
24 from twisted.words.protocols.jabber import client, jid, xmlstream | 24 from twisted.words.protocols.jabber import jid |
25 from twisted.words.protocols.jabber import error as jab_error | |
26 from twisted.words.protocols.jabber.xmlstream import IQ | |
27 from sat.memory.persistent import PersistentBinaryDict | 25 from sat.memory.persistent import PersistentBinaryDict |
28 import os.path | |
29 import types | 26 import types |
30 | 27 |
31 from zope.interface import implements | 28 from zope.interface import implements |
32 | 29 |
33 from wokkel import disco, iwokkel | 30 from wokkel import disco, iwokkel |
124 if not profile: | 121 if not profile: |
125 error('Requesting hash for an inexistant profile') | 122 error('Requesting hash for an inexistant profile') |
126 raise HashGenerationError | 123 raise HashGenerationError |
127 | 124 |
128 client = self.host.getClient(profile_key) | 125 client = self.host.getClient(profile_key) |
129 if not client: | |
130 error('Requesting hash for an inexistant client') | |
131 raise HashGenerationError | |
132 | 126 |
133 def generateHash_2(services, profile): | 127 def generateHash_2(services, profile): |
134 _s = [] | 128 _s = [] |
135 byte_identities = [ByteIdentity(service) for service in services if isinstance(service, disco.DiscoIdentity)] # FIXME: lang must be managed here | 129 byte_identities = [ByteIdentity(service) for service in services if isinstance(service, disco.DiscoIdentity)] # FIXME: lang must be managed here |
136 byte_identities.sort(key=lambda i: i.lang) | 130 byte_identities.sort(key=lambda i: i.lang) |
147 #TODO: manage XEP-0128 data form here | 141 #TODO: manage XEP-0128 data form here |
148 XEP_0115.cap_hash = b64encode(sha1(''.join(_s)).digest()) | 142 XEP_0115.cap_hash = b64encode(sha1(''.join(_s)).digest()) |
149 debug(_('Capability hash generated: [%s]') % XEP_0115.cap_hash) | 143 debug(_('Capability hash generated: [%s]') % XEP_0115.cap_hash) |
150 self.presenceHack(profile) | 144 self.presenceHack(profile) |
151 | 145 |
152 services = client.discoHandler.info(client.jid, client.jid, '').addCallback(generateHash_2, profile) | 146 client.discoHandler.info(client.jid, client.jid, '').addCallback(generateHash_2, profile) |
153 | 147 |
154 | 148 |
155 class XEP_0115_handler(XMPPHandler): | 149 class XEP_0115_handler(XMPPHandler): |
156 implements(iwokkel.IDisco) | 150 implements(iwokkel.IDisco) |
157 | 151 |