1# Thanks to Kevin Jacob's 'Virtual Exceptions'
2# http://mail.python.org/pipermail/db-sig/2003-April/003345.html
3
4class Warning:
5    pass
6class Error:
7    pass
8class InterfaceError(Error):
9    pass
10class DatabaseError(Error):
11    pass
12class DataError(DatabaseError):
13    pass
14class OperationalError(DatabaseError):
15    pass
16class IntegrityError(DatabaseError):
17    pass
18class InternalError(DatabaseError):
19    pass
20class ProgrammingError(DatabaseError):
21    pass
22class NotSupportedError(DatabaseError):
23    pass
24
25_dbapi_exceptions = { 'Warning'             : Warning,
26                      'Error'               : Error,
27                      'InterfaceError'      : InterfaceError,
28                      'DatabaseError'       : DatabaseError,
29                      'DataError'           : DataError,
30                      'OperationalError'    : OperationalError,
31                      'IntegrityError'      : IntegrityError,
32                      'InternalError'       : InternalError,
33                      'ProgrammingError'    : ProgrammingError,
34                      'NotSupportedError'   : NotSupportedError }
35
36__all__ = _dbapi_exceptions.keys()
37
38def _setExceptions(wrapper):
39    driver = wrapper._driver
40    for exception in _dbapi_exceptions.keys():
41        dbapi_exception = _dbapi_exceptions[exception]
42        sub_exception = getattr(driver, exception)
43#        if (not StandardError in sub_exception.mro()):
44#            sub_exception.__bases__ += (StandardError, )
45        if (not dbapi_exception in sub_exception.mro()):
46            sub_exception.__bases__ += (dbapi_exception,)
47