summaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-12-18 14:37:22 -0800
committerJoffrey F <joffrey@docker.com>2016-01-18 13:53:52 -0800
commitcd66f6c6cdd211653ea9dfa99724e4d193f583ca (patch)
tree1fecdd4cbdeaa55b305fe45c104f51c11173c49a /docker
parent57b79cb1e7edc5226a276f9776ccc2c3fd19c22b (diff)
downloaddocker-py-cd66f6c6cdd211653ea9dfa99724e4d193f583ca.tar.gz
parse_bytes: Add ability to handle 64-bit integers in py2
Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'docker')
-rw-r--r--docker/utils/utils.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index b33c5bd..ab80971 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -486,6 +486,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
@@ -506,20 +512,21 @@ def parse_bytes(s):
if suffix in units.keys() or suffix.isdigit():
try:
- digits = int(digits_part)
+ 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)
+ raise errors.DockerException(
+ 'Failed converting the string value for memory ({0}) to'
+ ' an integer.'.format(digits_part)
+ )
- 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'
- ' should be one of the `b` `k` `m` `g`'
- ' characters')
- raise errors.DockerException(message.format(s))
+ raise errors.DockerException(
+ 'The specified value for memory ({0}) should specify the'
+ ' units. The postfix should be one of the `b` `k` `m` `g`'
+ ' characters'.format(s)
+ )
return s