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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. def __init__(self, msg = "Unknown error", key_id = None, filename = None):
  11. self.__msg = msg
  12. self.__key_id = key_id
  13. self.__filename = filename
  14. def __repr__(self): return str(self)
  15. def __str__(self):
  16. res = "Error "
  17. if self.__filename is not None:
  18. res += "in file '%s' " % self.__filename
  19. if self.__key_id is not None:
  20. res += "for key '%s'" % self.__key_id
  21. res += ": %s" % (self.__msg)
  22. return res
  23. ##@brief Designed to handles mutliple SettingsError
  24. class SettingsErrors(Exception):
  25. ##@brief Instanciate an SettingsErrors
  26. # @param exceptions list : list of SettingsError instance
  27. def __init__(self, exceptions):
  28. for expt in exceptions:
  29. if not isinstance(expt, SettingsError):
  30. raise ValueError("The 'exceptions' argument has to be an array of <class SettingsError>, but a %s was found in the list" % type(expt))
  31. self.__exceptions = exceptions
  32. def __repr__(self): return str(self)
  33. def __str__(self):
  34. res = "Errors :\n"
  35. for expt in self.__exceptions:
  36. res += "\t%s\n" % str(expt)
  37. return res