No Description
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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #-*- coding: utf-8 -*-
  2. ## @package lodel.settings.utils Lodel 2 settings utility
  3. #
  4. # For now 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 multiple SettingsError
  25. class SettingsErrors(Exception):
  26. ##@brief Instanciate a SettingsErrors
  27. # @param exception 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. ## @brief Return a string representation of a list of SettingError
  35. # This representation is the concatenation of all SettingError string representations
  36. def __str__(self):
  37. res = "Errors :\n"
  38. for expt in self.__exceptions:
  39. res += "\t%s\n" % str(expt)
  40. return res