From 7fef9cbec725beed62eb425449083c59416ed975 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Nov 25 2016 15:18:22 +0000 Subject: Fix Python 3 bugs discovered by pylint In Python 3 exception instances no longer have a message attribute. For most exceptions, str(e) or string formatting give the same result. Fix some renamed modules, module members and functions. https://fedorahosted.org/freeipa/ticket/4985 Signed-off-by: Christian Heimes Reviewed-By: Martin Basti --- diff --git a/ipalib/krb_utils.py b/ipalib/krb_utils.py index e6e277c..d005a87 100644 --- a/ipalib/krb_utils.py +++ b/ipalib/krb_utils.py @@ -161,7 +161,7 @@ def get_credentials(name=None, ccache_name=None): return gssapi.Credentials(usage='initiate', name=name, store=store) except gssapi.exceptions.GSSError as e: if e.min_code == KRB5_FCC_NOFILE: # pylint: disable=no-member - raise ValueError('"%s", ccache="%s"' % (e.message, ccache_name)) + raise ValueError('"%s", ccache="%s"' % (e, ccache_name)) raise def get_principal(ccache_name=None): diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index bbfc6f6..94a5e1e 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -27,7 +27,10 @@ import contextlib import collections import os import pwd -from urlparse import urlparse + +# pylint: disable=import-error +from six.moves.urllib.parse import urlparse +# pylint: enable=import-error import ldap import ldap.sasl diff --git a/ipaserver/install/dns.py b/ipaserver/install/dns.py index dd4ab7b..842973f 100644 --- a/ipaserver/install/dns.py +++ b/ipaserver/install/dns.py @@ -132,7 +132,7 @@ def install_check(standalone, api, replica, options, hostname): if options.force or options.allow_zone_overlap: root_logger.warning("%s Please make sure that the domain is " "properly delegated to this IPA server.", - e.message) + e) else: raise e @@ -141,7 +141,7 @@ def install_check(standalone, api, replica, options, hostname): dnsutil.check_zone_overlap(reverse_zone) except ValueError as e: if options.force or options.allow_zone_overlap: - root_logger.warning(e.message) + root_logger.warning(six.text_type(e)) else: raise e diff --git a/ipaserver/plugins/aci.py b/ipaserver/plugins/aci.py index c353715..e09a0ab 100644 --- a/ipaserver/plugins/aci.py +++ b/ipaserver/plugins/aci.py @@ -354,7 +354,7 @@ def _aci_to_kw(ldap, a, test=False, pkey_only=False): try: targetdn = DN(target.replace('ldap:///','')) except ValueError as e: - raise errors.ValidationError(name='subtree', error=_("invalid DN (%s)") % e.message) + raise errors.ValidationError(name='subtree', error=_("invalid DN (%s)") % e) if targetdn.endswith(DN(api.env.container_group, api.env.basedn)): kw['targetgroup'] = targetdn[0]['cn'] else: diff --git a/ipaserver/plugins/dns.py b/ipaserver/plugins/dns.py index 3336e9e..08f9c6d 100644 --- a/ipaserver/plugins/dns.py +++ b/ipaserver/plugins/dns.py @@ -2149,7 +2149,7 @@ class DNSZoneBase_add(LDAPCreate): try: check_zone_overlap(keys[-1], raise_on_error=False) except ValueError as e: - raise errors.InvocationError(e.message) + raise errors.InvocationError(six.text_type(e)) return dn diff --git a/ipatests/i18n.py b/ipatests/i18n.py index aa8932d..80f9827 100755 --- a/ipatests/i18n.py +++ b/ipatests/i18n.py @@ -32,6 +32,8 @@ import traceback import polib from collections import namedtuple +import six + ''' We test our translations by taking the original untranslated string (e.g. msgid) and prepend a prefix character and then append a suffix @@ -610,8 +612,14 @@ def test_translations(po_file, lang, domain, locale_dir): t = gettext.translation(domain, locale_dir) - get_msgstr = t.ugettext - get_msgstr_plural = t.ungettext + if six.PY2: + # pylint: disable=no-member + get_msgstr = t.ugettext + get_msgstr_plural = t.ungettext + # pylint: enable=no-member + else: + get_msgstr = t.gettext + get_msgstr_plural = t.ngettext return po_file_iterate(po_file, get_msgstr, get_msgstr_plural) diff --git a/ipatests/test_integration/env_config.py b/ipatests/test_integration/env_config.py index 6e3770f..2a137c6 100644 --- a/ipatests/test_integration/env_config.py +++ b/ipatests/test_integration/env_config.py @@ -114,8 +114,8 @@ def config_from_env(env): try: import yaml except ImportError as e: - raise ImportError("%s, please install PyYAML package to fix it" % - e.message) + raise ImportError( + "%s, please install PyYAML package to fix it" % e) with open(env['IPATEST_YAML_CONFIG']) as file: confdict = yaml.safe_load(file) return Config.from_dict(confdict) diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py index c6aab32..58b3a65 100644 --- a/ipatests/test_integration/tasks.py +++ b/ipatests/test_integration/tasks.py @@ -1032,7 +1032,8 @@ def install_topo(topo, master, replicas, clients, domain_level=None, def install_clients(servers, clients): """Install IPA clients, distributing them among the given servers""" - for server, client in itertools.izip(itertools.cycle(servers), clients): + izip = getattr(itertools, 'izip', zip) + for server, client in izip(itertools.cycle(servers), clients): log.info('Installing client %s on %s' % (server, client)) install_client(server, client) diff --git a/ipatests/test_integration/test_idviews.py b/ipatests/test_integration/test_idviews.py index 9df8c0a..8a117e0 100644 --- a/ipatests/test_integration/test_idviews.py +++ b/ipatests/test_integration/test_idviews.py @@ -68,7 +68,7 @@ class TestCertsInIDOverrides(IntegrationTest): # Initialize NSS database tasks.run_certutil(master, ["-N", "-f", cls.pwname], cls.reqdir) # Now generate self-signed certs for a windows user - stdin_text = string.digits+string.letters[2:] + '\n' + stdin_text = string.digits+string.ascii_letters[2:] + '\n' tasks.run_certutil(master, ['-S', '-s', "cn=%s,dc=ad,dc=test" % cls.adcert1, '-n', cls.adcert1, '-x', '-t', 'CT,C,C', '-v', diff --git a/ipatests/test_xmlrpc/test_automount_plugin.py b/ipatests/test_xmlrpc/test_automount_plugin.py index e3ad8b4..aa39b60 100644 --- a/ipatests/test_xmlrpc/test_automount_plugin.py +++ b/ipatests/test_xmlrpc/test_automount_plugin.py @@ -106,7 +106,7 @@ class AutomountTest(XMLRPC_test): skipped=(), duplicatemaps=(), duplicatekeys=(), - )), res) + )), res) # pylint: disable=used-before-assignment self.check_tofiles() finally: res = api.Command['automountlocation_del'](self.locname)['result']