提交 8dc5e358 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Make the config parser stricter on valid option parameters

上级 5573bd40
...@@ -171,12 +171,16 @@ class ConfigParam(object): ...@@ -171,12 +171,16 @@ class ConfigParam(object):
So the value should be the same during all the execution So the value should be the same during all the execution
""" """
self.default = default self.default = default
self.filter=filter self.filter = filter
self.allow_override = allow_override self.allow_override = allow_override
# N.B. -- # N.B. --
# self.fullname # set by AddConfigVar # self.fullname # set by AddConfigVar
# self.doc # set by AddConfigVar # self.doc # set by AddConfigVar
# Check that default is a valid value
if self.filter:
self.filter(self.default)
def __get__(self, *args): def __get__(self, *args):
#print "GETTING PARAM", self.fullname, self, args #print "GETTING PARAM", self.fullname, self, args
if not hasattr(self, 'val'): if not hasattr(self, 'val'):
...@@ -203,6 +207,13 @@ class EnumStr(ConfigParam): ...@@ -203,6 +207,13 @@ class EnumStr(ConfigParam):
def __init__(self, default, *options, **kwargs): def __init__(self, default, *options, **kwargs):
self.default = default self.default = default
self.all = (default,) + options self.all = (default,) + options
# All options should be strings
for val in self.all:
if not isinstance(val, str):
raise ValueError('Valid values for an EnumStr parameter '
'should be strings', val, type(val))
def filter(val): def filter(val):
if val in self.all: if val in self.all:
return val return val
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论