conftypes: Use slicing instead of rstrip.

"100%%".rstrip('%') would give use "100" instead of "100%" which is not what we
want.
This commit is contained in:
Florian Bruhin 2014-08-05 13:04:34 +02:00
parent f414a0bf4b
commit 8402aa051a

View File

@ -377,9 +377,9 @@ class Perc(BaseType):
self.maxval = maxval self.maxval = maxval
def transform(self, value): def transform(self, value):
return int(value.rstrip('%'))
if self.none_ok and not value: if self.none_ok and not value:
return return
return int(value[:-1])
def validate(self, value): def validate(self, value):
if not value: if not value:
@ -390,7 +390,7 @@ class Perc(BaseType):
if not value.endswith('%'): if not value.endswith('%'):
raise ValidationError(value, "does not end with %") raise ValidationError(value, "does not end with %")
try: try:
intval = int(value.rstrip('%')) intval = int(value[:-1])
except ValueError: except ValueError:
raise ValidationError(value, "invalid percentage!") raise ValidationError(value, "invalid percentage!")
if self.minval is not None and intval < self.minval: if self.minval is not None and intval < self.minval:
@ -472,7 +472,7 @@ class PercOrInt(BaseType):
return return
if value.endswith('%'): if value.endswith('%'):
try: try:
intval = int(value.rstrip('%')) intval = int(value[:-1])
except ValueError: except ValueError:
raise ValidationError(value, "invalid percentage!") raise ValidationError(value, "invalid percentage!")
if self.minperc is not None and intval < self.minperc: if self.minperc is not None and intval < self.minperc: