mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Replace StandardError with Exception
StandardError was removed in Python3 and instead Exception should be used. Signed-off-by: Robert Kuska <rkuska@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
committed by
Jan Cholasta
parent
34e6c3ea05
commit
01da4a8de3
@@ -754,7 +754,7 @@ def run(api):
|
||||
api.log.info('operation aborted')
|
||||
except PublicError, e:
|
||||
error = e
|
||||
except StandardError, e:
|
||||
except Exception, e:
|
||||
api.log.exception('%s: %s', e.__class__.__name__, str(e))
|
||||
error = InternalError()
|
||||
if error is not None:
|
||||
|
||||
@@ -13,7 +13,7 @@ env._finalize_core(**dict(DEFAULT_CONFIG))
|
||||
api.bootstrap(context='server', debug=env.debug, log=None) (ref:wsgi-app-bootstrap)
|
||||
try:
|
||||
api.finalize() (ref:wsgi-app-finalize)
|
||||
except StandardError, e:
|
||||
except Exception, e:
|
||||
api.log.error('Failed to start IPA: %s' % e)
|
||||
else:
|
||||
api.log.info('*** PROCESS START ***')
|
||||
|
||||
@@ -38,7 +38,7 @@ env._finalize_core(**dict(DEFAULT_CONFIG))
|
||||
api.bootstrap(context='server', debug=env.debug, log=None)
|
||||
try:
|
||||
api.finalize()
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
api.log.error('Failed to start IPA: %s' % e)
|
||||
else:
|
||||
api.log.info('*** PROCESS START ***')
|
||||
|
||||
@@ -1818,7 +1818,7 @@ def update_ssh_keys(server, hostname, ssh_dir, create_sshfp):
|
||||
)
|
||||
except errors.EmptyModlist:
|
||||
pass
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
root_logger.info("host_mod: %s", str(e))
|
||||
root_logger.warning("Failed to upload host SSH public keys.")
|
||||
return
|
||||
|
||||
@@ -56,7 +56,7 @@ class Connectible(Backend):
|
||||
Create thread-local connection.
|
||||
"""
|
||||
if hasattr(context, self.id):
|
||||
raise StandardError(
|
||||
raise Exception(
|
||||
"connect: 'context.%s' already exists in thread %r" % (
|
||||
self.id, threading.currentThread().getName()
|
||||
)
|
||||
@@ -71,7 +71,7 @@ class Connectible(Backend):
|
||||
|
||||
def disconnect(self):
|
||||
if not hasattr(context, self.id):
|
||||
raise StandardError(
|
||||
raise Exception(
|
||||
"disconnect: 'context.%s' does not exist in thread %r" % (
|
||||
self.id, threading.currentThread().getName()
|
||||
)
|
||||
@@ -130,7 +130,7 @@ class Executioner(Backend):
|
||||
result = self.Command[_name](*args, **options)
|
||||
except PublicError as e:
|
||||
error = e
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
self.exception(
|
||||
'non-public: %s: %s', e.__class__.__name__, str(e)
|
||||
)
|
||||
|
||||
@@ -1350,7 +1350,7 @@ def run(api):
|
||||
api.log.info('operation aborted')
|
||||
except PublicError as e:
|
||||
error = e
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
api.log.exception('%s: %s', e.__class__.__name__, str(e))
|
||||
error = InternalError()
|
||||
if error is not None:
|
||||
|
||||
@@ -210,7 +210,7 @@ class Env(object):
|
||||
Prevent further changes to environment.
|
||||
"""
|
||||
if self.__locked is True:
|
||||
raise StandardError(
|
||||
raise Exception(
|
||||
'%s.__lock__() already called' % self.__class__.__name__
|
||||
)
|
||||
object.__setattr__(self, '_Env__locked', True)
|
||||
@@ -407,7 +407,7 @@ class Env(object):
|
||||
|
||||
def __doing(self, name):
|
||||
if name in self.__done:
|
||||
raise StandardError(
|
||||
raise Exception(
|
||||
'%s.%s() already called' % (self.__class__.__name__, name)
|
||||
)
|
||||
self.__done.add(name)
|
||||
|
||||
@@ -49,7 +49,7 @@ TYPE_ERROR = '%s: need a %r; got %r (a %r)'
|
||||
# Stardard format for TypeError message when a callable is expected:
|
||||
CALLABLE_ERROR = '%s: need a callable; got %r (which is a %r)'
|
||||
|
||||
# Standard format for StandardError message when overriding an attribute:
|
||||
# Standard format for Exception message when overriding an attribute:
|
||||
OVERRIDE_ERROR = 'cannot override %s.%s value %r with %r'
|
||||
|
||||
# Standard format for AttributeError message when a read-only attribute is
|
||||
|
||||
@@ -107,7 +107,7 @@ from ipalib import messages
|
||||
from ipaplatform.paths import paths
|
||||
|
||||
|
||||
class PrivateError(StandardError):
|
||||
class PrivateError(Exception):
|
||||
"""
|
||||
Base class for exceptions that are *never* forwarded in an RPC response.
|
||||
"""
|
||||
@@ -122,7 +122,7 @@ class PrivateError(StandardError):
|
||||
self.__class__.__name__, key, value,
|
||||
)
|
||||
setattr(self, key, value)
|
||||
StandardError.__init__(self, self.msg)
|
||||
Exception.__init__(self, self.msg)
|
||||
|
||||
|
||||
class SubprocessError(PrivateError):
|
||||
@@ -239,7 +239,7 @@ def _(message):
|
||||
return message
|
||||
|
||||
|
||||
class PublicError(StandardError):
|
||||
class PublicError(Exception):
|
||||
"""
|
||||
**900** Base class for exceptions that can be forwarded in an RPC response.
|
||||
"""
|
||||
|
||||
@@ -242,7 +242,7 @@ class DefaultFrom(ReadOnly):
|
||||
return
|
||||
try:
|
||||
return self.callback(*vals)
|
||||
except StandardError:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def __json__(self):
|
||||
@@ -740,7 +740,7 @@ class Param(ReadOnly):
|
||||
return value
|
||||
try:
|
||||
return self.normalizer(value)
|
||||
except StandardError:
|
||||
except Exception:
|
||||
return value
|
||||
|
||||
def convert(self, value):
|
||||
@@ -917,7 +917,7 @@ class Param(ReadOnly):
|
||||
if default is not None:
|
||||
try:
|
||||
return self.convert(self.normalize(default))
|
||||
except StandardError:
|
||||
except Exception:
|
||||
pass
|
||||
return self.default
|
||||
|
||||
|
||||
@@ -360,7 +360,7 @@ class API(ReadOnly):
|
||||
|
||||
def __doing(self, name):
|
||||
if name in self.__done:
|
||||
raise StandardError(
|
||||
raise Exception(
|
||||
'%s.%s() already called' % (self.__class__.__name__, name)
|
||||
)
|
||||
self.__done.add(name)
|
||||
@@ -572,7 +572,7 @@ class API(ReadOnly):
|
||||
module = importlib.import_module(name)
|
||||
except errors.SkipPluginModule as e:
|
||||
self.log.debug("skipping plugin module %s: %s", name, e.reason)
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
if self.env.startup_traceback:
|
||||
import traceback
|
||||
self.log.error("could not load plugin module %s\n%s", name,
|
||||
|
||||
@@ -31,7 +31,7 @@ from ipalib.plugins.user import NO_UPG_MAGIC
|
||||
if api.env.in_server and api.env.context in ['lite', 'server']:
|
||||
try:
|
||||
from ipaserver.plugins.ldap2 import ldap2
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
raise e
|
||||
from ipalib import _
|
||||
from ipapython.dn import DN
|
||||
@@ -922,7 +922,7 @@ can use their Kerberos accounts.''')
|
||||
ds_base_dn = DN(entries[0]['namingcontexts'][0])
|
||||
assert isinstance(ds_base_dn, DN)
|
||||
except (IndexError, KeyError) as e:
|
||||
raise StandardError(str(e))
|
||||
raise Exception(str(e))
|
||||
|
||||
# migrate!
|
||||
(migrated, failed) = self.migrate(
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#
|
||||
|
||||
|
||||
class SetseboolError(StandardError):
|
||||
class SetseboolError(Exception):
|
||||
"""Raised when setting a SELinux boolean fails
|
||||
|
||||
:param failed: Dictionary mapping boolean names to intended values
|
||||
|
||||
@@ -282,11 +282,11 @@ class wsgi_dispatch(Executioner, HTTP_Status):
|
||||
Mount the WSGI application *app* at *key*.
|
||||
"""
|
||||
# if self.__islocked__():
|
||||
# raise StandardError('%s.mount(): locked, cannot mount %r at %r' % (
|
||||
# raise Exception('%s.mount(): locked, cannot mount %r at %r' % (
|
||||
# self.name, app, key)
|
||||
# )
|
||||
if key in self.__apps:
|
||||
raise StandardError('%s.mount(): cannot replace %r with %r at %r' % (
|
||||
raise Exception('%s.mount(): cannot replace %r with %r at %r' % (
|
||||
self.name, self.__apps[key], app, key)
|
||||
)
|
||||
self.debug('Mounting %r at %r', app, key)
|
||||
@@ -354,7 +354,7 @@ class WSGIExecutioner(Executioner):
|
||||
if self.api.env.debug:
|
||||
self.debug('WSGI wsgi_execute PublicError: %s', traceback.format_exc())
|
||||
error = e
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
self.exception(
|
||||
'non-public: %s: %s', e.__class__.__name__, str(e)
|
||||
)
|
||||
@@ -407,7 +407,7 @@ class WSGIExecutioner(Executioner):
|
||||
status = HTTP_STATUS_SUCCESS
|
||||
response = self.wsgi_execute(environ)
|
||||
headers = [('Content-Type', self.content_type + '; charset=utf-8')]
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
self.exception('WSGI %s.__call__():', self.name)
|
||||
status = HTTP_STATUS_SERVER_ERROR
|
||||
response = status
|
||||
|
||||
@@ -46,7 +46,7 @@ def use_keytab(principal, keytab):
|
||||
conn.connect(autobind=ipaldap.AUTOBIND_DISABLED)
|
||||
conn.disconnect()
|
||||
except gssapi.exceptions.GSSError as e:
|
||||
raise StandardError('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal, keytab, str(e)))
|
||||
raise Exception('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal, keytab, str(e)))
|
||||
finally:
|
||||
os.environ.pop('KRB5CCNAME', None)
|
||||
if tmpdir:
|
||||
@@ -138,7 +138,7 @@ class test_ipagetkeytab(cmdline_test):
|
||||
"""
|
||||
try:
|
||||
use_keytab(self.service_princ, self.keytabname)
|
||||
except StandardError as errmsg:
|
||||
except Exception as errmsg:
|
||||
assert('Unable to bind to LDAP. Error initializing principal' in str(errmsg))
|
||||
|
||||
def test_9_cleanup(self):
|
||||
|
||||
@@ -90,9 +90,9 @@ class test_Connectible(ClassChecker):
|
||||
assert conn.conn == 'The connection.'
|
||||
assert conn.disconnect == o.disconnect
|
||||
|
||||
# Test that StandardError is raised if already connected:
|
||||
# Test that Exception is raised if already connected:
|
||||
m = "connect: 'context.%s' already exists in thread %r"
|
||||
e = raises(StandardError, o.connect, *args, **kw)
|
||||
e = raises(Exception, o.connect, *args, **kw)
|
||||
assert str(e) == m % ('example', threading.currentThread().getName())
|
||||
|
||||
# Double check that it works after deleting context.example:
|
||||
@@ -121,7 +121,7 @@ class test_Connectible(ClassChecker):
|
||||
o = example(api, shared_instance=True)
|
||||
|
||||
m = "disconnect: 'context.%s' does not exist in thread %r"
|
||||
e = raises(StandardError, o.disconnect)
|
||||
e = raises(Exception, o.disconnect)
|
||||
assert str(e) == m % ('example', threading.currentThread().getName())
|
||||
|
||||
context.example = 'The connection.'
|
||||
|
||||
@@ -166,7 +166,7 @@ class test_Env(ClassChecker):
|
||||
assert o.__islocked__() is False
|
||||
o.__lock__()
|
||||
assert o.__islocked__() is True
|
||||
e = raises(StandardError, o.__lock__)
|
||||
e = raises(Exception, o.__lock__)
|
||||
assert str(e) == 'Env.__lock__() already called'
|
||||
|
||||
# Also test with base.lock() function:
|
||||
@@ -429,7 +429,7 @@ class test_Env(ClassChecker):
|
||||
assert o._isdone('_bootstrap') is False
|
||||
o._bootstrap(**overrides)
|
||||
assert o._isdone('_bootstrap') is True
|
||||
e = raises(StandardError, o._bootstrap)
|
||||
e = raises(Exception, o._bootstrap)
|
||||
assert str(e) == 'Env._bootstrap() already called'
|
||||
return (o, home)
|
||||
|
||||
@@ -512,7 +512,7 @@ class test_Env(ClassChecker):
|
||||
assert key in o
|
||||
|
||||
# Check that it can't be called twice:
|
||||
e = raises(StandardError, o._finalize_core)
|
||||
e = raises(Exception, o._finalize_core)
|
||||
assert str(e) == 'Env._finalize_core() already called'
|
||||
|
||||
return (o, home)
|
||||
@@ -586,7 +586,7 @@ class test_Env(ClassChecker):
|
||||
assert o._isdone('_finalize') is True
|
||||
|
||||
# Check that it can't be called twice:
|
||||
e = raises(StandardError, o._finalize)
|
||||
e = raises(Exception, o._finalize)
|
||||
assert str(e) == 'Env._finalize() already called'
|
||||
|
||||
# Check that _finalize() calls __lock__()
|
||||
@@ -594,7 +594,7 @@ class test_Env(ClassChecker):
|
||||
assert o.__islocked__() is False
|
||||
o._finalize()
|
||||
assert o.__islocked__() is True
|
||||
e = raises(StandardError, o.__lock__)
|
||||
e = raises(Exception, o.__lock__)
|
||||
assert str(e) == 'Env.__lock__() already called'
|
||||
|
||||
# Check that **lastchance works
|
||||
|
||||
@@ -45,7 +45,7 @@ class PrivateExceptionTester(object):
|
||||
def __get_klass(self):
|
||||
if self.__klass is None:
|
||||
self.__klass = self._klass
|
||||
assert issubclass(self.__klass, StandardError)
|
||||
assert issubclass(self.__klass, Exception)
|
||||
assert issubclass(self.__klass, errors.PrivateError)
|
||||
assert not issubclass(self.__klass, errors.PublicError)
|
||||
return self.__klass
|
||||
@@ -55,7 +55,7 @@ class PrivateExceptionTester(object):
|
||||
for (key, value) in kw.items():
|
||||
assert not hasattr(self.klass, key), key
|
||||
inst = self.klass(**kw)
|
||||
assert isinstance(inst, StandardError)
|
||||
assert isinstance(inst, Exception)
|
||||
assert isinstance(inst, errors.PrivateError)
|
||||
assert isinstance(inst, self.klass)
|
||||
assert not isinstance(inst, errors.PublicError)
|
||||
@@ -203,7 +203,7 @@ class PublicExceptionTester(object):
|
||||
def __get_klass(self):
|
||||
if self.__klass is None:
|
||||
self.__klass = self._klass
|
||||
assert issubclass(self.__klass, StandardError)
|
||||
assert issubclass(self.__klass, Exception)
|
||||
assert issubclass(self.__klass, errors.PublicError)
|
||||
assert not issubclass(self.__klass, errors.PrivateError)
|
||||
assert type(self.__klass.errno) is int
|
||||
@@ -234,7 +234,7 @@ class test_PublicError(PublicExceptionTester):
|
||||
Test the `ipalib.errors.PublicError` exception.
|
||||
"""
|
||||
_klass = errors.PublicError
|
||||
required_classes = StandardError, errors.PublicError
|
||||
required_classes = Exception, errors.PublicError
|
||||
|
||||
def test_init(self):
|
||||
message = u'The translated, interpolated message'
|
||||
@@ -375,7 +375,7 @@ class BaseMessagesTest(object):
|
||||
class test_PublicErrors(object):
|
||||
message_list = errors.public_errors
|
||||
errno_range = list(range(900, 5999))
|
||||
required_classes = (StandardError, errors.PublicError)
|
||||
required_classes = (Exception, errors.PublicError)
|
||||
texts = errors._texts
|
||||
|
||||
def extratest(self, cls):
|
||||
|
||||
@@ -80,7 +80,7 @@ class test_Plugin(ClassChecker):
|
||||
# whose names conflict with the logger methods set in Plugin.__init__():
|
||||
class check(self.cls):
|
||||
info = 'whatever'
|
||||
e = raises(StandardError, check, api)
|
||||
e = raises(Exception, check, api)
|
||||
assert str(e) == \
|
||||
"info is already bound to ipatests.test_ipalib.test_plugable.check()"
|
||||
|
||||
@@ -257,7 +257,7 @@ class test_API(ClassChecker):
|
||||
assert inst.method(7) == 7 + b
|
||||
|
||||
# Test that calling finilize again raises AssertionError:
|
||||
e = raises(StandardError, api.finalize)
|
||||
e = raises(Exception, api.finalize)
|
||||
assert str(e) == 'API.finalize() already called', str(e)
|
||||
|
||||
def test_bootstrap(self):
|
||||
@@ -273,7 +273,7 @@ class test_API(ClassChecker):
|
||||
assert o.env._isdone('_bootstrap') is True
|
||||
assert o.env._isdone('_finalize_core') is True
|
||||
assert o.env.my_test_override == 'Hello, world!'
|
||||
e = raises(StandardError, o.bootstrap)
|
||||
e = raises(Exception, o.bootstrap)
|
||||
assert str(e) == 'API.bootstrap() already called'
|
||||
|
||||
def test_load_plugins(self):
|
||||
@@ -286,5 +286,5 @@ class test_API(ClassChecker):
|
||||
o.load_plugins()
|
||||
assert o.isdone('bootstrap') is True
|
||||
assert o.isdone('load_plugins') is True
|
||||
e = raises(StandardError, o.load_plugins)
|
||||
e = raises(Exception, o.load_plugins)
|
||||
assert str(e) == 'API.load_plugins() already called'
|
||||
|
||||
@@ -173,8 +173,8 @@ class test_session(object):
|
||||
assert inst['foo'] is app1
|
||||
assert list(inst) == ['foo']
|
||||
|
||||
# Test that StandardError is raise if trying override a mount:
|
||||
e = raises(StandardError, inst.mount, app2, 'foo')
|
||||
# Test that Exception is raise if trying override a mount:
|
||||
e = raises(Exception, inst.mount, app2, 'foo')
|
||||
assert str(e) == '%s.mount(): cannot replace %r with %r at %r' % (
|
||||
'wsgi_dispatch', app1, app2, 'foo'
|
||||
)
|
||||
|
||||
@@ -313,7 +313,7 @@ class Declarative(XMLRPC_test):
|
||||
name = klass.__name__
|
||||
try:
|
||||
output = api.Command[cmd](*args, **options)
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError(
|
||||
@@ -336,7 +336,7 @@ class Declarative(XMLRPC_test):
|
||||
e = None
|
||||
try:
|
||||
output = api.Command[cmd](*args, **options)
|
||||
except StandardError as e:
|
||||
except Exception as e:
|
||||
pass
|
||||
if not expected(e, output):
|
||||
raise AssertionError(
|
||||
|
||||
Reference in New Issue
Block a user