diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-08-16 19:00:00 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2015-08-17 21:14:12 +0200 |
commit | c46caa19d9e1fb429fd77693abcca2fe668366aa (patch) | |
tree | bb5ed5f4c2987959b53c4390783ae67f1d3a16d6 /base/server/python/pki/server/deployment/pkihelper.py | |
parent | 1c7a2735c82d6af1a871efd2c01f942387821a1f (diff) | |
download | pki-c46caa19d9e1fb429fd77693abcca2fe668366aa.tar.gz pki-c46caa19d9e1fb429fd77693abcca2fe668366aa.tar.xz pki-c46caa19d9e1fb429fd77693abcca2fe668366aa.zip |
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.
Diffstat (limited to 'base/server/python/pki/server/deployment/pkihelper.py')
-rw-r--r-- | base/server/python/pki/server/deployment/pkihelper.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index 821739bc5..e6833d270 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -30,10 +30,13 @@ import fileinput import re import requests.exceptions import shutil -from shutil import Error, WindowsError +from shutil import Error +try: + from shutil import WindowsError # pylint: disable=E0611 +except ImportError: + WindowsError = None import subprocess import time -import types from datetime import datetime from grp import getgrgid from grp import getgrnam @@ -1722,7 +1725,7 @@ class File: self.slots[slot], self.mdict[slot], extra=config.PKI_INDENTATION_LEVEL_3) line = line.replace(self.slots[slot], self.mdict[slot]) - sys.stdout.write(line) + print(line, end='') if uid is None: uid = self.identity.get_uid() if gid is None: @@ -3805,7 +3808,7 @@ class ConfigClient: extra=config.PKI_INDENTATION_LEVEL_2) certs = [] - if not isinstance(certs, types.ListType): + if not isinstance(certs, list): certs = [certs] for cdata in certs: if (self.subsystem == "CA" and self.external and @@ -3897,11 +3900,12 @@ class ConfigClient: extra=config.PKI_INDENTATION_LEVEL_2) if hasattr(e, 'response'): + text = e.response.text # pylint: disable=E1101 try: - root = ET.fromstring(e.response.text) + root = ET.fromstring(text) except ET.ParseError as pe: config.pki_log.error( - "ParseError: %s: %s " % (pe, e.response.text), + "ParseError: %s: %s " % (pe, text), extra=config.PKI_INDENTATION_LEVEL_2) raise |