ud-mailgate: remove exception for münchen.debian.net
[mirror/userdir-ldap.git] / userdir_exceptions.py
1 # vim: set fileencoding=utf-8 ai et sts=4 sw=4 tw=0:
2 # -*- coding: <utf-8> -*-
3 # Userdir-LDAP exception classes
4 # © 2009 Stephen Gran <sgran@debian.org>
5 # © 2009 Mark Hymers <mhy@debian.org>
6 """
7 These classes implement the necessary exceptions in the userdir-ldap namespace
8 """
9
10
11 class UDError(Exception):
12     """
13     Base class for exceptions in ud-ldap.
14     """
15     def __init__(self, message):
16         Exception.__init__(self)
17         self.message = message
18
19     def __str__(self):
20         return "%s: %s" % (self._name_, self.message)
21
22
23 __all__ = ['UDError']
24
25
26 UDERRORS = {
27     "UDPasswdError": """Exception raised for authentication errors.""",
28     "UDFormatError": """Exception raised for data format errors.""",
29     "UDExecuteError": """Exception raised for subprocess execution errors.""",
30     "UDNotAllowedError": """Exception raised for attempts to modify off-limits or disabled entries.""",
31     "UDEmptyList": """Exception raised for empty list objects.""",
32     "UDLoadFail": """Exception raised for LDAP lookup failures.""",
33 }
34
35
36 def construct_udld_exception(name, description):
37     """Generator function for userdir-ldap exceptions"""
38
39     class Error(UDError):
40         """meta class for user-ldap exceptions"""
41         __doc__ = description
42
43     setattr(Error, "__name__", name)
44     setattr(Error, "_name_", name)
45     return Error
46
47
48 for key in UDERRORS.keys():
49     globals()[key] = construct_udld_exception(key, UDERRORS[key])
50     __all__ += [key]