PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Python/Lib/site-packages/pypm/external/2/sqlalchemy/exc.py

https://gitlab.com/orvi2014/rcs-db-ext
Python | 200 lines | 149 code | 18 blank | 33 comment | 0 complexity | ba902f395eced7b493a5abd7c21b0473 MD5 | raw file
  1. # sqlalchemy/exc.py
  2. # Copyright (C) 2005-2011 the SQLAlchemy authors and contributors <see AUTHORS file>
  3. #
  4. # This module is part of SQLAlchemy and is released under
  5. # the MIT License: http://www.opensource.org/licenses/mit-license.php
  6. """Exceptions used with SQLAlchemy.
  7. The base exception class is :class:`.SQLAlchemyError`. Exceptions which are raised as a
  8. result of DBAPI exceptions are all subclasses of
  9. :class:`.DBAPIError`.
  10. """
  11. class SQLAlchemyError(Exception):
  12. """Generic error class."""
  13. class ArgumentError(SQLAlchemyError):
  14. """Raised when an invalid or conflicting function argument is supplied.
  15. This error generally corresponds to construction time state errors.
  16. """
  17. class CircularDependencyError(SQLAlchemyError):
  18. """Raised by topological sorts when a circular dependency is detected"""
  19. def __init__(self, message, cycles, edges):
  20. message += ": cycles: %r all edges: %r" % (cycles, edges)
  21. SQLAlchemyError.__init__(self, message)
  22. self.cycles = cycles
  23. self.edges = edges
  24. class CompileError(SQLAlchemyError):
  25. """Raised when an error occurs during SQL compilation"""
  26. class IdentifierError(SQLAlchemyError):
  27. """Raised when a schema name is beyond the max character limit"""
  28. # Moved to orm.exc; compatability definition installed by orm import until 0.6
  29. ConcurrentModificationError = None
  30. class DisconnectionError(SQLAlchemyError):
  31. """A disconnect is detected on a raw DB-API connection.
  32. This error is raised and consumed internally by a connection pool. It can
  33. be raised by a ``PoolListener`` so that the host pool forces a disconnect.
  34. """
  35. # Moved to orm.exc; compatability definition installed by orm import until 0.6
  36. FlushError = None
  37. class TimeoutError(SQLAlchemyError):
  38. """Raised when a connection pool times out on getting a connection."""
  39. class InvalidRequestError(SQLAlchemyError):
  40. """SQLAlchemy was asked to do something it can't do.
  41. This error generally corresponds to runtime state errors.
  42. """
  43. class ResourceClosedError(InvalidRequestError):
  44. """An operation was requested from a connection, cursor, or other
  45. object that's in a closed state."""
  46. class NoSuchColumnError(KeyError, InvalidRequestError):
  47. """A nonexistent column is requested from a ``RowProxy``."""
  48. class NoReferenceError(InvalidRequestError):
  49. """Raised by ``ForeignKey`` to indicate a reference cannot be resolved."""
  50. class NoReferencedTableError(NoReferenceError):
  51. """Raised by ``ForeignKey`` when the referred ``Table`` cannot be located."""
  52. class NoReferencedColumnError(NoReferenceError):
  53. """Raised by ``ForeignKey`` when the referred ``Column`` cannot be located."""
  54. class NoSuchTableError(InvalidRequestError):
  55. """Table does not exist or is not visible to a connection."""
  56. class UnboundExecutionError(InvalidRequestError):
  57. """SQL was attempted without a database connection to execute it on."""
  58. # Moved to orm.exc; compatability definition installed by orm import until 0.6
  59. UnmappedColumnError = None
  60. class DBAPIError(SQLAlchemyError):
  61. """Raised when the execution of a database operation fails.
  62. ``DBAPIError`` wraps exceptions raised by the DB-API underlying the
  63. database operation. Driver-specific implementations of the standard
  64. DB-API exception types are wrapped by matching sub-types of SQLAlchemy's
  65. ``DBAPIError`` when possible. DB-API's ``Error`` type maps to
  66. ``DBAPIError`` in SQLAlchemy, otherwise the names are identical. Note
  67. that there is no guarantee that different DB-API implementations will
  68. raise the same exception type for any given error condition.
  69. If the error-raising operation occured in the execution of a SQL
  70. statement, that statement and its parameters will be available on
  71. the exception object in the ``statement`` and ``params`` attributes.
  72. The wrapped exception object is available in the ``orig`` attribute.
  73. Its type and properties are DB-API implementation specific.
  74. """
  75. @classmethod
  76. def instance(cls, statement, params, orig, connection_invalidated=False):
  77. # Don't ever wrap these, just return them directly as if
  78. # DBAPIError didn't exist.
  79. if isinstance(orig, (KeyboardInterrupt, SystemExit)):
  80. return orig
  81. if orig is not None:
  82. name, glob = orig.__class__.__name__, globals()
  83. if name in glob and issubclass(glob[name], DBAPIError):
  84. cls = glob[name]
  85. return cls(statement, params, orig, connection_invalidated)
  86. def __init__(self, statement, params, orig, connection_invalidated=False):
  87. try:
  88. text = str(orig)
  89. except (KeyboardInterrupt, SystemExit):
  90. raise
  91. except Exception, e:
  92. text = 'Error in str() of DB-API-generated exception: ' + str(e)
  93. SQLAlchemyError.__init__(
  94. self, '(%s) %s' % (orig.__class__.__name__, text))
  95. self.statement = statement
  96. self.params = params
  97. self.orig = orig
  98. self.connection_invalidated = connection_invalidated
  99. def __str__(self):
  100. if isinstance(self.params, (list, tuple)) and len(self.params) > 10 and isinstance(self.params[0], (list, dict, tuple)):
  101. return ' '.join((SQLAlchemyError.__str__(self),
  102. repr(self.statement),
  103. repr(self.params[:2]),
  104. '... and a total of %i bound parameter sets' % len(self.params)))
  105. return ' '.join((SQLAlchemyError.__str__(self),
  106. repr(self.statement), repr(self.params)))
  107. # As of 0.4, SQLError is now DBAPIError.
  108. # SQLError alias will be removed in 0.6.
  109. SQLError = DBAPIError
  110. class InterfaceError(DBAPIError):
  111. """Wraps a DB-API InterfaceError."""
  112. class DatabaseError(DBAPIError):
  113. """Wraps a DB-API DatabaseError."""
  114. class DataError(DatabaseError):
  115. """Wraps a DB-API DataError."""
  116. class OperationalError(DatabaseError):
  117. """Wraps a DB-API OperationalError."""
  118. class IntegrityError(DatabaseError):
  119. """Wraps a DB-API IntegrityError."""
  120. class InternalError(DatabaseError):
  121. """Wraps a DB-API InternalError."""
  122. class ProgrammingError(DatabaseError):
  123. """Wraps a DB-API ProgrammingError."""
  124. class NotSupportedError(DatabaseError):
  125. """Wraps a DB-API NotSupportedError."""
  126. # Warnings
  127. class SADeprecationWarning(DeprecationWarning):
  128. """Issued once per usage of a deprecated API."""
  129. class SAPendingDeprecationWarning(PendingDeprecationWarning):
  130. """Issued once per usage of a deprecated API."""
  131. class SAWarning(RuntimeWarning):
  132. """Issued at runtime."""