0001"""
0002`DB-API <http://www.python.org/peps/pep-0249.html>`_ exceptions.
0003
0004This is the exception inheritance layout::
0005
0006    StandardError
0007    |__Warning
0008    |__Error
0009       |__InterfaceError
0010       |__DatabaseError
0011          |__DataError
0012          |__OperationalError
0013          |__IntegrityError
0014          |__InternalError
0015          |__ProgrammingError
0016          |__NotSupportedError
0017"""
0018
0019class Warning(StandardError):
0020    """
0021    Exception raised for important warnings like data
0022    truncations while inserting, etc. It must be a subclass of
0023    the Python StandardError (defined in the module
0024    exceptions).
0025    """
0026
0027class Error(StandardError):
0028    """
0029    Exception that is the base class of all other error
0030    exceptions. You can use this to catch all errors with one
0031    single 'except' statement. Warnings are not considered
0032    errors and thus should not use this class as base. It must
0033    be a subclass of the Python StandardError (defined in the
0034    module exceptions).
0035    """
0036
0037class InterfaceError(Error):
0038    """
0039    Exception raised for errors that are related to the
0040    database interface rather than the database itself.  It
0041    must be a subclass of Error.
0042    """
0043
0044class DatabaseError(Error):
0045    """
0046    Exception raised for errors that are related to the
0047    database.  It must be a subclass of Error.
0048    """
0049
0050class DataError(DatabaseError):
0051    """
0052    Exception raised for errors that are due to problems with
0053    the processed data like division by zero, numeric value
0054    out of range, etc. It must be a subclass of DatabaseError.
0055    """
0056
0057class OperationalError(DatabaseError):
0058    """
0059    Exception raised for errors that are related to the
0060    database's operation and not necessarily under the control
0061    of the programmer, e.g. an unexpected disconnect occurs,
0062    the data source name is not found, a transaction could not
0063    be processed, a memory allocation error occurred during
0064    processing, etc.  It must be a subclass of DatabaseError.
0065    """
0066
0067class IntegrityError(DatabaseError):
0068    """
0069    Exception raised when the relational integrity of the
0070    database is affected, e.g. a foreign key check fails.  It
0071    must be a subclass of DatabaseError.
0072    """
0073
0074class InternalError(DatabaseError):
0075    """
0076    Exception raised when the database encounters an internal
0077    error, e.g. the cursor is not valid anymore, the
0078    transaction is out of sync, etc.  It must be a subclass of
0079    DatabaseError.
0080    """
0081
0082class ProgrammingError(DatabaseError):
0083    """
0084    Exception raised for programming errors, e.g. table not
0085    found or already exists, syntax error in the SQL
0086    statement, wrong number of parameters specified, etc.  It
0087    must be a subclass of DatabaseError.
0088    """
0089
0090class NotSupportedError(DatabaseError):
0091    """
0092    Exception raised in case a method or database API was used
0093    which is not supported by the database, e.g. requesting a
0094    .rollback() on a connection that does not support
0095    transaction or has transactions turned off.  It must be a
0096    subclass of DatabaseError.
0097    """
0098
0099def _insert_base(exc, base):
0100    exc.__bases__ = exc.__bases__ + (base,)
0101
0102def install_exception_hierarchy(db_mod):
0103    """
0104    This takes the given DB-API compliant module, and makes sure that
0105    the exceptions inherit from the exceptions defined here.
0106    """
0107    _insert_base(db_mod.Warning, Warning)
0108    _insert_base(db_mod.Error, Error)
0109    _insert_base(db_mod.InterfaceError, InterfaceError)
0110    _insert_base(db_mod.DatabaseError, DatabaseError)
0111    _insert_base(db_mod.DataError, DataError)
0112    _insert_base(db_mod.OperationalError, OperationalError)
0113    _insert_base(db_mod.IntegrityError, IntegrityError)
0114    _insert_base(db_mod.InternalError, InternalError)
0115    _insert_base(db_mod.ProgrammingError, ProgrammingError)
0116    _insert_base(db_mod.NotSupportedError, NotSupportedError)