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:
Petr Viktorin
2015-09-21 13:29:18 +02:00
committed by Tomas Babej
parent c44dd40b26
commit e0eff8b834
2 changed files with 4 additions and 0 deletions

View File

@@ -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)