mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/lib/error.py
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, bytes("Warning : " + provided_string + "\n",
00044                                    'utf-8')
00045             )
00046 
00047 
00048 
00049 
00050 
00051 # ------------------------------------------------------------------------------
00052 # --------------------------------------------------------------------------
00053 # ------------------------------------------------------------------------------
00054 ##
00055 # @exception UnreachableData
00056 # @brief Raised if a searched for data can't be found.
00057 class UnreachableData(Exception):
00058     def __init__(self, data):
00059         self.data = data
00060 
00061 
00062 
00063 
00064 
00065     def __str__(self):
00066         return "Can't find : " + str(self.data)
00067 
00068 
00069 
00070 
00071 
00072 
00073 # ------------------------------------------------------------------------------
00074 # --------------------------------------------------------------------------
00075 # ------------------------------------------------------------------------------
00076 ##
00077 # @exception MethodShouldBeRedefined
00078 # @brief Raised if one tries to use a method that should have been redefined.
00079 class MethodShouldBeRedefined(Exception):
00080     def __init__(self, objct, method):
00081         self.objct = objct
00082         self.method = method
00083 
00084 
00085 
00086 
00087 
00088     def __str__(self):
00089         return "The method " + str(self.method)                              \
00090                + " has just been called by this type of object "              \
00091                + str(type(self.objct)) \
00092                + " that should have redefined it in order to use it."
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 # ------------------------------------------------------------------------------
00101 # --------------------------------------------------------------------------
00102 # ------------------------------------------------------------------------------
00103 ##
00104 # @exception NotImplementedYet
00105 # @brief Raised if one tries to use a portion of code that is not written yet.
00106 class NotImplementedYet(Exception):
00107     def __init__(self, method):
00108         self.method = method
00109 
00110 
00111 
00112 
00113 
00114     def __str__(self):
00115         return "The method " + str(self.method)                              \
00116                + " must handle with a case that is not implemented yet !"
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 # ------------------------------------------------------------------------------
00125 # --------------------------------------------------------------------------
00126 # ------------------------------------------------------------------------------
00127 ##
00128 # @exception NotInstanciableObject
00129 # @brief Raised if one tries to instanciate a non instanciable object.
00130 class NotInstanciableObject(Exception):
00131     def __init__(self, objct):
00132         self.objct = objct
00133 
00134 
00135 
00136 
00137 
00138     def __str__(self):
00139         return "It is not allowed to instanciate this type of objects : "     \
00140                + str(type(self.objet))
00141 
00142 
00143 
00144 
00145 
00146 # ------------------------------------------------------------------------------
00147 # --------------------------------------------------------------------------
00148 # ------------------------------------------------------------------------------
00149 ##
00150 # @exception OutOfRangeArgument
00151 # @brief Raised if the value of an argument is out of the expected range.
00152 class OutOfRangeArgument(Exception):
00153     def __init__(self, objct, expected_range):
00154         self.objct = objct
00155         self.expected_range = expected_range
00156 
00157 
00158 
00159 
00160 
00161     def __str__(self):
00162         return "\nValue of the given argument is out " \
00163                + "of expected range or values : "      \
00164                + str(self.objct)                                        \
00165                + ".\nExpected range is : "                                    \
00166                + str(self.expected_range)
00167 
00168 
00169 
00170 
00171 
00172 # ------------------------------------------------------------------------------
00173 # --------------------------------------------------------------------------
00174 # ------------------------------------------------------------------------------
00175 ##
00176 # @exception UncompatibleObjects
00177 # @brief Raised if one tries to manage two objects in a unconvenient way
00178 # For example if you try to add an Equation and a Number
00179 class UncompatibleObjects(Exception):
00180     def __init__(self, objct1, objct2, given_action, expected_result):
00181         self.objct1 = objct1
00182         self.objct2 = objct2
00183         self.given_action = given_action
00184         self.expected_result = self.expected_result
00185 
00186 
00187 
00188 
00189     def __str__(self):
00190         return "The following action is attempted : " + str(self.given_action)\
00191                + " on " + str(self.objct1)                                    \
00192                + " and " + str(self.objct2)                                   \
00193                + " and expects this result : " + str(self.expected_result)
00194 
00195 
00196 
00197 
00198 
00199 # ------------------------------------------------------------------------------
00200 # --------------------------------------------------------------------------
00201 # ------------------------------------------------------------------------------
00202 ##
00203 # @exception UncompatibleType
00204 # @brief Raised if an object isn't from the expected type.
00205 class UncompatibleType(Exception):
00206     def __init__(self, objct, possible_types):
00207         self.objct = objct
00208         self.possible_types = possible_types
00209 
00210 
00211 
00212 
00213 
00214     def __str__(self):
00215         return "One tries to use an object from unexpected type : "           \
00216                + str(type(self.objct))                                        \
00217                + ". Usable types here are : "                                 \
00218                + str(self.possible_types)
00219 
00220 
00221 
00222 
00223 
00224 # ------------------------------------------------------------------------------
00225 # --------------------------------------------------------------------------
00226 # ------------------------------------------------------------------------------
00227 ##
00228 # @exception UncompatibleOptions
00229 # @brief Raised if two options are used together when it's not desired
00230 class UncompatibleOptions(Exception):
00231     def __init__(self, opt1, opt2):
00232         self.opt1 = opt1
00233         self.opt2 = opt2
00234 
00235 
00236 
00237 
00238 
00239     def __str__(self):
00240         return "One tries to use these two uncompatible options : #1: "      \
00241                + str(self.opt1)                                        \
00242                + " and #2: "                                 \
00243                + str(self.opt2)
00244 
00245 
00246 
00247 
00248 
00249 # ------------------------------------------------------------------------------
00250 # --------------------------------------------------------------------------
00251 # ------------------------------------------------------------------------------
00252 ##
00253 # @exception UnknownOutputFormat
00254 # @brief Raised if the given format isn't available yet.
00255 class UnknownOutputFormat(Exception):
00256     def __init__(self, given_format):
00257         self.given_format = given_format
00258 
00259 
00260 
00261 
00262 
00263     def __str__(self):
00264         return str(self.given_format) + " isn't available yet."
00265 
00266 
00267 
00268 
00269 
00270 # ------------------------------------------------------------------------------
00271 # --------------------------------------------------------------------------
00272 # ------------------------------------------------------------------------------
00273 ##
00274 # @exception ArgumentNeeded
00275 # @brief Raised if an argument was expected.
00276 class ArgumentNeeded(Exception):
00277     def __init__(self, data):
00278         self.data = data
00279 
00280 
00281 
00282 
00283 
00284     def __str__(self):
00285         return "Expected : " + str(self.data)
00286 
00287 
00288 
00289 
00290 
00291 
00292 # ------------------------------------------------------------------------------
00293 # --------------------------------------------------------------------------
00294 # ------------------------------------------------------------------------------
00295 ##
00296 # @exception ImpossibleAction
00297 # @brief Raised if the programm is asked something impossible.
00298 class ImpossibleAction(Exception):
00299     def __init__(self, data):
00300         self.data = data
00301 
00302 
00303 
00304 
00305 
00306     def __str__(self):
00307         return "Impossible to " + str(self.data)
00308 
00309 
00310 
00311 
00312 
00313 # ------------------------------------------------------------------------------
00314 # --------------------------------------------------------------------------
00315 # ------------------------------------------------------------------------------
00316 ##
00317 # @exception WrongObject
00318 # @brief Raised if an error in an object has been found.
00319 class WrongObject(Exception):
00320     def __init__(self, data):
00321         self.data = data
00322 
00323 
00324 
00325 
00326 
00327     def __str__(self):
00328         return "Cause of the error : " + str(self.data)
00329 
00330 
00331 
00332 # ------------------------------------------------------------------------------
00333 # --------------------------------------------------------------------------
00334 # ------------------------------------------------------------------------------
00335 ##
00336 # @exception WrongArgument
00337 # @brief Raised if a given argument doesn't match what was expected.
00338 class WrongArgument(Exception):
00339     def __init__(self, given_arg, expected_arg):
00340         self.given_arg = given_arg
00341         self.expected_arg = expected_arg
00342 
00343 
00344 
00345 
00346 
00347     def __str__(self):
00348         return "This kind of argument was given : " + str(self.given_arg) \
00349                 + "\nbut this argument was expected : " + str(self.expected_arg)
00350 
00351 
00352 
00353