Package orm2 :: Module exceptions
[hide private]
[frames] | no frames]

Source Code for Module orm2.exceptions

  1  #!/usr/bin/env python 
  2  # -*- coding: iso-8859-1 -*- 
  3   
  4  ##  This file is part of orm, The Object Relational Membrane Version 2. 
  5  ## 
  6  ##  Copyright 2002-2006 by Diedrich Vorberg <diedrich@tux4web.de> 
  7  ## 
  8  ##  All Rights Reserved 
  9  ## 
 10  ##  For more Information on orm see the README file. 
 11  ## 
 12  ##  This program is free software; you can redistribute it and/or modify 
 13  ##  it under the terms of the GNU General Public License as published by 
 14  ##  the Free Software Foundation; either version 2 of the License, or 
 15  ##  (at your option) any later version. 
 16  ## 
 17  ##  This program is distributed in the hope that it will be useful, 
 18  ##  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 19  ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 20  ##  GNU General Public License for more details. 
 21  ## 
 22  ##  You should have received a copy of the GNU General Public License 
 23  ##  along with this program; if not, write to the Free Software 
 24  ##  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 25  ## 
 26  ##  I have added a copy of the GPL in the file gpl.txt 
 27   
 28  # Changelog 
 29  # --------- 
 30  # 
 31  # $Log: exceptions.py,v $ 
 32  # Revision 1.16  2007/07/04 09:47:17  diedrich 
 33  # Added PasswordsDontMatch. 
 34  # 
 35  # Revision 1.15  2006/07/08 17:07:51  diedrich 
 36  # Added DateValidatorException 
 37  # 
 38  # Revision 1.14  2006/07/05 21:40:08  diedrich 
 39  # Added NotEmptyError and ReValidatorError 
 40  # 
 41  # Revision 1.13  2006/06/09 09:05:08  diedrich 
 42  # Added InternalError exception 
 43  # 
 44  # Revision 1.12  2006/05/13 17:23:42  diedrich 
 45  # Massive docstring update. 
 46  # 
 47  # Revision 1.11  2006/05/10 21:55:10  diedrich 
 48  # Added IllegalConnectionString exception 
 49  # 
 50  # Revision 1.10  2006/04/28 09:49:27  diedrich 
 51  # Docstring updates for epydoc 
 52  # 
 53  # Revision 1.9  2006/04/28 08:43:02  diedrich 
 54  # Added NotNullError, RangeValidatorError and LengthValidatorException 
 55  # 
 56  # Revision 1.8  2006/04/21 18:54:22  diedrich 
 57  # Added validator exceptions 
 58  # 
 59  # Revision 1.7  2006/02/25 17:59:55  diedrich 
 60  # Made the many2one work with multi column keys. 
 61  # 
 62  # Revision 1.6  2006/02/25 00:20:20  diedrich 
 63  # - Added and tested the ability to use multiple column primary keys. 
 64  # - Some small misc bugs. 
 65  # 
 66  # Revision 1.5  2006/01/01 20:42:20  diedrich 
 67  # Added ObjectMustBeInserted, DatatypeMustBeUsedInClassDefinition and 
 68  # NoDbPropertyByThatName. 
 69  # 
 70  # Revision 1.4  2005/12/31 09:58:42  diedrich 
 71  # - Added PrimaryKeyNotKnown Exception 
 72  # - Moved a number of SQL related Exceptions into that module 
 73  # 
 74  # Revision 1.3  2005/12/18 22:35:46  diedrich 
 75  # - Inheritance 
 76  # - pgsql adapter 
 77  # - first unit tests 
 78  # - some more comments 
 79  # 
 80  # Revision 1.2  2005/11/21 19:59:35  diedrich 
 81  # Added ObjectAlreadyInserted and DBObjContainsNoData 
 82  # 
 83  # Revision 1.1.1.1  2005/11/20 14:55:46  diedrich 
 84  # Initial import 
 85  # 
 86  # 
 87  # 
 88   
 89  """ 
 90  orm2 comes with a whole bunch of exception classes, collected in this module. 
 91  """ 
 92   
93 -class ORMException(Exception):
94 """ 95 Base class for all of orm's exceptions 96 """
97
98 -class InternalError(Exception):
99 """ 100 Something inside orm has gone wrong. 101 """
102
103 -class IllegalConnectionString(ORMException):
104 """ 105 This exception indicates a syntax error in a connection string 106 """
107
108 -class NoSuchAttributeOrColumn(ORMException):
109 """ 110 Er... someone used an dbproperty that doesn't exist 111 """
112
113 -class NoPrimaryKey(ORMException):
114 """ 115 This error is raised if a class does not have a primary key 116 (__primary_key__ == None) but some function requires a primary key. 117 """
118
119 -class ObjectMustBeInserted(ORMException):
120 """ 121 To perform the requested operation, the object must have been stored 122 in the database. 123 """
124
125 -class ObjectAlreadyInserted(ORMException):
126 """ 127 Relationships may require dbobjects not to have been inserted into 128 the database prior to handling them. Also, you can't insert an object 129 into a table with a AUTO_INCREMENT column (or simmilar), that has the 130 corresponding attribute set already. 131 """ 132
133 -class DBObjContainsNoData(ORMException):
134 """ 135 This exception is raised if a dbobj wants to be inserted that has 136 none of its attributes set. If you want an empty tuple to be 137 inserted to the database (to be filled with default values by the 138 backend, for instance) you have to set at least one of the 139 db-attributes to None. 140 """
141
142 -class PrimaryKeyNotKnown(ORMException):
143 """ 144 This exception is raised when the select after insert mechanism is 145 invoked on an object of which the primary key is not known and cannot 146 be determined through the backend. 147 """
148
149 -class BackendError(ORMException):
150 """ 151 The backend had something to complain 152 """
153 154
155 -class DatatypeMustBeUsedInClassDefinition(ORMException):
156 """ 157 Most datatypes need to be part of the class definition and cannot 158 be added later. 159 """
160
161 -class NoDbPropertyByThatName(ORMException):
162 """ 163 Raised by dbobject.__dbproperty__. 164 """
165
166 -class SimplePrimaryKeyNeeded(ORMException):
167 """ 168 Raised if some function expects a single column primary key but a 169 multi column primary key is provided. 170 """
171
172 -class KeyNotSet(ORMException):
173 """ 174 Raised if a key is not set or not set completely (that is, all of 175 its columns) 176 """
177
178 -class IllegalForeignKey(ORMException):
179 """ 180 Raised if a foreign key attribute or set of attributes doesn't match 181 the attributes in the other dbclass. 182 """
183
184 -class ValidatorException(ORMException):
185 """ 186 Parentclass for all those exceptions raised by validators. Those 187 exceptions must always contain the dbobj, dbproperty and value 188 that caused the exception along with a plausible error message(! ;-) 189 This is ment to aid debugging and the creation of even more specific 190 error message than a generic validator could contain. (The idea is that 191 the message stored in the exception is an error for the programmer, 192 the error message for the user will be created from those values). 193 """
194 - def __init__(self, message, dbobj, dbproperty, value):
195 """ 196 @param message: String(!) error message that goes into the regular 197 exception object. This is intended for programmers (see above) and 198 thus should be generic and in English. 199 @param dbobj: The dbobject whoes property was supposed to be set 200 @param dbproperty: The actual dbproperty that was supposed to be set 201 @param value: A Python object (as opposed to a repr()) of the value 202 the dbproperty was supposed to be set to 203 """ 204 ORMException.__init__(self, message) 205 self.dbobj = dbobj 206 self.dbproperty = dbproperty 207 self.value = value
208 209
210 -class NotNullError(ValidatorException):
211 """ 212 Raised by the not_null_validator 213 """
214
215 -class NotEmptyError(ValidatorException):
216 """ 217 Raised by the not_empty_validator 218 """
219
220 -class RangeValidatorError(ValidatorException):
221 """ 222 Raised by range_check_validator 223 """
224
225 -class LengthValidatorException(ValidatorException):
226 """ 227 Raised by length_validator 228 """
229
230 -class ReValidatorException(ValidatorException):
231 - def __init__(self, msg, dbobj, dbproperty, re, value):
232 """ 233 @param re: The regular expression which has not been matched. 234 """ 235 ValidatorException.__init__(self, msg, dbobj, dbproperty, value) 236 self.re = re
237
238 -class DateValidatorException(ValidatorException):
239 - def __init__(self, msg, dbobj, dbproperty, value, format):
240 """ 241 @param format: Date format string as for strftime()/strptime() 242 """ 243 ValidatorException.__init__(self, msg, dbobj, dbproperty, value) 244 self.format = format
245
246 -class PasswordsDontMatch(ORMException):
247 pass
248