Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0313.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 | 2ea2369ae7de |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 20 |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.i18n import _ | 22 from sat.core.i18n import _ |
23 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
24 | |
24 log = getLogger(__name__) | 25 log = getLogger(__name__) |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
26 | 27 |
27 from twisted.words.protocols.jabber import jid | 28 from twisted.words.protocols.jabber import jid |
28 | 29 |
43 C.PI_IMPORT_NAME: "XEP-0313", | 44 C.PI_IMPORT_NAME: "XEP-0313", |
44 C.PI_TYPE: "XEP", | 45 C.PI_TYPE: "XEP", |
45 C.PI_PROTOCOLS: ["XEP-0313"], | 46 C.PI_PROTOCOLS: ["XEP-0313"], |
46 C.PI_MAIN: "XEP_0313", | 47 C.PI_MAIN: "XEP_0313", |
47 C.PI_HANDLER: "yes", | 48 C.PI_HANDLER: "yes", |
48 C.PI_DESCRIPTION: _("""Implementation of Message Archive Management""") | 49 C.PI_DESCRIPTION: _("""Implementation of Message Archive Management"""), |
49 } | 50 } |
50 | 51 |
51 | 52 |
52 class XEP_0313(object): | 53 class XEP_0313(object): |
53 | |
54 def __init__(self, host): | 54 def __init__(self, host): |
55 log.info(_("Message Archive Management plugin initialization")) | 55 log.info(_("Message Archive Management plugin initialization")) |
56 self.host = host | 56 self.host = host |
57 | 57 |
58 def getHandler(self, client): | 58 def getHandler(self, client): |
84 elt_list.append(message_elt) | 84 elt_list.append(message_elt) |
85 | 85 |
86 def _queryFinished(self, iq_result, client, elt_list, event): | 86 def _queryFinished(self, iq_result, client, elt_list, event): |
87 client.xmlstream.removeObserver(event, self._appendMessage) | 87 client.xmlstream.removeObserver(event, self._appendMessage) |
88 try: | 88 try: |
89 fin_elt = iq_result.elements(mam.NS_MAM, 'fin').next() | 89 fin_elt = iq_result.elements(mam.NS_MAM, "fin").next() |
90 except StopIteration: | 90 except StopIteration: |
91 raise exceptions.DataError(u"Invalid MAM result") | 91 raise exceptions.DataError(u"Invalid MAM result") |
92 | 92 |
93 try: | 93 try: |
94 rsm_response = rsm.RSMResponse.fromElement(fin_elt) | 94 rsm_response = rsm.RSMResponse.fromElement(fin_elt) |
117 @return: the server response as a Deferred domish.Element | 117 @return: the server response as a Deferred domish.Element |
118 """ | 118 """ |
119 # http://xmpp.org/extensions/xep-0313.html#prefs | 119 # http://xmpp.org/extensions/xep-0313.html#prefs |
120 return client._mam.queryPrefs(service) | 120 return client._mam.queryPrefs(service) |
121 | 121 |
122 def _setPrefs(self, service_s=None, default='roster', always=None, never=None, profile_key=C.PROF_KEY_NONE): | 122 def _setPrefs( |
123 self, | |
124 service_s=None, | |
125 default="roster", | |
126 always=None, | |
127 never=None, | |
128 profile_key=C.PROF_KEY_NONE, | |
129 ): | |
123 service = jid.JID(service_s) if service_s else None | 130 service = jid.JID(service_s) if service_s else None |
124 always_jid = [jid.JID(entity) for entity in always] | 131 always_jid = [jid.JID(entity) for entity in always] |
125 never_jid = [jid.JID(entity) for entity in never] | 132 never_jid = [jid.JID(entity) for entity in never] |
126 #TODO: why not build here a MAMPrefs object instead of passing the args separately? | 133 # TODO: why not build here a MAMPrefs object instead of passing the args separately? |
127 return self.setPrefs(service, default, always_jid, never_jid, profile_key) | 134 return self.setPrefs(service, default, always_jid, never_jid, profile_key) |
128 | 135 |
129 def setPrefs(self, client, service=None, default='roster', always=None, never=None): | 136 def setPrefs(self, client, service=None, default="roster", always=None, never=None): |
130 """Set news user preferences. | 137 """Set news user preferences. |
131 | 138 |
132 @param service: entity offering the MAM service (None for user archives) | 139 @param service: entity offering the MAM service (None for user archives) |
133 @param default (unicode): a value in ('always', 'never', 'roster') | 140 @param default (unicode): a value in ('always', 'never', 'roster') |
134 @param always (list): a list of JID instances | 141 @param always (list): a list of JID instances |
141 | 148 |
142 | 149 |
143 class SatMAMClient(mam.MAMClient): | 150 class SatMAMClient(mam.MAMClient): |
144 implements(disco.IDisco) | 151 implements(disco.IDisco) |
145 | 152 |
146 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | 153 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
147 return [disco.DiscoFeature(mam.NS_MAM)] | 154 return [disco.DiscoFeature(mam.NS_MAM)] |
148 | 155 |
149 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | 156 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
150 return [] | 157 return [] |