31: Renamed exceptions.py to errors.py

This commit is contained in:
Jason Gerard DeRose
2008-07-31 18:57:10 +00:00
parent bc1675dc38
commit d7569a84b9
5 changed files with 25 additions and 25 deletions

View File

@@ -23,7 +23,7 @@ Base classes for plug-in architecture and generative API.
import re import re
import inspect import inspect
import exceptions import errors
class NameSpace(object): class NameSpace(object):
@@ -45,7 +45,7 @@ class NameSpace(object):
For example, setting an attribute the normal way will raise an exception: For example, setting an attribute the normal way will raise an exception:
>>> ns.my_message = 'some new value' >>> ns.my_message = 'some new value'
(raises exceptions.SetError) (raises errors.SetError)
But a programmer could still set the attribute like this: But a programmer could still set the attribute like this:
@@ -82,7 +82,7 @@ class NameSpace(object):
NameSpace has been locked; otherwise calls object.__setattr__(). NameSpace has been locked; otherwise calls object.__setattr__().
""" """
if self.__locked: if self.__locked:
raise exceptions.SetError(name) raise errors.SetError(name)
super(NameSpace, self).__setattr__(name, value) super(NameSpace, self).__setattr__(name, value)
def __getitem__(self, key): def __getitem__(self, key):
@@ -190,7 +190,7 @@ class Attribute(Named):
return self.__obj return self.__obj
def __set_obj(self, obj): def __set_obj(self, obj):
if self.__obj is not None: if self.__obj is not None:
raise exceptions.TwiceSetError(self.__class__.__name__, 'obj') raise errors.TwiceSetError(self.__class__.__name__, 'obj')
assert isinstance(obj, Object) assert isinstance(obj, Object)
self.__obj = obj self.__obj = obj
assert self.obj is obj assert self.obj is obj
@@ -227,7 +227,7 @@ class Object(Named):
return self.__methods return self.__methods
def __set_methods(self, methods): def __set_methods(self, methods):
if self.__methods is not None: if self.__methods is not None:
raise exceptions.TwiceSetError( raise errors.TwiceSetError(
self.__class__.__name__, 'methods' self.__class__.__name__, 'methods'
) )
assert type(methods) is NameSpace assert type(methods) is NameSpace
@@ -239,7 +239,7 @@ class Object(Named):
return self.__properties return self.__properties
def __set_properties(self, properties): def __set_properties(self, properties):
if self.__properties is not None: if self.__properties is not None:
raise exceptions.TwiceSetError( raise errors.TwiceSetError(
self.__class__.__name__, 'properties' self.__class__.__name__, 'properties'
) )
assert type(properties) is NameSpace assert type(properties) is NameSpace
@@ -338,11 +338,11 @@ class Registrar(object):
def __findbase(self, cls): def __findbase(self, cls):
if not inspect.isclass(cls): if not inspect.isclass(cls):
raise exceptions.RegistrationError('not a class', cls) raise errors.RegistrationError('not a class', cls)
for base in self.__allowed: for base in self.__allowed:
if issubclass(cls, base): if issubclass(cls, base):
return base return base
raise exceptions.RegistrationError( raise errors.RegistrationError(
'not subclass of an allowed base', 'not subclass of an allowed base',
cls, cls,
) )

View File

@@ -18,12 +18,12 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
All custom exceptions raised by `ipalib` package. All custom errors raised by `ipalib` package.
""" """
class IPAError(Exception): class IPAError(Exception):
""" """
Use this base class for your custom IPA exceptions unless there is a Use this base class for your custom IPA errors unless there is a
specific reason to subclass from AttributeError, KeyError, etc. specific reason to subclass from AttributeError, KeyError, etc.
""" """
msg = None msg = None

View File

@@ -22,7 +22,7 @@ Utility classes for registering plugins, base classe for writing plugins.
""" """
import inspect import inspect
import exceptions import errors
@@ -50,7 +50,7 @@ class Registrar(object):
for base in self.__allowed: for base in self.__allowed:
if issubclass(cls, base): if issubclass(cls, base):
return base return base
raise exceptions.SubclassError(cls, self.__allowed) raise errors.SubclassError(cls, self.__allowed)
def __call__(self, cls, override=False): def __call__(self, cls, override=False):
""" """
@@ -65,17 +65,17 @@ class Registrar(object):
# Raise DuplicateError if this exact class was already registered: # Raise DuplicateError if this exact class was already registered:
if cls in self.__registered: if cls in self.__registered:
raise exceptions.DuplicateError(cls) raise errors.DuplicateError(cls)
# Check override: # Check override:
if cls.__name__ in sub_d: if cls.__name__ in sub_d:
# Must use override=True to override: # Must use override=True to override:
if not override: if not override:
raise exceptions.OverrideError(base, cls) raise errors.OverrideError(base, cls)
else: else:
# There was nothing already registered to override: # There was nothing already registered to override:
if override: if override:
raise exceptions.MissingOverrideError(base, cls) raise errors.MissingOverrideError(base, cls)
# The plugin is okay, add to __registered and sub_d: # The plugin is okay, add to __registered and sub_d:
self.__registered.add(cls) self.__registered.add(cls)

View File

@@ -21,7 +21,7 @@
Unit tests for `ipalib.base` module. Unit tests for `ipalib.base` module.
""" """
from ipalib import base, exceptions, crud from ipalib import base, errors, crud
def read_only(obj, name): def read_only(obj, name):
@@ -129,7 +129,7 @@ class test_NameSpace:
raised = False raised = False
try: try:
setattr(ns, key, value) setattr(ns, key, value)
except exceptions.SetError: except errors.SetError:
raised = True raised = True
assert raised assert raised
assert getattr(ns, key, None) != value assert getattr(ns, key, None) != value
@@ -206,7 +206,7 @@ def test_Attribute():
raised = False raised = False
try: try:
i.obj = u i.obj = u
except exceptions.TwiceSetError: except errors.TwiceSetError:
raised = True raised = True
assert raised assert raised
@@ -307,14 +307,14 @@ class test_Registrar():
raised = False raised = False
try: try:
r(user()) r(user())
except exceptions.RegistrationError: except errors.RegistrationError:
raised = True raised = True
# Check that exception is raised trying to register class of wrong base: # Check that exception is raised trying to register class of wrong base:
raised = False raised = False
try: try:
r(wrong_base) r(wrong_base)
except exceptions.RegistrationError: except errors.RegistrationError:
raised = True raised = True
assert raised assert raised

View File

@@ -21,7 +21,7 @@
Unit tests for `ipalib.plugable` module. Unit tests for `ipalib.plugable` module.
""" """
from ipalib import plugable, exceptions from ipalib import plugable, errors
def test_Registrar(): def test_Registrar():
@@ -56,7 +56,7 @@ def test_Registrar():
raised = False raised = False
try: try:
r(plugin3) r(plugin3)
except exceptions.SubclassError: except errors.SubclassError:
raised = True raised = True
assert raised assert raised
@@ -74,7 +74,7 @@ def test_Registrar():
raised = False raised = False
try: try:
r(plugin1) r(plugin1)
except exceptions.DuplicateError: except errors.DuplicateError:
raised = True raised = True
assert raised assert raised
@@ -88,7 +88,7 @@ def test_Registrar():
raised = False raised = False
try: try:
r(plugin1) r(plugin1)
except exceptions.OverrideError: except errors.OverrideError:
raised = True raised = True
assert raised assert raised
@@ -104,7 +104,7 @@ def test_Registrar():
raised = False raised = False
try: try:
r(plugin2, override=True) r(plugin2, override=True)
except exceptions.MissingOverrideError: except errors.MissingOverrideError:
raised = True raised = True
assert raised assert raised