X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=userdir_exceptions.py;h=ec879a934efcdbbfb9c2c69fb08ad1d3d6e6bcc1;hp=4e32307b8fbf5619efb2f7d97cebc724c132fccc;hb=HEAD;hpb=d91d0c5fd96a36bae43ecf2aa0460f663655c0fd diff --git a/userdir_exceptions.py b/userdir_exceptions.py index 4e32307..ec879a9 100644 --- a/userdir_exceptions.py +++ b/userdir_exceptions.py @@ -1,12 +1,13 @@ # vim: set fileencoding=utf-8 ai et sts=4 sw=4 tw=0: -# # -*- coding: -*- -## Userdir-LDAP exception classes -## © 2009 Stephen Gran -## © 2009 Mark Hymers +# -*- coding: -*- +# Userdir-LDAP exception classes +# © 2009 Stephen Gran +# © 2009 Mark Hymers """ These classes implement the necessary exceptions in the userdir-ldap namespace """ + class UDError(Exception): """ Base class for exceptions in ud-ldap. @@ -14,20 +15,24 @@ class UDError(Exception): def __init__(self, message): Exception.__init__(self) self.message = message - + def __str__(self): - return "UDError: %s" % self.message + return "%s: %s" % (self._name_, self.message) + __all__ = ['UDError'] + UDERRORS = { "UDPasswdError": """Exception raised for authentication errors.""", "UDFormatError": """Exception raised for data format errors.""", "UDExecuteError": """Exception raised for subprocess execution errors.""", "UDNotAllowedError": """Exception raised for attempts to modify off-limits or disabled entries.""", "UDEmptyList": """Exception raised for empty list objects.""", + "UDLoadFail": """Exception raised for LDAP lookup failures.""", } + def construct_udld_exception(name, description): """Generator function for userdir-ldap exceptions""" @@ -36,9 +41,10 @@ def construct_udld_exception(name, description): __doc__ = description setattr(Error, "__name__", name) + setattr(Error, "_name_", name) return Error + for key in UDERRORS.keys(): globals()[key] = construct_udld_exception(key, UDERRORS[key]) __all__ += [key] -