[Getan-commits] [PATCH] Porting Python 2 to Python 3

Wald Commits scm-commit at wald.intevation.org
Thu May 3 15:40:58 CEST 2018


# HG changeset patch
# User Magnus Schieder <mschieder at intevation.de>
# Date 1525354722 -7200
# Node ID 59d9c58402732a899374982afcadea0f38ecfd46
# Parent  9dab95965ac690bca52befdb4bbeedbcb06ae51b
Porting Python 2 to Python 3.

diff -r 9dab95965ac6 -r 59d9c5840273 CHANGES
--- a/CHANGES	Wed May 02 13:46:50 2018 +0200
+++ b/CHANGES	Thu May 03 15:38:42 2018 +0200
@@ -1,5 +1,11 @@
 2.x 20xx-xx-xx UNRELEASED
 
+ * Updated the source code to the latest version of pyhton (python 3) to better
+   maintain it in the future.
+   Python 2.7 will not be maintained past 2020.
+   Therefore, the whole source code of'done' and'done/scripts' is updated to
+   python 3.
+
  * Update and clean up the source code to better maintain it in the future.
    optparse to argparse Migration.
    The optparse module is deprecated and will not be developed further.The
diff -r 9dab95965ac6 -r 59d9c5840273 getan/backend.py
--- a/getan/backend.py	Wed May 02 13:46:50 2018 +0200
+++ b/getan/backend.py	Thu May 03 15:38:42 2018 +0200
@@ -175,7 +175,7 @@
         self.con = db.connect(database,
                               detect_types=db.PARSE_DECLTYPES |
                               db.PARSE_COLNAMES)
-        self.con.text_factory = lambda x: unicode(x, "utf-8", "ignore")
+        self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
 
     def ensure_exists(self):
         """ Creates the database file if it does not exist. """
diff -r 9dab95965ac6 -r 59d9c5840273 getan/config.py
--- a/getan/config.py	Wed May 02 13:46:50 2018 +0200
+++ b/getan/config.py	Thu May 03 15:38:42 2018 +0200
@@ -13,7 +13,7 @@
 import logging
 import os
 
-from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError
+from configparser import SafeConfigParser, NoSectionError, NoOptionError
 
 logger = None
 
@@ -242,7 +242,7 @@
 
     def get_palette(self):
         palette = []
-        for key in self.DEFAULT_THEME.keys():
+        for key in list(self.DEFAULT_THEME.keys()):
             colors = self.get_colors(key)
             line = [key]
             line.extend(colors)
diff -r 9dab95965ac6 -r 59d9c5840273 getan/project.py
--- a/getan/project.py	Wed May 02 13:46:50 2018 +0200
+++ b/getan/project.py	Thu May 03 15:38:42 2018 +0200
@@ -104,8 +104,8 @@
 
         # carefully handle non unicode string
         # urwid seems to have some issue with plain str
-        if self.desc and not isinstance(self.desc, unicode):
-            self.desc = unicode(self.desc, locale.getpreferredencoding())
+        if self.desc and not isinstance(self.desc, str):
+            self.desc = str(self.desc, locale.getpreferredencoding())
 
         c = self.desc
         if c:
diff -r 9dab95965ac6 -r 59d9c5840273 getan/resources.py
--- a/getan/resources.py	Wed May 02 13:46:50 2018 +0200
+++ b/getan/resources.py	Thu May 03 15:38:42 2018 +0200
@@ -9,4 +9,4 @@
     modir = os.path.join(share_dir, "locale")
     t = py_gettext.translation("getan", modir, fallback=True)
 
-    return t.ugettext(message)
+    return t.gettext(message)
diff -r 9dab95965ac6 -r 59d9c5840273 getan/template.py
--- a/getan/template.py	Wed May 02 13:46:50 2018 +0200
+++ b/getan/template.py	Thu May 03 15:38:42 2018 +0200
@@ -73,7 +73,7 @@
             database = os.path.expanduser(os.path.join("~", ".getan",
                                                        DEFAULT_DATABASE))
     if not os.path.isfile(database):
-        print >> sys.stderr, "'%s' does not exist or is not a file." % database
+        print("'%s' does not exist or is not a file." % database, file=sys.stderr)
         sys.exit(1)
 
     u_week = None
@@ -85,7 +85,7 @@
         year = c_year
 
     if not os.path.isfile(database):
-        print >> sys.stderr, "'%s' does not exist or is not a file." % database
+        print("'%s' does not exist or is not a file." % database, file=sys.stderr)
         sys.exit(1)
 
     loader = ChoiceLoader([FileSystemLoader(os.path.expanduser(os.path.join(
diff -r 9dab95965ac6 -r 59d9c5840273 scripts/getan-eval.py
--- a/scripts/getan-eval.py	Wed May 02 13:46:50 2018 +0200
+++ b/scripts/getan-eval.py	Thu May 03 15:38:42 2018 +0200
@@ -53,16 +53,15 @@
     if not args.encoding:
         encoding = locale.getdefaultlocale()[1] or "utf-8"
 
-    Writer = codecs.getwriter(encoding)
-    sys.stdout = Writer(sys.stdout)
+    sys.stdout = codecs.getwriter(encoding)(sys.stdout.detach())
 
     user = None
     if args.user:
         user = args.user.decode(encoding)
 
-    print render(database=args.database, user=user,
+    print(render(database=args.database, user=user,
                  template=template_name, year=year, week=week,
-                 project=args.project, empty_projects=args.empty)
+                 project=args.project, empty_projects=args.empty))
 
 
 if __name__ == '__main__':
diff -r 9dab95965ac6 -r 59d9c5840273 setup.py
--- a/setup.py	Wed May 02 13:46:50 2018 +0200
+++ b/setup.py	Thu May 03 15:38:42 2018 +0200
@@ -64,6 +64,6 @@
           "License :: OSI Approved :: "
               "GNU General Public License v3 or later (GPLv3+)",
           "Operating System :: POSIX",
-          "Programming Language :: Python :: 2"
+          "Programming Language :: Python :: 3"
       ],
       )


More information about the Getan-commits mailing list