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)
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):

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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',

View File

@ -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']