2013-04-16 22:44:16 +02:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
# Copyright (C) 2012-2013 Team tiramisu (see AUTHORS for all contributors)
|
|
|
|
|
#
|
2013-09-22 22:33:09 +02:00
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
|
# under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
|
# option) any later version.
|
2013-04-16 22:44:16 +02:00
|
|
|
|
#
|
2013-09-22 22:33:09 +02:00
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
|
# details.
|
2013-04-16 22:44:16 +02:00
|
|
|
|
#
|
2013-09-22 22:33:09 +02:00
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-04-16 22:44:16 +02:00
|
|
|
|
# ____________________________________________________________
|
2013-05-23 14:55:52 +02:00
|
|
|
|
"user defined exceptions"
|
2013-08-20 12:08:02 +02:00
|
|
|
|
|
|
|
|
|
|
2013-05-15 17:35:49 +02:00
|
|
|
|
# Exceptions for an Option
|
2013-04-19 20:10:55 +02:00
|
|
|
|
class PropertiesOptionError(AttributeError):
|
2013-05-21 18:42:56 +02:00
|
|
|
|
"attempt to access to an option with a property that is not allowed"
|
2013-04-19 20:10:55 +02:00
|
|
|
|
def __init__(self, msg, proptype):
|
|
|
|
|
self.proptype = proptype
|
|
|
|
|
super(PropertiesOptionError, self).__init__(msg)
|
|
|
|
|
|
|
|
|
|
|
2013-05-15 17:35:49 +02:00
|
|
|
|
#____________________________________________________________
|
|
|
|
|
# Exceptions for a Config
|
2013-08-28 11:33:43 +02:00
|
|
|
|
class ConfigError(Exception):
|
2013-05-15 17:35:49 +02:00
|
|
|
|
"""attempt to change an option's owner without a value
|
|
|
|
|
or in case of `_cfgimpl_descr` is None
|
|
|
|
|
or if a calculation cannot be carried out"""
|
2012-07-13 09:37:35 +02:00
|
|
|
|
pass
|
2013-04-13 22:50:55 +02:00
|
|
|
|
|
|
|
|
|
|
2013-08-28 11:33:43 +02:00
|
|
|
|
class ConflictError(Exception):
|
2013-05-15 17:35:49 +02:00
|
|
|
|
"duplicate options are present in a single config"
|
2012-07-13 09:37:35 +02:00
|
|
|
|
pass
|
2013-04-13 22:50:55 +02:00
|
|
|
|
|
|
|
|
|
|
2013-05-15 17:35:49 +02:00
|
|
|
|
#____________________________________________________________
|
|
|
|
|
# miscellaneous exceptions
|
2013-08-28 11:33:43 +02:00
|
|
|
|
class RequirementError(Exception):
|
2013-05-31 23:29:20 +02:00
|
|
|
|
"""a recursive loop occurs in the requirements tree
|
|
|
|
|
requires
|
|
|
|
|
"""
|
2012-07-26 10:54:57 +02:00
|
|
|
|
pass
|
2013-04-19 20:10:55 +02:00
|
|
|
|
|
|
|
|
|
|
2013-08-28 11:33:43 +02:00
|
|
|
|
class SlaveError(Exception):
|
2013-05-15 17:35:49 +02:00
|
|
|
|
"problem with a slave's value length"
|
2013-04-19 20:10:55 +02:00
|
|
|
|
pass
|
2013-08-26 21:48:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConstError(TypeError):
|
|
|
|
|
"no uniq value in _NameSpace"
|
|
|
|
|
pass
|
2013-09-26 21:56:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Warning
|
|
|
|
|
class ValueWarning(UserWarning):
|
|
|
|
|
"""Option could warn user and not raise ValueError.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
>>> import warnings
|
|
|
|
|
>>> from tiramisu.error import ValueWarning
|
|
|
|
|
>>> from tiramisu.option import StrOption, OptionDescription
|
|
|
|
|
>>> from tiramisu.config import Config
|
|
|
|
|
>>> warnings.simplefilter("always", ValueWarning)
|
|
|
|
|
>>> def a(val):
|
|
|
|
|
... raise ValueError('pouet')
|
|
|
|
|
...
|
2013-09-27 09:52:18 +02:00
|
|
|
|
>>> s=StrOption('s', '', validator=a, warnings_only=True)
|
2013-09-26 21:56:06 +02:00
|
|
|
|
>>> o=OptionDescription('o', '', [s])
|
|
|
|
|
>>> c=Config(o)
|
|
|
|
|
>>> c.s = 'val'
|
|
|
|
|
StrOption:0: ValueWarning: invalid value val for option s: pouet
|
|
|
|
|
>>> with warnings.catch_warnings(record=True) as w:
|
|
|
|
|
... c.s = 'val'
|
|
|
|
|
...
|
|
|
|
|
>>> w[0].message.opt == s
|
|
|
|
|
True
|
|
|
|
|
>>> print str(w[0].message)
|
|
|
|
|
invalid value val for option s: pouet
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, msg, opt):
|
|
|
|
|
self.opt = opt
|
|
|
|
|
super(ValueWarning, self).__init__(msg)
|