comparison sat/plugins/plugin_xep_0049.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
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.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23
23 log = getLogger(__name__) 24 log = getLogger(__name__)
24 from wokkel import compat 25 from wokkel import compat
25 from twisted.words.xish import domish 26 from twisted.words.xish import domish
26
27 27
28 28
29 PLUGIN_INFO = { 29 PLUGIN_INFO = {
30 C.PI_NAME: "XEP-0049 Plugin", 30 C.PI_NAME: "XEP-0049 Plugin",
31 C.PI_IMPORT_NAME: "XEP-0049", 31 C.PI_IMPORT_NAME: "XEP-0049",
32 C.PI_TYPE: "XEP", 32 C.PI_TYPE: "XEP",
33 C.PI_PROTOCOLS: ["XEP-0049"], 33 C.PI_PROTOCOLS: ["XEP-0049"],
34 C.PI_DEPENDENCIES: [], 34 C.PI_DEPENDENCIES: [],
35 C.PI_MAIN: "XEP_0049", 35 C.PI_MAIN: "XEP_0049",
36 C.PI_HANDLER: "no", 36 C.PI_HANDLER: "no",
37 C.PI_DESCRIPTION: _("""Implementation of private XML storage""") 37 C.PI_DESCRIPTION: _("""Implementation of private XML storage"""),
38 } 38 }
39 39
40 40
41 class XEP_0049(object): 41 class XEP_0049(object):
42 NS_PRIVATE = 'jabber:iq:private' 42 NS_PRIVATE = "jabber:iq:private"
43 43
44 def __init__(self, host): 44 def __init__(self, host):
45 log.info(_("Plugin XEP-0049 initialization")) 45 log.info(_("Plugin XEP-0049 initialization"))
46 self.host = host 46 self.host = host
47 47
53 """ 53 """
54 assert isinstance(element, domish.Element) 54 assert isinstance(element, domish.Element)
55 client = self.host.getClient(profile_key) 55 client = self.host.getClient(profile_key)
56 # XXX: feature announcement in disco#info is not mandatory in XEP-0049, so we have to try to use private XML, and react according to the answer 56 # XXX: feature announcement in disco#info is not mandatory in XEP-0049, so we have to try to use private XML, and react according to the answer
57 iq_elt = compat.IQ(client.xmlstream) 57 iq_elt = compat.IQ(client.xmlstream)
58 query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE) 58 query_elt = iq_elt.addElement("query", XEP_0049.NS_PRIVATE)
59 query_elt.addChild(element) 59 query_elt.addChild(element)
60 return iq_elt.send() 60 return iq_elt.send()
61 61
62 def privateXMLGet(self, node_name, namespace, profile_key): 62 def privateXMLGet(self, node_name, namespace, profile_key):
63 """Store private data 63 """Store private data
67 @return (domish.Element): a deferred which fire the stored data 67 @return (domish.Element): a deferred which fire the stored data
68 68
69 """ 69 """
70 client = self.host.getClient(profile_key) 70 client = self.host.getClient(profile_key)
71 # XXX: see privateXMLStore note about feature checking 71 # XXX: see privateXMLStore note about feature checking
72 iq_elt = compat.IQ(client.xmlstream, 'get') 72 iq_elt = compat.IQ(client.xmlstream, "get")
73 query_elt = iq_elt.addElement('query', XEP_0049.NS_PRIVATE) 73 query_elt = iq_elt.addElement("query", XEP_0049.NS_PRIVATE)
74 query_elt.addElement(node_name, namespace) 74 query_elt.addElement(node_name, namespace)
75
75 def getCb(answer_iq_elt): 76 def getCb(answer_iq_elt):
76 answer_query_elt = answer_iq_elt.elements(XEP_0049.NS_PRIVATE, 'query').next() 77 answer_query_elt = answer_iq_elt.elements(XEP_0049.NS_PRIVATE, "query").next()
77 return answer_query_elt.firstChildElement() 78 return answer_query_elt.firstChildElement()
79
78 d = iq_elt.send() 80 d = iq_elt.send()
79 d.addCallback(getCb) 81 d.addCallback(getCb)
80 return d 82 return d
81