diff options
Diffstat (limited to 'docker/utils/utils.py')
-rw-r--r-- | docker/utils/utils.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 03b4c35..e95829a 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -460,6 +460,12 @@ def datetime_to_timestamp(dt): return delta.seconds + delta.days * 24 * 3600 +def longint(n): + if six.PY3: + return int(n) + return long(n) + + def parse_bytes(s): if len(s) == 0: s = 0 @@ -480,14 +486,20 @@ def parse_bytes(s): if suffix in units.keys() or suffix.isdigit(): try: - digits = int(digits_part) + # Don't introduce floating point errors if the user specified + # an integer value. + if '.' in digits_part: + digits = float(digits_part) + else: + digits = longint(digits_part) except ValueError: message = ('Failed converting the string value for' 'memory ({0}) to a number.') formatted_message = message.format(digits_part) raise errors.DockerException(formatted_message) - s = digits * units[suffix] + # Reconvert to long for the final result + s = longint(digits * units[suffix]) else: message = ('The specified value for memory' ' ({0}) should specify the units. The postfix' |