Use strings for Perc configtypes
This commit is contained in:
parent
e6275ab561
commit
500ad8b00f
@ -549,24 +549,19 @@ class Perc(_Numeric):
|
|||||||
|
|
||||||
"""A percentage, as a string ending with %."""
|
"""A percentage, as a string ending with %."""
|
||||||
|
|
||||||
def from_str(self, value):
|
def from_py(self, value):
|
||||||
|
self._basic_validation(value, pytype=str)
|
||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
elif not value.endswith('%'):
|
|
||||||
raise configexc.ValidationError(value, "does not end with %")
|
|
||||||
|
|
||||||
|
if not value.endswith('%'):
|
||||||
|
raise configexc.ValidationError(value, "does not end with %")
|
||||||
try:
|
try:
|
||||||
floatval = float(value[:-1])
|
floatval = float(value[:-1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise configexc.ValidationError(value, "must be a percentage!")
|
raise configexc.ValidationError(value, "must be a percentage!")
|
||||||
return self.from_py(floatval)
|
self._validate_bounds(floatval, suffix='%')
|
||||||
|
return floatval
|
||||||
def from_py(self, value):
|
|
||||||
self._basic_validation(value, pytype=float)
|
|
||||||
if not value:
|
|
||||||
return None
|
|
||||||
self._validate_bounds(value, suffix='%')
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
class PercOrInt(_Numeric):
|
class PercOrInt(_Numeric):
|
||||||
|
Loading…
Reference in New Issue
Block a user