summaryrefslogtreecommitdiff
path: root/compose/container.py
diff options
context:
space:
mode:
authoralexrecuenco <alejandrogonzalezrecuenco@gmail.com>2020-02-24 13:24:57 +0100
committeralexrecuenco <safale93@gmail.com>2020-08-11 17:45:13 +0700
commit4d3d9f64b965af66662a934fc07af430e83ce524 (patch)
tree2583a452fe4fb13dbf3a2888f9d2bf30acaeeed3 /compose/container.py
parent32a5ea5ac85cdba7a08ac28b999ff402f6f4c316 (diff)
Removed Python2 support
Closes: #6890 Some remarks, - `# coding ... utf-8` statements are not needed - isdigit on strings instead of a try-catch. - Default opening mode is read, so we can do `open()` without the `'r'` everywhere - Removed inheritinng from `object` class, it isn't necessary in python3. - `super(ClassName, self)` can now be replaced with `super()` - Use of itertools and `chain` on a couple places dealing with sets. - Used the operator module instead of lambdas when warranted `itemgetter(0)` instead of `lambda x: x[0]` `attrgetter('name')` instead of `lambda x: x.name` - `sorted` returns a list, so no need to use `list(sorted(...))` - Removed `dict()` using dictionary comprehensions whenever possible - Attempted to remove python3.2 support Signed-off-by: alexrecuenco <alejandrogonzalezrecuenco@gmail.com>
Diffstat (limited to 'compose/container.py')
-rw-r--r--compose/container.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/compose/container.py b/compose/container.py
index 7160a982..00626b61 100644
--- a/compose/container.py
+++ b/compose/container.py
@@ -12,7 +12,7 @@ from .utils import truncate_id
from .version import ComposeVersion
-class Container(object):
+class Container:
"""
Represents a Docker container, constructed from the output of
GET /containers/:id:/json.
@@ -78,8 +78,8 @@ class Container(object):
@property
def name_without_project(self):
- if self.name.startswith('{0}_{1}'.format(self.project, self.service)):
- return '{0}_{1}'.format(self.service, self.number if self.number is not None else self.slug)
+ if self.name.startswith('{}_{}'.format(self.project, self.service)):
+ return '{}_{}'.format(self.service, self.number if self.number is not None else self.slug)
else:
return self.name
@@ -91,7 +91,7 @@ class Container(object):
number = self.labels.get(LABEL_CONTAINER_NUMBER)
if not number:
- raise ValueError("Container {0} does not have a {1} label".format(
+ raise ValueError("Container {} does not have a {} label".format(
self.short_id, LABEL_CONTAINER_NUMBER))
return int(number)
@@ -224,7 +224,7 @@ class Container(object):
return reduce(get_value, key.split('.'), self.dictionary)
def get_local_port(self, port, protocol='tcp'):
- port = self.ports.get("%s/%s" % (port, protocol))
+ port = self.ports.get("{}/{}".format(port, protocol))
return "{HostIp}:{HostPort}".format(**port[0]) if port else None
def get_mount(self, mount_dest):
@@ -266,7 +266,7 @@ class Container(object):
"""
if not self.name.startswith(self.short_id):
self.client.rename(
- self.id, '{0}_{1}'.format(self.short_id, self.name)
+ self.id, '{}_{}'.format(self.short_id, self.name)
)
def inspect_if_not_inspected(self):
@@ -309,7 +309,7 @@ class Container(object):
)
def __repr__(self):
- return '<Container: %s (%s)>' % (self.name, self.id[:6])
+ return '<Container: {} ({})>'.format(self.name, self.id[:6])
def __eq__(self, other):
if type(self) != type(other):