PageRenderTime 25ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 0ms

/HLI_ExomeseqQC_optimized/pymodules/python2.7/lib/python/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/exc.py

https://gitlab.com/pooja043/Globus_Docker_4
Python | 367 lines | 273 code | 30 blank | 64 comment | 2 complexity | 563f83df763e3e7bf39943be626c4743 MD5 | raw file
  1. # sqlalchemy/exc.py
  2. # Copyright (C) 2005-2014 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: http://www.opensource.org/licenses/mit-license.php
  7. """Exceptions used with SQLAlchemy.
  8. The base exception class is :exc:`.SQLAlchemyError`. Exceptions which are
  9. raised as a result of DBAPI exceptions are all subclasses of
  10. :exc:`.DBAPIError`.
  11. """
  12. import traceback
  13. class SQLAlchemyError(Exception):
  14. """Generic error class."""
  15. class ArgumentError(SQLAlchemyError):
  16. """Raised when an invalid or conflicting function argument is supplied.
  17. This error generally corresponds to construction time state errors.
  18. """
  19. class NoSuchModuleError(ArgumentError):
  20. """Raised when a dynamically-loaded module (usually a database dialect)
  21. of a particular name cannot be located."""
  22. class NoForeignKeysError(ArgumentError):
  23. """Raised when no foreign keys can be located between two selectables
  24. during a join."""
  25. class AmbiguousForeignKeysError(ArgumentError):
  26. """Raised when more than one foreign key matching can be located
  27. between two selectables during a join."""
  28. class CircularDependencyError(SQLAlchemyError):
  29. """Raised by topological sorts when a circular dependency is detected.
  30. There are two scenarios where this error occurs:
  31. * In a Session flush operation, if two objects are mutually dependent
  32. on each other, they can not be inserted or deleted via INSERT or
  33. DELETE statements alone; an UPDATE will be needed to post-associate
  34. or pre-deassociate one of the foreign key constrained values.
  35. The ``post_update`` flag described at :ref:`post_update` can resolve
  36. this cycle.
  37. * In a :meth:`.MetaData.create_all`, :meth:`.MetaData.drop_all`,
  38. :attr:`.MetaData.sorted_tables` operation, two :class:`.ForeignKey`
  39. or :class:`.ForeignKeyConstraint` objects mutually refer to each
  40. other. Apply the ``use_alter=True`` flag to one or both,
  41. see :ref:`use_alter`.
  42. """
  43. def __init__(self, message, cycles, edges, msg=None):
  44. if msg is None:
  45. message += " Cycles: %r all edges: %r" % (cycles, edges)
  46. else:
  47. message = msg
  48. SQLAlchemyError.__init__(self, message)
  49. self.cycles = cycles
  50. self.edges = edges
  51. def __reduce__(self):
  52. return self.__class__, (None, self.cycles,
  53. self.edges, self.args[0])
  54. class CompileError(SQLAlchemyError):
  55. """Raised when an error occurs during SQL compilation"""
  56. class UnsupportedCompilationError(CompileError):
  57. """Raised when an operation is not supported by the given compiler.
  58. .. versionadded:: 0.8.3
  59. """
  60. def __init__(self, compiler, element_type):
  61. super(UnsupportedCompilationError, self).__init__(
  62. "Compiler %r can't render element of type %s" %
  63. (compiler, element_type))
  64. class IdentifierError(SQLAlchemyError):
  65. """Raised when a schema name is beyond the max character limit"""
  66. class DisconnectionError(SQLAlchemyError):
  67. """A disconnect is detected on a raw DB-API connection.
  68. This error is raised and consumed internally by a connection pool. It can
  69. be raised by the :meth:`.PoolEvents.checkout` event so that the host pool
  70. forces a retry; the exception will be caught three times in a row before
  71. the pool gives up and raises :class:`~sqlalchemy.exc.InvalidRequestError`
  72. regarding the connection attempt.
  73. """
  74. class TimeoutError(SQLAlchemyError):
  75. """Raised when a connection pool times out on getting a connection."""
  76. class InvalidRequestError(SQLAlchemyError):
  77. """SQLAlchemy was asked to do something it can't do.
  78. This error generally corresponds to runtime state errors.
  79. """
  80. class NoInspectionAvailable(InvalidRequestError):
  81. """A subject passed to :func:`sqlalchemy.inspection.inspect` produced
  82. no context for inspection."""
  83. class ResourceClosedError(InvalidRequestError):
  84. """An operation was requested from a connection, cursor, or other
  85. object that's in a closed state."""
  86. class NoSuchColumnError(KeyError, InvalidRequestError):
  87. """A nonexistent column is requested from a ``RowProxy``."""
  88. class NoReferenceError(InvalidRequestError):
  89. """Raised by ``ForeignKey`` to indicate a reference cannot be resolved."""
  90. class NoReferencedTableError(NoReferenceError):
  91. """Raised by ``ForeignKey`` when the referred ``Table`` cannot be
  92. located.
  93. """
  94. def __init__(self, message, tname):
  95. NoReferenceError.__init__(self, message)
  96. self.table_name = tname
  97. def __reduce__(self):
  98. return self.__class__, (self.args[0], self.table_name)
  99. class NoReferencedColumnError(NoReferenceError):
  100. """Raised by ``ForeignKey`` when the referred ``Column`` cannot be
  101. located.
  102. """
  103. def __init__(self, message, tname, cname):
  104. NoReferenceError.__init__(self, message)
  105. self.table_name = tname
  106. self.column_name = cname
  107. def __reduce__(self):
  108. return self.__class__, (self.args[0], self.table_name,
  109. self.column_name)
  110. class NoSuchTableError(InvalidRequestError):
  111. """Table does not exist or is not visible to a connection."""
  112. class UnboundExecutionError(InvalidRequestError):
  113. """SQL was attempted without a database connection to execute it on."""
  114. class DontWrapMixin(object):
  115. """A mixin class which, when applied to a user-defined Exception class,
  116. will not be wrapped inside of :exc:`.StatementError` if the error is
  117. emitted within the process of executing a statement.
  118. E.g.::
  119. from sqlalchemy.exc import DontWrapMixin
  120. class MyCustomException(Exception, DontWrapMixin):
  121. pass
  122. class MySpecialType(TypeDecorator):
  123. impl = String
  124. def process_bind_param(self, value, dialect):
  125. if value == 'invalid':
  126. raise MyCustomException("invalid!")
  127. """
  128. # Moved to orm.exc; compatibility definition installed by orm import until 0.6
  129. UnmappedColumnError = None
  130. class StatementError(SQLAlchemyError):
  131. """An error occurred during execution of a SQL statement.
  132. :class:`StatementError` wraps the exception raised
  133. during execution, and features :attr:`.statement`
  134. and :attr:`.params` attributes which supply context regarding
  135. the specifics of the statement which had an issue.
  136. The wrapped exception object is available in
  137. the :attr:`.orig` attribute.
  138. """
  139. statement = None
  140. """The string SQL statement being invoked when this exception occurred."""
  141. params = None
  142. """The parameter list being used when this exception occurred."""
  143. orig = None
  144. """The DBAPI exception object."""
  145. def __init__(self, message, statement, params, orig):
  146. SQLAlchemyError.__init__(self, message)
  147. self.statement = statement
  148. self.params = params
  149. self.orig = orig
  150. self.detail = []
  151. def add_detail(self, msg):
  152. self.detail.append(msg)
  153. def __reduce__(self):
  154. return self.__class__, (self.args[0], self.statement,
  155. self.params, self.orig)
  156. def __str__(self):
  157. from sqlalchemy.sql import util
  158. params_repr = util._repr_params(self.params, 10)
  159. return ' '.join([
  160. "(%s)" % det for det in self.detail
  161. ] + [
  162. SQLAlchemyError.__str__(self),
  163. repr(self.statement), repr(params_repr)
  164. ])
  165. def __unicode__(self):
  166. return self.__str__()
  167. class DBAPIError(StatementError):
  168. """Raised when the execution of a database operation fails.
  169. Wraps exceptions raised by the DB-API underlying the
  170. database operation. Driver-specific implementations of the standard
  171. DB-API exception types are wrapped by matching sub-types of SQLAlchemy's
  172. :class:`DBAPIError` when possible. DB-API's ``Error`` type maps to
  173. :class:`DBAPIError` in SQLAlchemy, otherwise the names are identical. Note
  174. that there is no guarantee that different DB-API implementations will
  175. raise the same exception type for any given error condition.
  176. :class:`DBAPIError` features :attr:`~.StatementError.statement`
  177. and :attr:`~.StatementError.params` attributes which supply context
  178. regarding the specifics of the statement which had an issue, for the
  179. typical case when the error was raised within the context of
  180. emitting a SQL statement.
  181. The wrapped exception object is available in the
  182. :attr:`~.StatementError.orig` attribute. Its type and properties are
  183. DB-API implementation specific.
  184. """
  185. @classmethod
  186. def instance(cls, statement, params,
  187. orig, dbapi_base_err,
  188. connection_invalidated=False):
  189. # Don't ever wrap these, just return them directly as if
  190. # DBAPIError didn't exist.
  191. if isinstance(orig, (KeyboardInterrupt, SystemExit, DontWrapMixin)):
  192. return orig
  193. if orig is not None:
  194. # not a DBAPI error, statement is present.
  195. # raise a StatementError
  196. if not isinstance(orig, dbapi_base_err) and statement:
  197. msg = traceback.format_exception_only(
  198. orig.__class__, orig)[-1].strip()
  199. return StatementError(
  200. "%s (original cause: %s)" % (str(orig), msg),
  201. statement, params, orig
  202. )
  203. name, glob = orig.__class__.__name__, globals()
  204. if name in glob and issubclass(glob[name], DBAPIError):
  205. cls = glob[name]
  206. return cls(statement, params, orig, connection_invalidated)
  207. def __reduce__(self):
  208. return self.__class__, (self.statement, self.params,
  209. self.orig, self.connection_invalidated)
  210. def __init__(self, statement, params, orig, connection_invalidated=False):
  211. try:
  212. text = str(orig)
  213. except (KeyboardInterrupt, SystemExit):
  214. raise
  215. except Exception as e:
  216. text = 'Error in str() of DB-API-generated exception: ' + str(e)
  217. StatementError.__init__(
  218. self,
  219. '(%s) %s' % (orig.__class__.__name__, text),
  220. statement,
  221. params,
  222. orig
  223. )
  224. self.connection_invalidated = connection_invalidated
  225. class InterfaceError(DBAPIError):
  226. """Wraps a DB-API InterfaceError."""
  227. class DatabaseError(DBAPIError):
  228. """Wraps a DB-API DatabaseError."""
  229. class DataError(DatabaseError):
  230. """Wraps a DB-API DataError."""
  231. class OperationalError(DatabaseError):
  232. """Wraps a DB-API OperationalError."""
  233. class IntegrityError(DatabaseError):
  234. """Wraps a DB-API IntegrityError."""
  235. class InternalError(DatabaseError):
  236. """Wraps a DB-API InternalError."""
  237. class ProgrammingError(DatabaseError):
  238. """Wraps a DB-API ProgrammingError."""
  239. class NotSupportedError(DatabaseError):
  240. """Wraps a DB-API NotSupportedError."""
  241. # Warnings
  242. class SADeprecationWarning(DeprecationWarning):
  243. """Issued once per usage of a deprecated API."""
  244. class SAPendingDeprecationWarning(PendingDeprecationWarning):
  245. """Issued once per usage of a deprecated API."""
  246. class SAWarning(RuntimeWarning):
  247. """Issued at runtime."""