1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-11-02 04:20:55 +01:00
lodel2_mirror/lodel/settings/utils.py
Roland Haroutiounian 1849ddd48e Docstring
2016-07-08 16:37:07 +02:00

49 lines
1.5 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#-*- coding: utf-8 -*-
## @package lodel.settings.utils Lodel 2 settings utility
#
# For the moment defines exception classes
##@brief Error class for settings errors
class SettingsError(Exception):
##@brief Instanciate a new SettingsError
# @param msg str : Error message
# @param key_id str : The key concerned by the error
# @param filename str
def __init__(self, msg = "Unknown error", key_id = None, filename = None):
self.__msg = msg
self.__key_id = key_id
self.__filename = filename
def __repr__(self): return str(self)
def __str__(self):
res = "Error "
if self.__filename is not None:
res += "in file '%s' " % self.__filename
if self.__key_id is not None:
res += "for key '%s'" % self.__key_id
res += ": %s" % (self.__msg)
return res
##@brief Designed to handles mutliple SettingsError
class SettingsErrors(Exception):
##@brief Instanciate an SettingsErrors
# @param exceptions list : list of SettingsError instance
def __init__(self, exceptions):
for expt in exceptions:
if not isinstance(expt, SettingsError):
raise ValueError("The 'exceptions' argument has to be an array of <class SettingsError>, but a %s was found in the list" % type(expt))
self.__exceptions = exceptions
def __repr__(self): return str(self)
def __str__(self):
res = "Errors :\n"
for expt in self.__exceptions:
res += "\t%s\n" % str(expt)
return res