Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #-*- coding: utf-8 -*-
  2. ## @package lodel.settings.utils Lodel 2 settings utility
  3. #
  4. # For the moment defines exception classes
  5. ##@brief Error class for settings errors
  6. class SettingsError(Exception):
  7. ##@brief Instanciate a new SettingsError
  8. # @param msg str : Error message
  9. # @param key_id str : The key concerned by the error
  10. # @param filename str
  11. def __init__(self, msg = "Unknown error", key_id = None, filename = None):
  12. self.__msg = msg
  13. self.__key_id = key_id
  14. self.__filename = filename
  15. def __repr__(self): return str(self)
  16. def __str__(self):
  17. res = "Error "
  18. if self.__filename is not None:
  19. res += "in file '%s' " % self.__filename
  20. if self.__key_id is not None:
  21. res += "for key '%s'" % self.__key_id
  22. res += ": %s" % (self.__msg)
  23. return res
  24. ##@brief Designed to handles mutliple SettingsError
  25. class SettingsErrors(Exception):
  26. ##@brief Instanciate an SettingsErrors
  27. # @param exceptions list : list of SettingsError instance
  28. def __init__(self, exceptions):
  29. for expt in exceptions:
  30. if not isinstance(expt, SettingsError):
  31. raise ValueError("The 'exceptions' argument has to be an array of <class SettingsError>, but a %s was found in the list" % type(expt))
  32. self.__exceptions = exceptions
  33. def __repr__(self): return str(self)
  34. def __str__(self):
  35. res = "Errors :\n"
  36. for expt in self.__exceptions:
  37. res += "\t%s\n" % str(expt)
  38. return res