diff sat/bridge/bridge_constructor/base_constructor.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 a1bc34f90fa5
line wrap: on
line diff
--- a/sat/bridge/bridge_constructor/base_constructor.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/bridge/bridge_constructor/base_constructor.py	Tue Aug 13 19:08:41 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # SàT: a XMPP client
@@ -20,7 +20,7 @@
 """base constructor class"""
 
 from sat.bridge.bridge_constructor.constants import Const as C
-from ConfigParser import NoOptionError
+from configparser import NoOptionError
 import sys
 import os
 import os.path
@@ -191,7 +191,7 @@
         for arg in self.argumentsParser(signature):
             attr_string.append(
                 (
-                    "unicode(%(name)s)%(default)s"
+                    "str(%(name)s)%(default)s"
                     if (unicode_protect and arg == "s")
                     else "%(name)s%(default)s"
                 )
@@ -240,7 +240,7 @@
                 method = self.generateCoreSide
             elif side == "frontend":
                 if not self.FRONTEND_ACTIVATE:
-                    print(u"This constructor only handle core, please use core side")
+                    print("This constructor only handle core, please use core side")
                     sys.exit(1)
                 method = self.generateFrontendSide
         except AttributeError:
@@ -271,7 +271,7 @@
         sections.sort()
         for section in sections:
             function = self.getValues(section)
-            print("Adding %s %s" % (section, function["type"]))
+            print(("Adding %s %s" % (section, function["type"])))
             default = self.getDefault(section)
             arg_doc = self.getArgumentsDoc(section)
             async_ = "async" in self.getFlags(section)
@@ -291,7 +291,7 @@
             )
             extend_method(completion, function, default, arg_doc, async_)
 
-            for part, fmt in FORMATS.iteritems():
+            for part, fmt in FORMATS.items():
                 if part.startswith(function["type"]):
                     parts[part.upper()].append(fmt.format(**completion))
 
@@ -300,7 +300,7 @@
         bridge = []
         const_override = {
             env[len(C.ENV_OVERRIDE) :]: v
-            for env, v in os.environ.iteritems()
+            for env, v in os.environ.items()
             if env.startswith(C.ENV_OVERRIDE)
         }
         template_path = self.getTemplatePath(TEMPLATE)
@@ -308,7 +308,7 @@
             with open(template_path) as template:
                 for line in template:
 
-                    for part, extend_list in parts.iteritems():
+                    for part, extend_list in parts.items():
                         if line.startswith("##{}_PART##".format(part)):
                             bridge.extend(extend_list)
                             break
@@ -317,7 +317,7 @@
                         if line.startswith("const_"):
                             const_name = line[len("const_") : line.find(" = ")].strip()
                             if const_name in const_override:
-                                print("const {} overriden".format(const_name))
+                                print(("const {} overriden".format(const_name)))
                                 bridge.append(
                                     "const_{} = {}".format(
                                         const_name, const_override[const_name]
@@ -326,7 +326,7 @@
                                 continue
                         bridge.append(line.replace("\n", ""))
         except IOError:
-            print("can't open template file [{}]".format(template_path))
+            print(("can't open template file [{}]".format(template_path)))
             sys.exit(1)
 
         # now we write to final file
@@ -348,15 +348,15 @@
                 os.mkdir(self.args.dest_dir)
             full_path = os.path.join(self.args.dest_dir, filename)
             if os.path.exists(full_path) and not self.args.force:
-                print(
+                print((
                     "The destination file [%s] already exists ! Use --force to overwrite it"
                     % full_path
-                )
+                ))
             try:
                 with open(full_path, "w") as dest_file:
                     dest_file.write("\n".join(file_buf))
             except IOError:
-                print("Can't open destination file [%s]" % full_path)
+                print(("Can't open destination file [%s]" % full_path))
         except OSError:
             print("It's not possible to generate the file, check your permissions")
             exit(1)