Fix none_ok for RegexList and PercList.
This commit is contained in:
parent
23583b7d48
commit
c46abd8f89
@ -445,10 +445,17 @@ class PercList(List):
|
|||||||
self.maxval = maxval
|
self.maxval = maxval
|
||||||
|
|
||||||
def transform(self, value):
|
def transform(self, value):
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
vals = super().transform(value)
|
vals = super().transform(value)
|
||||||
return [int(v[:-1]) if v is not None else None for v in vals]
|
return [int(v[:-1]) if v is not None else None for v in vals]
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
|
if not value:
|
||||||
|
if self.none_ok:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise configexc.ValidationError(value, "may not be empty")
|
||||||
vals = super().transform(value)
|
vals = super().transform(value)
|
||||||
perctype = Perc(minval=self.minval, maxval=self.maxval)
|
perctype = Perc(minval=self.minval, maxval=self.maxval)
|
||||||
try:
|
try:
|
||||||
@ -786,11 +793,18 @@ class RegexList(List):
|
|||||||
self.flags = flags
|
self.flags = flags
|
||||||
|
|
||||||
def transform(self, value):
|
def transform(self, value):
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
vals = super().transform(value)
|
vals = super().transform(value)
|
||||||
return [re.compile(v, self.flags) if v is not None else None
|
return [re.compile(v, self.flags) if v is not None else None
|
||||||
for v in vals]
|
for v in vals]
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
|
if not value:
|
||||||
|
if self.none_ok:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise configexc.ValidationError(value, "may not be empty!")
|
||||||
try:
|
try:
|
||||||
vals = self.transform(value)
|
vals = self.transform(value)
|
||||||
except sre_constants.error as e:
|
except sre_constants.error as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user