X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=userdir_exceptions.py;fp=userdir_exceptions.py;h=a1d775eb04118e7b111291365167e677cc408538;hp=0000000000000000000000000000000000000000;hb=25e44ab9788aeb949e3dd5143a4f52f1c076ee1b;hpb=468c615b25dee534d6c4cd2c5d14e3f1609df109 diff --git a/userdir_exceptions.py b/userdir_exceptions.py new file mode 100644 index 0000000..a1d775e --- /dev/null +++ b/userdir_exceptions.py @@ -0,0 +1,43 @@ +# vim: set fileencoding=utf-8 ai et sts=4 sw=4 tw=0: +# # -*- 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. + """ + def __init__(self, message): + Exception.__init__(self) + self.message = message + + def __str__(self): + return "UDError: %s" % 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.""", +} + +def construct_udld_exception(name, description): + """Generator function for userdir-ldap exceptions""" + + class Error(UDError): + """meta class for user-ldap exceptions""" + __doc__ = description + + setattr(Error, "__name__", name) + return Error + +for key in UDERRORS.keys(): + globals()[key] = construct_udld_exception(key, UDERRORS[key]) + __all__ += [key] +