Package wtf :: Package ext :: Package db :: Module _exceptions
[hide private]
[frames] | no frames]

Source Code for Module wtf.ext.db._exceptions

  1  # -*- coding: ascii -*- 
  2  # 
  3  # Copyright 2010-2012 
  4  # Andr\xe9 Malo or his licensors, as applicable 
  5  # 
  6  # Licensed under the Apache License, Version 2.0 (the "License"); 
  7  # you may not use this file except in compliance with the License. 
  8  # You may obtain a copy of the License at 
  9  # 
 10  #     http://www.apache.org/licenses/LICENSE-2.0 
 11  # 
 12  # Unless required by applicable law or agreed to in writing, software 
 13  # distributed under the License is distributed on an "AS IS" BASIS, 
 14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 15  # See the License for the specific language governing permissions and 
 16  # limitations under the License. 
 17  """ 
 18  =============== 
 19   DB Exceptions 
 20  =============== 
 21   
 22  DB Exceptions. 
 23  """ 
 24  __author__ = u"Andr\xe9 Malo" 
 25  __docformat__ = "restructuredtext en" 
 26  __all__ = [ 
 27      'DBError', 
 28      'DBConfigurationError', 
 29      'DBAPIError', 
 30   
 31      'InterfaceError', 
 32      'DatabaseError', 
 33      'DataError', 
 34      'OperationalError', 
 35      'IntegrityError', 
 36      'InternalError', 
 37      'ProgrammingError', 
 38      'NotSupportedError', 
 39  ] 
 40   
 41  import sys as _sys 
 42   
 43  from wtf import Error 
 44   
 45   
46 -class DBError(Error):
47 """ Base DB exception """
48
49 -class DBConfigurationError(Error):
50 """ DB configuration error """
51
52 -class DBAPIError(DBError):
53 """ DB API Error """
54
55 -class InterfaceError(DBAPIError):
56 """ Interface error """
57
58 -class DatabaseError(DBAPIError):
59 """ Database error """
60
61 -class DataError(DatabaseError):
62 """ Data error """
63
64 -class OperationalError(DatabaseError):
65 """ Operational error """
66
67 -class IntegrityError(DatabaseError):
68 """ Integrity error """
69
70 -class InternalError(DatabaseError):
71 """ Internal error """
72
73 -class ProgrammingError(DatabaseError):
74 """ Programming error """
75
76 -class NotSupportedError(DatabaseError):
77 """ Not supported error """
78 79
80 -def translate(adapter):
81 """ 82 Translate exception to wtf.ext DBAPI exception 83 84 The new exception is raised. 85 86 :Parameters: 87 `adapter` : ``module`` 88 DBAPI module 89 90 :Warning: This is a private function. Use 91 ``wtf.ext.db.driver(dbname).translate_exception()``. 92 """ 93 e = _sys.exc_info() 94 try: 95 try: 96 raise 97 except adapter.NotSupportedError: 98 raise NotSupportedError, e[1], e[2] 99 except adapter.ProgrammingError: 100 raise ProgrammingError, e[1], e[2] 101 except adapter.InternalError: 102 raise InternalError, e[1], e[2] 103 except adapter.IntegrityError: 104 raise IntegrityError, e[1], e[2] 105 except adapter.OperationalError: 106 raise OperationalError, e[1], e[2] 107 except adapter.DataError: 108 raise DataError, e[1], e[2] 109 except adapter.DatabaseError: 110 raise DatabaseError, e[1], e[2] 111 except adapter.InterfaceError: 112 raise InterfaceError, e[1], e[2] 113 except adapter.Error: 114 raise DBAPIError, e[1], e[2] 115 finally: 116 del e
117