From c46caa19d9e1fb429fd77693abcca2fe668366aa Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 16 Aug 2015 19:00:00 +0200 Subject: Py3 modernization: misc manual fixes Python 3's exception class has no message attribute. e.message can either be replaced with string representation of e or e.args[0]. Use print(line, end='') instead of sys.stdout.write(). With end='' no new line is appended. Use six.reraise() to reraise an exception. Remove sys.exc_clear() as it is no longer available in Python 3. Conditionally import shutil.WindowsError. Use six.move to import correct modules / function like quote, urlparse and configparser. Silence some pylint warnings. pylint doesn't understand six.moves magic and emits a import-error warning. Add additional tox envs to check for Python 3 compatibility. --- base/common/python/pki/__init__.py | 5 +++-- base/common/python/pki/key.py | 4 ++-- base/common/python/pki/upgrade.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'base/common/python') diff --git a/base/common/python/pki/__init__.py b/base/common/python/pki/__init__.py index 6bfb82719..652b6697d 100644 --- a/base/common/python/pki/__init__.py +++ b/base/common/python/pki/__init__.py @@ -30,7 +30,8 @@ import re import sys import requests -from six.moves import input # pylint: disable=W0622 +from six.moves import input # pylint: disable=W0622,F0401 +import six CONF_DIR = '/etc/pki' @@ -311,7 +312,7 @@ def handle_exceptions(): # json raises ValueError. simplejson raises # JSONDecodeError, which is a subclass of ValueError. # re-raise original exception - raise exc_type, exc_val, exc_tb + six.reraise(exc_type, exc_val, exc_tb) else: # clear reference cycle exc_type = exc_val = exc_tb = None diff --git a/base/common/python/pki/key.py b/base/common/python/pki/key.py index 7b9a463a0..83883dd31 100644 --- a/base/common/python/pki/key.py +++ b/base/common/python/pki/key.py @@ -28,9 +28,9 @@ from __future__ import absolute_import from __future__ import print_function import base64 import json -import urllib from six import iteritems +from six.moves.urllib.parse import quote # pylint: disable=F0401 import pki import pki.encoder as encoder @@ -509,7 +509,7 @@ class KeyClient(object): if client_key_id is None: raise TypeError("Client Key ID must be specified") - url = self.key_url + '/active/' + urllib.quote(client_key_id) + url = self.key_url + '/active/' + quote(client_key_id) response = self.connection.get(url, headers=self.headers) return KeyInfo.from_json(response.json()) diff --git a/base/common/python/pki/upgrade.py b/base/common/python/pki/upgrade.py index 2dfc0d2b9..44decd5bd 100644 --- a/base/common/python/pki/upgrade.py +++ b/base/common/python/pki/upgrade.py @@ -633,7 +633,7 @@ class PKIUpgrader(object): print() - message = 'Upgrade failed: ' + e.message + message = 'Upgrade failed: %s' % e if verbose: traceback.print_exc() -- cgit