Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0334.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0334.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat/plugins/plugin_xep_0334.py Tue Aug 13 19:08:41 2019 +0200 @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # SAT plugin for Delayed Delivery (XEP-0334) @@ -29,21 +29,21 @@ from wokkel import disco, iwokkel from twisted.words.protocols.jabber import xmlstream -from zope.interface import implements +from zope.interface import implementer from textwrap import dedent PLUGIN_INFO = { - C.PI_NAME: u"Message Processing Hints", - C.PI_IMPORT_NAME: u"XEP-0334", - C.PI_TYPE: u"XEP", - C.PI_PROTOCOLS: [u"XEP-0334"], + C.PI_NAME: "Message Processing Hints", + C.PI_IMPORT_NAME: "XEP-0334", + C.PI_TYPE: "XEP", + C.PI_PROTOCOLS: ["XEP-0334"], C.PI_MAIN: "XEP_0334", - C.PI_HANDLER: u"yes", - C.PI_DESCRIPTION: D_(u"""Implementation of Message Processing Hints"""), + C.PI_HANDLER: "yes", + C.PI_DESCRIPTION: D_("""Implementation of Message Processing Hints"""), C.PI_USAGE: dedent( D_( - u"""\ + """\ Frontends can use HINT_* constants in mess_data['extra'] in a serialized 'hints' dict. Internal plugins can use directly addHint([HINT_* constant]). Will set mess_data['extra']['history'] to 'skipped' when no store is requested and message is not saved in history.""" @@ -51,14 +51,14 @@ ), } -NS_HINTS = u"urn:xmpp:hints" +NS_HINTS = "urn:xmpp:hints" class XEP_0334(object): - HINT_NO_PERMANENT_STORE = u"no-permanent-store" - HINT_NO_STORE = u"no-store" - HINT_NO_COPY = u"no-copy" - HINT_STORE = u"store" + HINT_NO_PERMANENT_STORE = "no-permanent-store" + HINT_NO_STORE = "no-store" + HINT_NO_COPY = "no-copy" + HINT_STORE = "store" HINTS = (HINT_NO_PERMANENT_STORE, HINT_NO_STORE, HINT_NO_COPY, HINT_STORE) def __init__(self, host): @@ -73,14 +73,14 @@ def addHint(self, mess_data, hint): if hint == self.HINT_NO_COPY and not mess_data["to"].resource: log.error( - u"{hint} can only be used with full jids! Ignoring it.".format(hint=hint) + "{hint} can only be used with full jids! Ignoring it.".format(hint=hint) ) return hints = mess_data.setdefault("hints", set()) if hint in self.HINTS: hints.add(hint) else: - log.error(u"Unknown hint: {}".format(hint)) + log.error("Unknown hint: {}".format(hint)) def addHintElements(self, message_elt, hints): """Add hints elements to message stanza @@ -93,22 +93,22 @@ def _sendPostXmlTreatment(self, mess_data): if "hints" in mess_data: - self.addHintElements(mess_data[u"xml"], mess_data[u"hints"]) + self.addHintElements(mess_data["xml"], mess_data["hints"]) return mess_data def sendMessageTrigger( self, client, mess_data, pre_xml_treatments, post_xml_treatments ): """Add the hints element to the message to be sent""" - if u"hints" in mess_data[u"extra"]: - for hint in data_format.dict2iter(u"hints", mess_data[u"extra"], pop=True): + if "hints" in mess_data["extra"]: + for hint in data_format.dict2iter("hints", mess_data["extra"], pop=True): self.addHint(hint) post_xml_treatments.addCallback(self._sendPostXmlTreatment) return True def _receivedSkipHistory(self, mess_data): - mess_data[u"history"] = C.HISTORY_SKIP + mess_data["history"] = C.HISTORY_SKIP return mess_data def messageReceivedTrigger(self, client, message_elt, post_treat): @@ -118,14 +118,14 @@ self.HINT_NO_PERMANENT_STORE, self.HINT_NO_STORE, ): - log.debug(u"history will be skipped for this message, as requested") + log.debug("history will be skipped for this message, as requested") post_treat.addCallback(self._receivedSkipHistory) break return True +@implementer(iwokkel.IDisco) class XEP_0334_handler(xmlstream.XMPPHandler): - implements(iwokkel.IDisco) def getDiscoInfo(self, requestor, target, nodeIdentifier=""): return [disco.DiscoFeature(NS_HINTS)]