diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-10-23 20:05:53 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-10-23 20:05:53 +0300 |
commit | 73d35dcaea977162c9ef5b193ad8470ae8244a48 (patch) | |
tree | 9cb05896cfcbc855802fa31549a808a22fa4aea9 /optinterpreter.py | |
parent | 7e05457edbaa4dff0dc35594844dcce4b79ec41c (diff) | |
download | meson-73d35dcaea977162c9ef5b193ad8470ae8244a48.zip meson-73d35dcaea977162c9ef5b193ad8470ae8244a48.tar.gz meson-73d35dcaea977162c9ef5b193ad8470ae8244a48.tar.bz2 |
Validate option values on all assignments.
Diffstat (limited to 'optinterpreter.py')
-rw-r--r-- | optinterpreter.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/optinterpreter.py b/optinterpreter.py index 0b87e04..154b5fe 100644 --- a/optinterpreter.py +++ b/optinterpreter.py @@ -28,16 +28,22 @@ class UserOption: class UserStringOption(UserOption): def __init__(self, kwargs): super().__init__(kwargs) - self.value = kwargs.get('value', '') - if not isinstance(self.value, str): + self.set_value(kwargs.get('value', '')) + + def set_value(self, newvalue): + if not isinstance(newvalue, str): raise OptionException('Value of string option is not a string.') + self.value = newvalue class UserBooleanOption(UserOption): def __init__(self, kwargs): super().__init__(kwargs) - self.value = kwargs.get('value', 'true') - if not isinstance(self.value, bool): + self.set_value(kwargs.get('value', 'true')) + + def set_value(self, newvalue): + if not isinstance(newvalue, bool): raise OptionException('Value of boolean option is not boolean.') + self.value = newvalue class UserComboOption(UserOption): def __init__(self, kwargs): @@ -51,8 +57,11 @@ class UserComboOption(UserOption): if not isinstance(i, str): raise OptionException('Combo choice elements must be strings.') self.value = kwargs.get('value', self.choices[0]) - if self.value not in self.choices: + + def set_value(self, newvalue): + if newvalue not in self.choices: raise OptionException('Combo value must be one of the choices.') + self.value = newvalue option_types = {'string' : UserStringOption, 'boolean' : UserBooleanOption, |