diff sat/memory/params.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 fee60f17ebac
line wrap: on
line diff
--- a/sat/memory/params.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/memory/params.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: a jabber client
@@ -56,7 +56,7 @@
 
     # TODO: when priority is changed, a new presence stanza must be emitted
     # TODO: int type (Priority should be int instead of string)
-    default_xml = u"""
+    default_xml = """
     <params>
     <general>
     </general>
@@ -80,20 +80,20 @@
     </individual>
     </params>
     """ % {
-        u"category_general": D_(u"General"),
-        u"category_connection": D_(u"Connection"),
-        u"history_param": C.HISTORY_LIMIT,
-        u"history_label": D_(u"Chat history limit"),
-        u"show_offline_contacts": C.SHOW_OFFLINE_CONTACTS,
-        u"show_offline_contacts_label": D_(u"Show offline contacts"),
-        u"show_empty_groups": C.SHOW_EMPTY_GROUPS,
-        u"show_empty_groups_label": D_(u"Show empty groups"),
-        u"force_server_param": C.FORCE_SERVER_PARAM,
-        u"force_port_param": C.FORCE_PORT_PARAM,
-        u"new_account_label": D_(u"Register new account"),
-        u"autoconnect_label": D_(u"Connect on frontend startup"),
-        u"autodisconnect_label": D_(u"Disconnect on frontend closure"),
-        u"check_certificate_label": D_(u"Check certificate (don't uncheck if unsure)"),
+        "category_general": D_("General"),
+        "category_connection": D_("Connection"),
+        "history_param": C.HISTORY_LIMIT,
+        "history_label": D_("Chat history limit"),
+        "show_offline_contacts": C.SHOW_OFFLINE_CONTACTS,
+        "show_offline_contacts_label": D_("Show offline contacts"),
+        "show_empty_groups": C.SHOW_EMPTY_GROUPS,
+        "show_empty_groups_label": D_("Show empty groups"),
+        "force_server_param": C.FORCE_SERVER_PARAM,
+        "force_port_param": C.FORCE_PORT_PARAM,
+        "new_account_label": D_("Register new account"),
+        "autoconnect_label": D_("Connect on frontend startup"),
+        "autodisconnect_label": D_("Disconnect on frontend closure"),
+        "check_certificate_label": D_("Check certificate (don't uncheck if unsure)"),
     }
 
     def load_default_params(self):
@@ -158,7 +158,7 @@
             del self.params[profile]
         except KeyError:
             log.error(
-                _(u"Trying to purge cache of a profile not in memory: [%s]") % profile
+                _("Trying to purge cache of a profile not in memory: [%s]") % profile
             )
 
     def save_xml(self, filename):
@@ -238,7 +238,7 @@
         elif return_profile_keys and profile_key in [C.PROF_KEY_ALL]:
             return profile_key  # this value must be managed by the caller
         if not self.storage.hasProfile(profile_key):
-            log.error(_(u"Trying to access an unknown profile (%s)") % profile_key)
+            log.error(_("Trying to access an unknown profile (%s)") % profile_key)
             raise exceptions.ProfileUnknownError(profile_key)
         return profile_key
 
@@ -294,7 +294,7 @@
                     if (
                         len(cat_node.childNodes) == to_remove_count
                     ):  # remove empty category
-                        for __ in xrange(0, to_remove_count):
+                        for __ in range(0, to_remove_count):
                             to_remove.pop()
                         to_remove.append(cat_node)
             for node in to_remove:
@@ -333,7 +333,7 @@
         if not app:
             log.warning(
                 _(
-                    u"Trying to register frontends parameters with no specified app: aborted"
+                    "Trying to register frontends parameters with no specified app: aborted"
                 )
             )
             return
@@ -342,14 +342,14 @@
         if app in self.frontends_cache:
             log.debug(
                 _(
-                    u"Trying to register twice frontends parameters for %(app)s: aborted"
+                    "Trying to register twice frontends parameters for %(app)s: aborted"
                     % {"app": app}
                 )
             )
             return
         self.frontends_cache.append(app)
         self.updateParams(xml, security_limit, app)
-        log.debug(u"Frontends parameters registered for %(app)s" % {"app": app})
+        log.debug("Frontends parameters registered for %(app)s" % {"app": app})
 
     def __default_ok(self, value, name, category):
         # FIXME: will not work with individual parameters
@@ -357,7 +357,7 @@
 
     def __default_ko(self, failure, name, category):
         log.error(
-            _(u"Can't determine default value for [%(category)s/%(name)s]: %(reason)s")
+            _("Can't determine default value for [%(category)s/%(name)s]: %(reason)s")
             % {"category": category, "name": name, "reason": str(failure.value)}
         )
 
@@ -380,7 +380,7 @@
         if not node:
             log.error(
                 _(
-                    u"Requested param [%(name)s] in category [%(category)s] doesn't exist !"
+                    "Requested param [%(name)s] in category [%(category)s] doesn't exist !"
                 )
                 % {"name": name, "category": category}
             )
@@ -443,14 +443,14 @@
                     if len(selected) == 0:
                         log.error(
                             _(
-                                u"Parameter (%(cat)s, %(param)s) of type list has no default option!"
+                                "Parameter (%(cat)s, %(param)s) of type list has no default option!"
                             )
                             % {"cat": cat, "param": param}
                         )
                     else:
                         log.error(
                             _(
-                                u"Parameter (%(cat)s, %(param)s) of type list has more than one default option!"
+                                "Parameter (%(cat)s, %(param)s) of type list has more than one default option!"
                             )
                             % {"cat": cat, "param": param}
                         )
@@ -468,7 +468,7 @@
                         jids[idx] = jid.JID(value)
                     except (RuntimeError, jid.InvalidFormat, AttributeError):
                         log.warning(
-                            u"Incorrect jid value found in jids list: [{}]".format(value)
+                            "Incorrect jid value found in jids list: [{}]".format(value)
                         )
                         to_delete.append(value)
                 for value in to_delete:
@@ -564,7 +564,7 @@
         if not node:
             log.error(
                 _(
-                    u"Requested param [%(name)s] in category [%(category)s] doesn't exist !"
+                    "Requested param [%(name)s] in category [%(category)s] doesn't exist !"
                 )
                 % {"name": name, "category": category}
             )
@@ -630,7 +630,7 @@
         if not node:
             log.error(
                 _(
-                    u"Requested param [%(name)s] in category [%(category)s] doesn't exist !"
+                    "Requested param [%(name)s] in category [%(category)s] doesn't exist !"
                 )
                 % {"name": name, "category": category}
             )
@@ -639,7 +639,7 @@
         if not self.checkSecurityLimit(node[1], security_limit):
             log.warning(
                 _(
-                    u"Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
+                    "Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
                     % {"param": name, "cat": category}
                 )
             )
@@ -697,7 +697,7 @@
                         name = param_node.getAttribute("name")
                         if not name:
                             log.warning(
-                                u"ignoring attribute without name: {}".format(
+                                "ignoring attribute without name: {}".format(
                                     param_node.toxml()
                                 )
                             )
@@ -850,7 +850,7 @@
                                         AttributeError,
                                     ):
                                         log.warning(
-                                            u"Incorrect jid value found in jids list: [{}]".format(
+                                            "Incorrect jid value found in jids list: [{}]".format(
                                                 jid_
                                             )
                                         )
@@ -982,13 +982,13 @@
         if profile_key != C.PROF_KEY_NONE:
             profile = self.getProfileName(profile_key)
             if not profile:
-                log.error(_(u"Trying to set parameter for an unknown profile"))
+                log.error(_("Trying to set parameter for an unknown profile"))
                 raise exceptions.ProfileUnknownError(profile_key)
 
         node = self._getParamNode(name, category, "@ALL@")
         if not node:
             log.error(
-                _(u"Requesting an unknown parameter (%(category)s/%(name)s)")
+                _("Requesting an unknown parameter (%(category)s/%(name)s)")
                 % {"category": category, "name": name}
             )
             return defer.succeed(None)
@@ -996,7 +996,7 @@
         if not self.checkSecurityLimit(node[1], security_limit):
             log.warning(
                 _(
-                    u"Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
+                    "Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
                     % {"param": name, "cat": category}
                 )
             )
@@ -1012,7 +1012,7 @@
                 except ValueError:
                     log.debug(
                         _(
-                            u"Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value"
+                            "Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value"
                             % {"param": name, "cat": category}
                         )
                     )
@@ -1051,7 +1051,7 @@
         assert profile_key != C.PROF_KEY_NONE
 
         if type_ == "button":
-            log.debug(u"Clicked param button %s" % node.toxml())
+            log.debug("Clicked param button %s" % node.toxml())
             return defer.succeed(None)
         elif type_ == "password":
             try: