From 53b5ed2178bec143d3dced71a36cc9112e1149bf Mon Sep 17 00:00:00 2001 From: nir0s Date: Wed, 11 Feb 2015 22:24:06 +0200 Subject: [PATCH 1/3] fixed string formatting in utils --- docker/utils/utils.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index fdaf6679..1a41571d 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -163,11 +163,11 @@ def convert_volume_binds(binds): result = [] for k, v in binds.items(): if isinstance(v, dict): - result.append('%s:%s:%s' % ( + result.append('{0}:{1}:{2}'.format( k, v['bind'], 'ro' if v.get('ro', False) else 'rw' )) else: - result.append('%s:%s:rw' % (k, v)) + result.append('{0}:{1}:rw'.format(k, v)) return result @@ -201,7 +201,8 @@ def parse_host(addr): addr = addr.replace('http+unix://', 'unix://') if addr == 'tcp://': - raise errors.DockerException("Invalid bind address format: %s" % addr) + raise errors.DockerException( + "Invalid bind address format: {0}".format(addr)) elif addr.startswith('unix://'): addr = addr[7:] elif addr.startswith('tcp://'): @@ -215,7 +216,7 @@ def parse_host(addr): else: if "://" in addr: raise errors.DockerException( - "Invalid bind address protocol: %s" % addr + "Invalid bind address protocol: {0]".format(addr) ) proto = "http" @@ -223,7 +224,7 @@ def parse_host(addr): host_parts = addr.split(':') if len(host_parts) != 2: raise errors.DockerException( - "Invalid bind address format: %s" % addr + "Invalid bind address format: {0}".format(addr) ) if host_parts[0]: host = host_parts[0] @@ -236,13 +237,14 @@ def parse_host(addr): ) elif proto in ("http", "https") and ':' not in addr: - raise errors.DockerException("Bind address needs a port: %s" % addr) + raise errors.DockerException( + "Bind address needs a port: {0}".format(addr)) else: host = addr if proto == "http+unix": - return "%s://%s" % (proto, host) - return "%s://%s:%d" % (proto, host, port) + return "{0}://{1}".format(proto, host) + return "{0}://{1}:{2}" % (proto, host, port) def parse_devices(devices): From ea2148ade16215fe82318450f7f9a90d39c97c6c Mon Sep 17 00:00:00 2001 From: nir0s Date: Wed, 11 Feb 2015 22:26:23 +0200 Subject: [PATCH 2/3] fixes --- docker/utils/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 1a41571d..fd76d31e 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -216,7 +216,7 @@ def parse_host(addr): else: if "://" in addr: raise errors.DockerException( - "Invalid bind address protocol: {0]".format(addr) + "Invalid bind address protocol: {0}".format(addr) ) proto = "http" @@ -244,7 +244,7 @@ def parse_host(addr): if proto == "http+unix": return "{0}://{1}".format(proto, host) - return "{0}://{1}:{2}" % (proto, host, port) + return "{0}://{1}:{2}".format(proto, host, port) def parse_devices(devices): From dd1a6fc9061eb4c74fd984ec6a8ab1c940229e4c Mon Sep 17 00:00:00 2001 From: nir0s Date: Wed, 11 Feb 2015 22:27:53 +0200 Subject: [PATCH 3/3] fixed string formatting in errors --- docker/errors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/errors.py b/docker/errors.py index 69246c9f..fb9cb5a6 100644 --- a/docker/errors.py +++ b/docker/errors.py @@ -30,15 +30,15 @@ class APIError(requests.exceptions.HTTPError): message = super(APIError, self).__str__() if self.is_client_error(): - message = '%s Client Error: %s' % ( + message = '{0} Client Error: {1}'.format( self.response.status_code, self.response.reason) elif self.is_server_error(): - message = '%s Server Error: %s' % ( + message = '{0} Server Error: {1}'.format( self.response.status_code, self.response.reason) if self.explanation: - message = '%s ("%s")' % (message, self.explanation) + message = '{0} ("{1}")'.format(message, self.explanation) return message