Modernize code base to Python 3+ syntax

Replaces syntax that was relevant in earlier Python versions but that
now has modernized equivalents.
This commit is contained in:
Justin Mayer 2020-04-26 09:55:08 +02:00
commit d43b786b30
37 changed files with 104 additions and 171 deletions

View file

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
import locale
import logging
import os
@ -480,9 +478,9 @@ class TestUtils(LoggedTestCase):
old_locale = locale.setlocale(locale.LC_ALL)
if platform == 'win32':
locale.setlocale(locale.LC_ALL, str('Turkish'))
locale.setlocale(locale.LC_ALL, 'Turkish')
else:
locale.setlocale(locale.LC_ALL, str('tr_TR.UTF-8'))
locale.setlocale(locale.LC_ALL, 'tr_TR.UTF-8')
d = utils.SafeDatetime(2012, 8, 29)
@ -514,9 +512,9 @@ class TestUtils(LoggedTestCase):
old_locale = locale.setlocale(locale.LC_ALL)
if platform == 'win32':
locale.setlocale(locale.LC_ALL, str('French'))
locale.setlocale(locale.LC_ALL, 'French')
else:
locale.setlocale(locale.LC_ALL, str('fr_FR.UTF-8'))
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
d = utils.SafeDatetime(2012, 8, 29)
@ -557,7 +555,7 @@ class TestCopy(unittest.TestCase):
def setUp(self):
self.root_dir = mkdtemp(prefix='pelicantests.')
self.old_locale = locale.setlocale(locale.LC_ALL)
locale.setlocale(locale.LC_ALL, str('C'))
locale.setlocale(locale.LC_ALL, 'C')
def tearDown(self):
shutil.rmtree(self.root_dir)
@ -666,26 +664,26 @@ class TestDateFormatter(unittest.TestCase):
# This test tries to reproduce an issue that
# occurred with python3.3 under macos10 only
if platform == 'win32':
locale.setlocale(locale.LC_ALL, str('French'))
locale.setlocale(locale.LC_ALL, 'French')
else:
locale.setlocale(locale.LC_ALL, str('fr_FR.UTF-8'))
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
date = utils.SafeDatetime(2014, 8, 14)
# we compare the lower() dates since macos10 returns
# "Jeudi" for %A whereas linux reports "jeudi"
self.assertEqual(
u'jeudi, 14 août 2014',
'jeudi, 14 août 2014',
utils.strftime(date, date_format="%A, %d %B %Y").lower())
df = utils.DateFormatter()
self.assertEqual(
u'jeudi, 14 août 2014',
'jeudi, 14 août 2014',
df(date, date_format="%A, %d %B %Y").lower())
# Let us now set the global locale to C:
locale.setlocale(locale.LC_ALL, str('C'))
locale.setlocale(locale.LC_ALL, 'C')
# DateFormatter should still work as expected
# since it is the whole point of DateFormatter
# (This is where pre-2014/4/15 code fails on macos10)
df_date = df(date, date_format="%A, %d %B %Y").lower()
self.assertEqual(u'jeudi, 14 août 2014', df_date)
self.assertEqual('jeudi, 14 août 2014', df_date)
@unittest.skipUnless(locale_available('fr_FR.UTF-8') or
locale_available('French'),