mathmaker
0.4(alpha)
|
00001 # -*- coding: utf-8 -*- 00002 00003 # Mathmaker creates automatically maths exercises sheets 00004 # with their answers 00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net> 00006 00007 # This file is part of Mathmaker. 00008 00009 # Mathmaker is free software; you can redistribute it and/or modify 00010 # it under the terms of the GNU General Public License as published by 00011 # the Free Software Foundation; either version 3 of the License, or 00012 # any later version. 00013 00014 # Mathmaker is distributed in the hope that it will be useful, 00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 # GNU General Public License for more details. 00018 00019 # You should have received a copy of the GNU General Public License 00020 # along with Mathmaker; if not, write to the Free Software 00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 # ------------------------------------------------------------------------------ 00024 # -------------------------------------------------------------------------- 00025 # ------------------------------------------------------------------------------ 00026 ## 00027 # @package error 00028 # @brief This contains all exceptions used by this software. 00029 00030 import os 00031 import sys 00032 sdt_err_output = sys.stderr.fileno() 00033 00034 00035 00036 00037 00038 # -------------------------------------------------------------------------- 00039 ## 00040 # @brief Writes a warning to stderr with the given String as explanation 00041 # @param provided_string The explanation accompanying the warning 00042 def write_warning(provided_string): 00043 os.write(sdt_err_output, "Warning : " + provided_string + "\n") 00044 00045 00046 00047 00048 00049 # ------------------------------------------------------------------------------ 00050 # -------------------------------------------------------------------------- 00051 # ------------------------------------------------------------------------------ 00052 ## 00053 # @exception UnreachableData 00054 # @brief Raised if a searched for data can't be found. 00055 class UnreachableData(Exception): 00056 def __init__(self, data): 00057 self.data = data 00058 00059 00060 00061 00062 00063 def __str__(self): 00064 return "Can't find : " + str(self.data) 00065 00066 00067 00068 00069 00070 00071 # ------------------------------------------------------------------------------ 00072 # -------------------------------------------------------------------------- 00073 # ------------------------------------------------------------------------------ 00074 ## 00075 # @exception MethodShouldBeRedefined 00076 # @brief Raised if one tries to use a method that should have been redefined. 00077 class MethodShouldBeRedefined(Exception): 00078 def __init__(self, objct, method): 00079 self.objct = objct 00080 self.method = method 00081 00082 00083 00084 00085 00086 def __str__(self): 00087 return "The method " + str(self.method) \ 00088 + " has just been called by this type of object " \ 00089 + str(type(self.objct)) \ 00090 + " that should have redefined it in order to use it." 00091 00092 00093 00094 00095 00096 00097 00098 # ------------------------------------------------------------------------------ 00099 # -------------------------------------------------------------------------- 00100 # ------------------------------------------------------------------------------ 00101 ## 00102 # @exception NotImplementedYet 00103 # @brief Raised if one tries to use a portion of code that is not written yet. 00104 class NotImplementedYet(Exception): 00105 def __init__(self, method): 00106 self.method = method 00107 00108 00109 00110 00111 00112 def __str__(self): 00113 return "The method " + str(self.method) \ 00114 + " must handle with a case that is not implemented yet !" 00115 00116 00117 00118 00119 00120 00121 00122 # ------------------------------------------------------------------------------ 00123 # -------------------------------------------------------------------------- 00124 # ------------------------------------------------------------------------------ 00125 ## 00126 # @exception NotInstanciableObject 00127 # @brief Raised if one tries to instanciate a non instanciable object. 00128 class NotInstanciableObject(Exception): 00129 def __init__(self, objct): 00130 self.objct = objct 00131 00132 00133 00134 00135 00136 def __str__(self): 00137 return "It is not allowed to instanciate this type of objects : " \ 00138 + str(type(self.objet)) 00139 00140 00141 00142 00143 00144 # ------------------------------------------------------------------------------ 00145 # -------------------------------------------------------------------------- 00146 # ------------------------------------------------------------------------------ 00147 ## 00148 # @exception OutOfRangeArgument 00149 # @brief Raised if the value of an argument is out of the expected range. 00150 class OutOfRangeArgument(Exception): 00151 def __init__(self, objct, expected_range): 00152 self.objct = objct 00153 self.expected_range = expected_range 00154 00155 00156 00157 00158 00159 def __str__(self): 00160 return "\nValue of the given argument is out " \ 00161 + "of expected range or values : " \ 00162 + str(self.objct) \ 00163 + ".\nExpected range is : " \ 00164 + str(self.expected_range) 00165 00166 00167 00168 00169 00170 # ------------------------------------------------------------------------------ 00171 # -------------------------------------------------------------------------- 00172 # ------------------------------------------------------------------------------ 00173 ## 00174 # @exception UncompatibleObjects 00175 # @brief Raised if one tries to manage two objects in a unconvenient way 00176 # For example if you try to add an Equation and a Number 00177 class UncompatibleObjects(Exception): 00178 def __init__(self, objct1, objct2, given_action, expected_result): 00179 self.objct1 = objct1 00180 self.objct2 = objct2 00181 self.given_action = given_action 00182 self.expected_result = self.expected_result 00183 00184 00185 00186 00187 def __str__(self): 00188 return "The following action is attempted : " + str(self.given_action)\ 00189 + " on " + str(self.objct1) \ 00190 + " and " + str(self.objct2) \ 00191 + " and expects this result : " + str(self.expected_result) 00192 00193 00194 00195 00196 00197 # ------------------------------------------------------------------------------ 00198 # -------------------------------------------------------------------------- 00199 # ------------------------------------------------------------------------------ 00200 ## 00201 # @exception UncompatibleType 00202 # @brief Raised if an object isn't from the expected type. 00203 class UncompatibleType(Exception): 00204 def __init__(self, objct, possible_types): 00205 self.objct = objct 00206 self.possible_types = possible_types 00207 00208 00209 00210 00211 00212 def __str__(self): 00213 return "One tries to use an object from unexpected type : " \ 00214 + str(type(self.objct)) \ 00215 + ". Usable types here are : " \ 00216 + str(self.possible_types) 00217 00218 00219 00220 00221 00222 # ------------------------------------------------------------------------------ 00223 # -------------------------------------------------------------------------- 00224 # ------------------------------------------------------------------------------ 00225 ## 00226 # @exception UncompatibleOptions 00227 # @brief Raised if two options are used together when it's not desired 00228 class UncompatibleOptions(Exception): 00229 def __init__(self, opt1, opt2): 00230 self.opt1 = opt1 00231 self.opt2 = opt2 00232 00233 00234 00235 00236 00237 def __str__(self): 00238 return "One tries to use these two uncompatible options : #1: " \ 00239 + str(self.opt1) \ 00240 + " and #2: " \ 00241 + str(self.opt2) 00242 00243 00244 00245 00246 00247 # ------------------------------------------------------------------------------ 00248 # -------------------------------------------------------------------------- 00249 # ------------------------------------------------------------------------------ 00250 ## 00251 # @exception UnknownOutputFormat 00252 # @brief Raised if the given format isn't available yet. 00253 class UnknownOutputFormat(Exception): 00254 def __init__(self, given_format): 00255 self.given_format = given_format 00256 00257 00258 00259 00260 00261 def __str__(self): 00262 return str(self.given_format) + " isn't available yet." 00263 00264 00265 00266 00267 00268 # ------------------------------------------------------------------------------ 00269 # -------------------------------------------------------------------------- 00270 # ------------------------------------------------------------------------------ 00271 ## 00272 # @exception ArgumentNeeded 00273 # @brief Raised if an argument was expected. 00274 class ArgumentNeeded(Exception): 00275 def __init__(self, data): 00276 self.data = data 00277 00278 00279 00280 00281 00282 def __str__(self): 00283 return "Expected : " + str(self.data) 00284 00285 00286 00287 00288 00289 00290 # ------------------------------------------------------------------------------ 00291 # -------------------------------------------------------------------------- 00292 # ------------------------------------------------------------------------------ 00293 ## 00294 # @exception ImpossibleAction 00295 # @brief Raised if the programm is asked something impossible. 00296 class ImpossibleAction(Exception): 00297 def __init__(self, data): 00298 self.data = data 00299 00300 00301 00302 00303 00304 def __str__(self): 00305 return "Impossible to " + str(self.data) 00306 00307 00308 00309 00310 00311 # ------------------------------------------------------------------------------ 00312 # -------------------------------------------------------------------------- 00313 # ------------------------------------------------------------------------------ 00314 ## 00315 # @exception WrongObject 00316 # @brief Raised if an error in an object has been found. 00317 class WrongObject(Exception): 00318 def __init__(self, data): 00319 self.data = data 00320 00321 00322 00323 00324 00325 def __str__(self): 00326 return "Cause of the error : " + str(self.data) 00327 00328 00329 00330 # ------------------------------------------------------------------------------ 00331 # -------------------------------------------------------------------------- 00332 # ------------------------------------------------------------------------------ 00333 ## 00334 # @exception WrongArgument 00335 # @brief Raised if a given argument doesn't match what was expected. 00336 class WrongArgument(Exception): 00337 def __init__(self, given_arg, expected_arg): 00338 self.given_arg = given_arg 00339 self.expected_arg = expected_arg 00340 00341 00342 00343 00344 00345 def __str__(self): 00346 return "This kind of argument was given : " + str(self.given_arg) \ 00347 + "\nbut this argument was expected : " + str(self.expected_arg) 00348 00349 00350 00351