2008-07-18 12:51:34 -05:00
|
|
|
# Authors:
|
|
|
|
# Jason Gerard DeRose <jderose@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Red Hat
|
2008-07-18 15:31:12 -05:00
|
|
|
# see file 'COPYING' for use and warranty inmsgion
|
2008-07-18 12:51:34 -05:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation; version 2 only
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
"""
|
2008-07-31 13:57:10 -05:00
|
|
|
All custom errors raised by `ipalib` package.
|
2008-07-18 12:51:34 -05:00
|
|
|
"""
|
|
|
|
|
2008-07-18 15:31:12 -05:00
|
|
|
class IPAError(Exception):
|
2008-08-08 12:11:29 -05:00
|
|
|
"""
|
|
|
|
Use this base class for your custom IPA errors unless there is a
|
|
|
|
specific reason to subclass from AttributeError, KeyError, etc.
|
|
|
|
"""
|
|
|
|
msg = None
|
|
|
|
|
|
|
|
def __init__(self, *args, **kw):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.args = args
|
|
|
|
self.kw = kw
|
2008-08-08 12:11:29 -05:00
|
|
|
|
|
|
|
def __str__(self):
|
2008-08-08 16:40:03 -05:00
|
|
|
"""
|
|
|
|
Returns the string representation of this exception.
|
|
|
|
"""
|
|
|
|
if self.msg is None:
|
|
|
|
if len(self.args) == 1:
|
|
|
|
return unicode(self.args[0])
|
|
|
|
return unicode(self.args)
|
|
|
|
if len(self.args) > 0:
|
|
|
|
return self.msg % self.args
|
|
|
|
return self.msg % self.kw
|
2008-07-18 12:51:34 -05:00
|
|
|
|
|
|
|
|
2008-08-06 22:38:49 -05:00
|
|
|
class ValidationError(IPAError):
|
2008-08-08 12:11:29 -05:00
|
|
|
msg = 'invalid %r value %r: %s'
|
2008-08-06 22:38:49 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, name, value, error):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.name = name
|
|
|
|
self.value = value
|
|
|
|
self.error = error
|
2008-08-12 23:11:26 -05:00
|
|
|
IPAError.__init__(self, name, value, error)
|
2008-08-06 22:38:49 -05:00
|
|
|
|
2008-08-07 01:23:02 -05:00
|
|
|
|
2008-08-06 22:38:49 -05:00
|
|
|
class NormalizationError(ValidationError):
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, name, value, type):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.type = type
|
2008-08-12 23:11:26 -05:00
|
|
|
ValidationError.__init__(self, name, value,
|
2008-08-08 16:40:03 -05:00
|
|
|
'not %r' % type
|
|
|
|
)
|
2008-08-06 22:38:49 -05:00
|
|
|
|
|
|
|
|
2008-08-07 01:23:02 -05:00
|
|
|
class RuleError(ValidationError):
|
2008-08-13 00:14:12 -05:00
|
|
|
"""
|
|
|
|
Raised when a required option was not provided.
|
|
|
|
"""
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, name, value, rule, error):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.rule = rule
|
2008-08-12 23:11:26 -05:00
|
|
|
ValidationError.__init__(self, name, value, error)
|
2008-07-27 23:34:25 -05:00
|
|
|
|
|
|
|
|
2008-08-13 00:14:12 -05:00
|
|
|
class RequirementError(ValidationError):
|
|
|
|
"""
|
|
|
|
Raised when a required option was not provided.
|
|
|
|
"""
|
|
|
|
def __init__(self, name):
|
|
|
|
ValidationError.__init__(self, name, None,
|
|
|
|
'missing required value'
|
|
|
|
)
|
|
|
|
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-07-19 02:43:48 -05:00
|
|
|
class SetError(IPAError):
|
2008-08-08 12:11:29 -05:00
|
|
|
msg = 'setting %r, but NameSpace does not allow attribute setting'
|
2008-07-18 23:28:03 -05:00
|
|
|
|
|
|
|
|
2008-07-19 02:43:48 -05:00
|
|
|
|
2008-07-18 23:28:03 -05:00
|
|
|
class RegistrationError(IPAError):
|
2008-08-08 12:11:29 -05:00
|
|
|
"""
|
|
|
|
Base class for errors that occur during plugin registration.
|
|
|
|
"""
|
2008-07-27 23:34:25 -05:00
|
|
|
|
|
|
|
|
2008-08-05 01:33:09 -05:00
|
|
|
class NameSpaceError(RegistrationError):
|
2008-08-08 12:11:29 -05:00
|
|
|
msg = 'name %r does not re.match %r'
|
2008-08-05 01:33:09 -05:00
|
|
|
|
|
|
|
|
2008-07-27 23:34:25 -05:00
|
|
|
class SubclassError(RegistrationError):
|
2008-08-08 12:11:29 -05:00
|
|
|
"""
|
|
|
|
Raised when registering a plugin that is not a subclass of one of the
|
|
|
|
allowed bases.
|
|
|
|
"""
|
|
|
|
msg = 'plugin %r not subclass of any base in %r'
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, cls, allowed):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.cls = cls
|
|
|
|
self.allowed = allowed
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __str__(self):
|
2008-08-08 16:40:03 -05:00
|
|
|
return self.msg % (self.cls, self.allowed)
|
2008-07-27 23:34:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
class DuplicateError(RegistrationError):
|
2008-08-08 12:11:29 -05:00
|
|
|
"""
|
|
|
|
Raised when registering a plugin whose exact class has already been
|
|
|
|
registered.
|
|
|
|
"""
|
|
|
|
msg = '%r at %d was already registered'
|
2008-07-19 01:03:34 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, cls):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.cls = cls
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __str__(self):
|
2008-08-08 16:40:03 -05:00
|
|
|
return self.msg % (self.cls, id(self.cls))
|
2008-07-27 23:34:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
class OverrideError(RegistrationError):
|
2008-08-08 12:11:29 -05:00
|
|
|
"""
|
|
|
|
Raised when override=False yet registering a plugin that overrides an
|
|
|
|
existing plugin in the same namespace.
|
|
|
|
"""
|
|
|
|
msg = 'unexpected override of %s.%s with %r (use override=True if intended)'
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, base, cls):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.base = base
|
|
|
|
self.cls = cls
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __str__(self):
|
2008-08-08 16:40:03 -05:00
|
|
|
return self.msg % (self.base.__name__, self.cls.__name__, self.cls)
|
2008-07-27 23:34:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
class MissingOverrideError(RegistrationError):
|
2008-08-08 12:11:29 -05:00
|
|
|
"""
|
|
|
|
Raised when override=True yet no preexisting plugin with the same name
|
|
|
|
and base has been registered.
|
|
|
|
"""
|
|
|
|
msg = '%s.%s has not been registered, cannot override with %r'
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __init__(self, base, cls):
|
2008-08-08 16:40:03 -05:00
|
|
|
self.base = base
|
|
|
|
self.cls = cls
|
2008-07-27 23:34:25 -05:00
|
|
|
|
2008-08-08 12:11:29 -05:00
|
|
|
def __str__(self):
|
2008-08-08 16:40:03 -05:00
|
|
|
return self.msg % (self.base.__name__, self.cls.__name__, self.cls)
|
2008-07-19 01:03:34 -05:00
|
|
|
|
2008-07-20 02:09:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TwiceSetError(IPAError):
|
2008-08-08 12:11:29 -05:00
|
|
|
msg = '%s.%s cannot be set twice'
|