bugfix: strtol didn't worked correctly with 1 digit numbers

This commit is contained in:
Alexander Kukushkin
2016-07-01 16:19:57 +02:00
parent dc27a30800
commit bc9aec9076
+9 -1
View File
@@ -81,14 +81,20 @@ def parse_bool(value):
def strtol(value, strict=True):
"""As most as possible close equivalent of strtol(3) function (with base=0),
used by postgres to parse parameter values.
>>> strtol(0) == (0, '')
True
>>> strtol(1) == (1, '')
True
>>> strtol(9) == (9, '')
True
>>> strtol(' +0x400MB') == (1024, 'MB')
True
>>> strtol(' -070d') == (-56, 'd')
True
>>> strtol(' d ') == (None, 'd')
True
>>> strtol('9s', False) == (9, 's')
True
>>> strtol(' s ', False) == (1, 's')
True
"""
@@ -112,7 +118,7 @@ def strtol(value, strict=True):
base = 10
ret = None
while i < l:
while i <= l:
try: # try to find maximally long number
i += 1 # by giving to `int` longer and longer strings
ret = long(value[:i], base)
@@ -137,6 +143,8 @@ def parse_int(value, base_unit=None):
True
>>> parse_int('1GB', 'MB') is None
True
>>> parse_int(0) == 0
True
"""
convert = {