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 <cheimes@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Christian Heimes 2016-11-23 11:01:56 +01:00 committed by Martin Basti
parent 38e8719f72
commit 7fef9cbec7
10 changed files with 25 additions and 13 deletions

View File

@ -161,7 +161,7 @@ def get_credentials(name=None, ccache_name=None):
return gssapi.Credentials(usage='initiate', name=name, store=store) return gssapi.Credentials(usage='initiate', name=name, store=store)
except gssapi.exceptions.GSSError as e: except gssapi.exceptions.GSSError as e:
if e.min_code == KRB5_FCC_NOFILE: # pylint: disable=no-member 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 raise
def get_principal(ccache_name=None): def get_principal(ccache_name=None):

View File

@ -27,7 +27,10 @@ import contextlib
import collections import collections
import os import os
import pwd 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
import ldap.sasl import ldap.sasl

View File

@ -132,7 +132,7 @@ def install_check(standalone, api, replica, options, hostname):
if options.force or options.allow_zone_overlap: if options.force or options.allow_zone_overlap:
root_logger.warning("%s Please make sure that the domain is " root_logger.warning("%s Please make sure that the domain is "
"properly delegated to this IPA server.", "properly delegated to this IPA server.",
e.message) e)
else: else:
raise e raise e
@ -141,7 +141,7 @@ def install_check(standalone, api, replica, options, hostname):
dnsutil.check_zone_overlap(reverse_zone) dnsutil.check_zone_overlap(reverse_zone)
except ValueError as e: except ValueError as e:
if options.force or options.allow_zone_overlap: if options.force or options.allow_zone_overlap:
root_logger.warning(e.message) root_logger.warning(six.text_type(e))
else: else:
raise e raise e

View File

@ -354,7 +354,7 @@ def _aci_to_kw(ldap, a, test=False, pkey_only=False):
try: try:
targetdn = DN(target.replace('ldap:///','')) targetdn = DN(target.replace('ldap:///',''))
except ValueError as e: 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)): if targetdn.endswith(DN(api.env.container_group, api.env.basedn)):
kw['targetgroup'] = targetdn[0]['cn'] kw['targetgroup'] = targetdn[0]['cn']
else: else:

View File

@ -2149,7 +2149,7 @@ class DNSZoneBase_add(LDAPCreate):
try: try:
check_zone_overlap(keys[-1], raise_on_error=False) check_zone_overlap(keys[-1], raise_on_error=False)
except ValueError as e: except ValueError as e:
raise errors.InvocationError(e.message) raise errors.InvocationError(six.text_type(e))
return dn return dn

View File

@ -32,6 +32,8 @@ import traceback
import polib import polib
from collections import namedtuple from collections import namedtuple
import six
''' '''
We test our translations by taking the original untranslated string We test our translations by taking the original untranslated string
(e.g. msgid) and prepend a prefix character and then append a suffix (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) t = gettext.translation(domain, locale_dir)
get_msgstr = t.ugettext if six.PY2:
get_msgstr_plural = t.ungettext # 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) return po_file_iterate(po_file, get_msgstr, get_msgstr_plural)

View File

@ -114,8 +114,8 @@ def config_from_env(env):
try: try:
import yaml import yaml
except ImportError as e: except ImportError as e:
raise ImportError("%s, please install PyYAML package to fix it" % raise ImportError(
e.message) "%s, please install PyYAML package to fix it" % e)
with open(env['IPATEST_YAML_CONFIG']) as file: with open(env['IPATEST_YAML_CONFIG']) as file:
confdict = yaml.safe_load(file) confdict = yaml.safe_load(file)
return Config.from_dict(confdict) return Config.from_dict(confdict)

View File

@ -1032,7 +1032,8 @@ def install_topo(topo, master, replicas, clients, domain_level=None,
def install_clients(servers, clients): def install_clients(servers, clients):
"""Install IPA clients, distributing them among the given servers""" """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)) log.info('Installing client %s on %s' % (server, client))
install_client(server, client) install_client(server, client)

View File

@ -68,7 +68,7 @@ class TestCertsInIDOverrides(IntegrationTest):
# Initialize NSS database # Initialize NSS database
tasks.run_certutil(master, ["-N", "-f", cls.pwname], cls.reqdir) tasks.run_certutil(master, ["-N", "-f", cls.pwname], cls.reqdir)
# Now generate self-signed certs for a windows user # 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', tasks.run_certutil(master, ['-S', '-s',
"cn=%s,dc=ad,dc=test" % cls.adcert1, '-n', "cn=%s,dc=ad,dc=test" % cls.adcert1, '-n',
cls.adcert1, '-x', '-t', 'CT,C,C', '-v', cls.adcert1, '-x', '-t', 'CT,C,C', '-v',

View File

@ -106,7 +106,7 @@ class AutomountTest(XMLRPC_test):
skipped=(), skipped=(),
duplicatemaps=(), duplicatemaps=(),
duplicatekeys=(), duplicatekeys=(),
)), res) )), res) # pylint: disable=used-before-assignment
self.check_tofiles() self.check_tofiles()
finally: finally:
res = api.Command['automountlocation_del'](self.locname)['result'] res = api.Command['automountlocation_del'](self.locname)['result']