mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-07-29 15:55:47 -05:00
ipalib.parameters: Handle 0-prefixed octal format of ints
In Python 2, numbers prfixed with '0' are parsed as octal, e.g. '020' -> 16. In Python 3, the prefix is '0o'. Handle the old syntax for IPA's parameter conversion to keep backwards compatibility. Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
committed by
Tomas Babej
parent
c44dd40b26
commit
e0eff8b834
@@ -1072,6 +1072,9 @@ class Int(Number):
|
||||
if type(value) is unicode:
|
||||
if u'.' in value:
|
||||
return int(float(value))
|
||||
if six.PY3 and re.match('0[0-9]+', value):
|
||||
# 0-prefixed octal format
|
||||
return int(value, 8)
|
||||
return int(value, 0)
|
||||
|
||||
raise ValueError(value)
|
||||
|
||||
@@ -1195,6 +1195,7 @@ def check_int_scalar_conversions(o):
|
||||
assert o._convert_scalar(u'16') == 16
|
||||
assert o._convert_scalar(u'0x10') == 16
|
||||
assert o._convert_scalar(u'020') == 16
|
||||
assert o._convert_scalar(u'0o20') == 16
|
||||
|
||||
|
||||
class test_IntEnum(EnumChecker):
|
||||
|
||||
Reference in New Issue
Block a user