Mercurial > libervia-backend
diff sat_frontends/jp/cmd_message.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 | 0ae25883e223 |
children | fee60f17ebac |
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_message.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat_frontends/jp/cmd_message.py Tue Aug 13 19:08:41 2019 +0200 @@ -37,15 +37,15 @@ def add_parser_options(self): self.parser.add_argument( - "-l", "--lang", type=str, default="", help=_(u"language of the message") + "-l", "--lang", type=str, default="", help=_("language of the message") ) self.parser.add_argument( "-s", "--separate", action="store_true", help=_( - u"separate xmpp messages: send one message per line instead of one " - u"message alone." + "separate xmpp messages: send one message per line instead of one " + "message alone." ), ) self.parser.add_argument( @@ -53,17 +53,16 @@ "--new-line", action="store_true", help=_( - u"add a new line at the beginning of the input (usefull for ascii art ;))" + "add a new line at the beginning of the input (usefull for ascii art ;))" ), ) self.parser.add_argument( "-S", "--subject", - type=base.unicode_decoder, - help=_(u"subject of the message"), + help=_("subject of the message"), ) self.parser.add_argument( - "-L", "--subject_lang", type=str, default="", help=_(u"language of subject") + "-L", "--subject_lang", type=str, default="", help=_("language of subject") ) self.parser.add_argument( "-t", @@ -73,16 +72,16 @@ help=_("type of the message"), ) self.parser.add_argument("-e", "--encrypt", metavar="ALGORITHM", - help=_(u"encrypt message using given algorithm")) + help=_("encrypt message using given algorithm")) self.parser.add_argument( "--encrypt-noreplace", action="store_true", - help=_(u"don't replace encryption algorithm if an other one is already used")) + help=_("don't replace encryption algorithm if an other one is already used")) syntax = self.parser.add_mutually_exclusive_group() - syntax.add_argument("-x", "--xhtml", action="store_true", help=_(u"XHTML body")) - syntax.add_argument("-r", "--rich", action="store_true", help=_(u"rich body")) + syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body")) + syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body")) self.parser.add_argument( - "jid", type=base.unicode_decoder, help=_(u"the destination jid") + "jid", help=_("the destination jid") ) def multi_send_cb(self): @@ -91,7 +90,7 @@ self.host.quit(self.errcode) def multi_send_eb(self, failure_, msg): - self.disp(_(u"Can't send message [{msg}]: {reason}").format( + self.disp(_("Can't send message [{msg}]: {reason}").format( msg=msg, reason=failure_)) self.errcode = C.EXIT_BRIDGE_ERRBACK self.multi_send_cb() @@ -112,10 +111,10 @@ subject = {self.args.subject_lang: self.args.subject} if self.args.xhtml or self.args.rich: - key = u"xhtml" if self.args.xhtml else u"rich" + key = "xhtml" if self.args.xhtml else "rich" if self.args.lang: - key = u"{}_{}".format(key, self.args.lang) - extra[key] = clean_ustr(u"".join(stdin_lines)) + key = "{}_{}".format(key, self.args.lang) + extra[key] = clean_ustr("".join(stdin_lines)) stdin_lines = [] if self.args.separate: # we send stdin in several messages @@ -150,7 +149,7 @@ else: msg = ( - {self.args.lang: header + clean_ustr(u"".join(stdin_lines))} + {self.args.lang: header + clean_ustr("".join(stdin_lines))} if not (self.args.xhtml or self.args.rich) else {} ) @@ -163,7 +162,7 @@ profile_key=self.host.profile, callback=self.host.quit, errback=partial(self.errback, - msg=_(u"Can't send message: {}"))) + msg=_("Can't send message: {}"))) def encryptionNamespaceGetCb(self, namespace, jid_): self.host.bridge.messageEncryptionStart( @@ -171,7 +170,7 @@ self.profile, callback=lambda: self.sendStdin(jid_), errback=partial(self.errback, - msg=_(u"Can't start encryption session: {}"), + msg=_("Can't start encryption session: {}"), exit_code=C.EXIT_BRIDGE_ERRBACK, )) @@ -179,7 +178,7 @@ def start(self): if self.args.xhtml and self.args.separate: self.disp( - u"argument -s/--separate is not compatible yet with argument -x/--xhtml", + "argument -s/--separate is not compatible yet with argument -x/--xhtml", error=True, ) self.host.quit(2) @@ -194,7 +193,7 @@ self.host.bridge.encryptionNamespaceGet(self.args.encrypt, callback=partial(self.encryptionNamespaceGetCb, jid_=jid_), errback=partial(self.errback, - msg=_(u"Can't get encryption namespace: {}"), + msg=_("Can't get encryption namespace: {}"), exit_code=C.EXIT_BRIDGE_ERRBACK, )) else: @@ -205,49 +204,49 @@ def __init__(self, host): super(MAM, self).__init__( - host, "mam", use_output=C.OUTPUT_MESS, use_verbose=True, help=_(u"query archives using MAM")) + host, "mam", use_output=C.OUTPUT_MESS, use_verbose=True, help=_("query archives using MAM")) self.need_loop=True def add_parser_options(self): self.parser.add_argument( - "-s", "--service", type=base.unicode_decoder, default=u"", - help=_(u"jid of the service (default: profile's server")) + "-s", "--service", default="", + help=_("jid of the service (default: profile's server")) self.parser.add_argument( "-S", "--start", dest="mam_start", type=base.date_decoder, help=_( - u"start fetching archive from this date (default: from the beginning)")) + "start fetching archive from this date (default: from the beginning)")) self.parser.add_argument( "-E", "--end", dest="mam_end", type=base.date_decoder, - help=_(u"end fetching archive after this date (default: no limit)")) + help=_("end fetching archive after this date (default: no limit)")) self.parser.add_argument( - "-W", "--with", dest="mam_with", type=base.unicode_decoder, - help=_(u"retrieve only archives with this jid")) + "-W", "--with", dest="mam_with", + help=_("retrieve only archives with this jid")) self.parser.add_argument( "-m", "--max", dest="rsm_max", type=int, default=20, - help=_(u"maximum number of items to retrieve, using RSM (default: 20))")) + help=_("maximum number of items to retrieve, using RSM (default: 20))")) rsm_page_group = self.parser.add_mutually_exclusive_group() rsm_page_group.add_argument( - "-a", "--after", dest="rsm_after", type=base.unicode_decoder, - help=_(u"find page after this item"), metavar='ITEM_ID') + "-a", "--after", dest="rsm_after", + help=_("find page after this item"), metavar='ITEM_ID') rsm_page_group.add_argument( - "-b", "--before", dest="rsm_before", type=base.unicode_decoder, - help=_(u"find page before this item"), metavar='ITEM_ID') + "-b", "--before", dest="rsm_before", + help=_("find page before this item"), metavar='ITEM_ID') rsm_page_group.add_argument( "--index", dest="rsm_index", type=int, - help=_(u"index of the page to retrieve")) + help=_("index of the page to retrieve")) def _sessionInfosGetCb(self, session_info, data, metadata): - self.host.own_jid = jid.JID(session_info[u"jid"]) + self.host.own_jid = jid.JID(session_info["jid"]) self.output(data) # FIXME: metadata are not displayed correctly and don't play nice with output # they should be added to output data somehow if self.verbosity: - for value in (u"rsm_first", u"rsm_last", u"rsm_index", u"rsm_count", - u"mam_complete", u"mam_stable"): + for value in ("rsm_first", "rsm_last", "rsm_index", "rsm_count", + "mam_complete", "mam_stable"): if value in metadata: - label = value.split(u"_")[1] + label = value.split("_")[1] self.disp(A.color( - C.A_HEADER, label, u': ' , A.RESET, metadata[value])) + C.A_HEADER, label, ': ' , A.RESET, metadata[value])) self.host.quit() @@ -260,16 +259,16 @@ def start(self): extra = {} if self.args.mam_start is not None: - extra[u"mam_start"] = float(self.args.mam_start) + extra["mam_start"] = float(self.args.mam_start) if self.args.mam_end is not None: - extra[u"mam_end"] = float(self.args.mam_end) + extra["mam_end"] = float(self.args.mam_end) if self.args.mam_with is not None: - extra[u"mam_with"] = self.args.mam_with + extra["mam_with"] = self.args.mam_with for suff in ('max', 'after', 'before', 'index'): - key = u'rsm_' + suff + key = 'rsm_' + suff value = getattr(self.args,key) if value is not None: - extra[key] = unicode(value) + extra[key] = str(value) self.host.bridge.MAMGet( self.args.service, data_format.serialise(extra), self.profile, callback=self._MAMGetCb, errback=self.errback)