diff --git a/patroni/utils.py b/patroni/utils.py index 9c7a9e9d..8b2389f7 100644 --- a/patroni/utils.py +++ b/patroni/utils.py @@ -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 = {