From ed4210a43575f7329780ff6fbb6816f15eebadfa Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Fri, 5 May 2023 10:56:34 +0200 Subject: [PATCH] `pyupgrade --py36-plus` as 3.6 is the minimum supported version Signed-off-by: Simon Deziel --- contrib_testing/local-http-test.py | 10 +++++----- contrib_testing/local-unix-test.py | 10 +++++----- contrib_testing/remote-test.py | 10 +++++----- doc/source/conf.py | 1 - integration/test_cluster_members.py | 2 +- integration/test_containers.py | 4 ++-- integration/test_images.py | 4 ++-- integration/test_networks.py | 6 +++--- integration/test_profiles.py | 4 ++-- integration/test_storage.py | 2 +- integration/testing.py | 4 ++-- migration/test_containers.py | 4 ++-- migration/testing.py | 4 ++-- pylxd/__init__.py | 2 -- pylxd/client.py | 6 +++--- pylxd/deprecated/connection.py | 8 ++++---- pylxd/deprecated/container.py | 14 +++++++------- pylxd/deprecated/exceptions.py | 2 +- pylxd/deprecated/hosts.py | 18 +++++++++--------- pylxd/deprecated/image.py | 26 +++++++++++++------------- pylxd/deprecated/operation.py | 6 +++--- pylxd/deprecated/tests/test_image.py | 4 ++-- pylxd/exceptions.py | 2 +- pylxd/models/_model.py | 4 ++-- pylxd/models/instance.py | 4 ++-- pylxd/models/network.py | 4 ++-- 26 files changed, 81 insertions(+), 84 deletions(-) diff --git a/contrib_testing/local-http-test.py b/contrib_testing/local-http-test.py index 9ddde29e..d3c0bba0 100755 --- a/contrib_testing/local-http-test.py +++ b/contrib_testing/local-http-test.py @@ -13,7 +13,7 @@ def log(s): now = datetime.datetime.utcnow() - print("{} - {}".format(now, s)) + print(f"{now} - {s}") def create_and_update(client): @@ -39,11 +39,11 @@ def create_and_update(client): ["apt-get", "install", "openssh-server", "sudo", "man", "-y"], ] for command in commands: - log("command: {}".format(command)) + log(f"command: {command}") result = base.execute(command) - log("result: {}".format(result.exit_code)) - log("stdout: {}".format(result.stdout)) - log("stderr: {}".format(result.stderr)) + log(f"result: {result.exit_code}") + log(f"stdout: {result.stdout}") + log(f"stderr: {result.stderr}") if __name__ == "__main__": diff --git a/contrib_testing/local-unix-test.py b/contrib_testing/local-unix-test.py index fa291d71..25608ccd 100755 --- a/contrib_testing/local-unix-test.py +++ b/contrib_testing/local-unix-test.py @@ -13,7 +13,7 @@ def log(s): now = datetime.datetime.utcnow() - print("{} - {}".format(now, s)) + print(f"{now} - {s}") def create_and_update(client): @@ -39,11 +39,11 @@ def create_and_update(client): ["apt-get", "install", "openssh-server", "sudo", "man", "-y"], ] for command in commands: - log("command: {}".format(command)) + log(f"command: {command}") result = base.execute(command) - log("result: {}".format(result.exit_code)) - log("stdout: {}".format(result.stdout)) - log("stderr: {}".format(result.stderr)) + log(f"result: {result.exit_code}") + log(f"stdout: {result.stdout}") + log(f"stderr: {result.stderr}") if __name__ == "__main__": diff --git a/contrib_testing/remote-test.py b/contrib_testing/remote-test.py index 5eac5809..a000889e 100755 --- a/contrib_testing/remote-test.py +++ b/contrib_testing/remote-test.py @@ -13,7 +13,7 @@ def log(s): now = datetime.datetime.utcnow() - print("{} - {}".format(now, s)) + print(f"{now} - {s}") def create_and_update(client): @@ -40,11 +40,11 @@ def create_and_update(client): ["apt-get", "install", "openssh-server", "sudo", "man", "-y"], ] for command in commands: - log("command: {}".format(command)) + log(f"command: {command}") result = base.execute(command) - log("result: {}".format(result.exit_code)) - log("stdout: {}".format(result.stdout)) - log("stderr: {}".format(result.stderr)) + log(f"result: {result.exit_code}") + log(f"stdout: {result.stdout}") + log(f"stderr: {result.stderr}") if __name__ == "__main__": diff --git a/doc/source/conf.py b/doc/source/conf.py index b304e819..036c24c3 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/integration/test_cluster_members.py b/integration/test_cluster_members.py index cb132c70..45e54c54 100644 --- a/integration/test_cluster_members.py +++ b/integration/test_cluster_members.py @@ -17,7 +17,7 @@ class ClusterMemberTestCase(IntegrationTestCase): def setUp(self): - super(ClusterMemberTestCase, self).setUp() + super().setUp() if not self.client.has_api_extension("clustering"): self.skipTest("Required LXD API extension not available!") diff --git a/integration/test_containers.py b/integration/test_containers.py index 9563652a..13619c5e 100644 --- a/integration/test_containers.py +++ b/integration/test_containers.py @@ -60,12 +60,12 @@ class TestContainer(IntegrationTestCase): """Tests for Client.Container.""" def setUp(self): - super(TestContainer, self).setUp() + super().setUp() name = self.create_container() self.container = self.client.containers.get(name) def tearDown(self): - super(TestContainer, self).tearDown() + super().tearDown() self.delete_container(self.container.name) def test_save(self): diff --git a/integration/test_images.py b/integration/test_images.py index e2221991..2c1991ce 100644 --- a/integration/test_images.py +++ b/integration/test_images.py @@ -58,12 +58,12 @@ class TestImage(IntegrationTestCase): """Tests for Image.""" def setUp(self): - super(TestImage, self).setUp() + super().setUp() fingerprint, _ = self.create_image() self.image = self.client.images.get(fingerprint) def tearDown(self): - super(TestImage, self).tearDown() + super().tearDown() self.delete_image(self.image.fingerprint) def test_save(self): diff --git a/integration/test_networks.py b/integration/test_networks.py index 359dd6b2..72518545 100644 --- a/integration/test_networks.py +++ b/integration/test_networks.py @@ -18,7 +18,7 @@ class NetworkTestCase(IntegrationTestCase): def setUp(self): - super(NetworkTestCase, self).setUp() + super().setUp() if not self.client.has_api_extension("network"): self.skipTest("Required LXD API extension not available!") @@ -88,12 +88,12 @@ class TestNetwork(NetworkTestCase): """Tests for `Network`.""" def setUp(self): - super(TestNetwork, self).setUp() + super().setUp() name = self.create_network() self.network = self.client.networks.get(name) def tearDown(self): - super(TestNetwork, self).tearDown() + super().tearDown() self.delete_network(self.network.name) def test_save(self): diff --git a/integration/test_profiles.py b/integration/test_profiles.py index 0f3a16f6..49d287f2 100644 --- a/integration/test_profiles.py +++ b/integration/test_profiles.py @@ -51,12 +51,12 @@ class TestProfile(IntegrationTestCase): """Tests for `Profile`.""" def setUp(self): - super(TestProfile, self).setUp() + super().setUp() name = self.create_profile() self.profile = self.client.profiles.get(name) def tearDown(self): - super(TestProfile, self).tearDown() + super().tearDown() self.delete_profile(self.profile.name) def test_save(self): diff --git a/integration/test_storage.py b/integration/test_storage.py index 85ace2e2..9c2978a8 100644 --- a/integration/test_storage.py +++ b/integration/test_storage.py @@ -22,7 +22,7 @@ class StorageTestCase(IntegrationTestCase): def setUp(self): - super(StorageTestCase, self).setUp() + super().setUp() if not self.client.has_api_extension("storage"): self.skipTest("Required LXD API extension not available!") diff --git a/integration/testing.py b/integration/testing.py index 842d627f..118d71e9 100644 --- a/integration/testing.py +++ b/integration/testing.py @@ -25,7 +25,7 @@ class IntegrationTestCase(unittest.TestCase): """A base test case for pylxd integration tests.""" def setUp(self): - super(IntegrationTestCase, self).setUp() + super().setUp() self.client = Client() self.lxd = self.client.api @@ -34,7 +34,7 @@ def generate_object_name(self): # Underscores are not allowed in container names. test = self.id().split(".")[-1].replace("_", "") rando = str(uuid.uuid1()).split("-")[-1] - return "{}-{}".format(test, rando) + return f"{test}-{rando}" def create_container(self): """Create a container in lxd.""" diff --git a/migration/test_containers.py b/migration/test_containers.py index b29a8876..c2dc9cbc 100644 --- a/migration/test_containers.py +++ b/migration/test_containers.py @@ -19,12 +19,12 @@ class TestContainer(IntegrationTestCase): """Tests for Client.Container.""" def setUp(self): - super(TestContainer, self).setUp() + super().setUp() name = self.create_container() self.container = self.client.containers.get(name) def tearDown(self): - super(TestContainer, self).tearDown() + super().tearDown() self.delete_container(self.container.name) def test_migrate_running(self): diff --git a/migration/testing.py b/migration/testing.py index 1052b264..843fd0db 100644 --- a/migration/testing.py +++ b/migration/testing.py @@ -25,7 +25,7 @@ class IntegrationTestCase(unittest.TestCase): """A base test case for pylxd integration tests.""" def setUp(self): - super(IntegrationTestCase, self).setUp() + super().setUp() self.client = Client() self.lxd = self.client.api @@ -34,7 +34,7 @@ def generate_object_name(self): # Underscores are not allowed in container names. test = self.id().split(".")[-1].replace("_", "") rando = str(uuid.uuid1()).split("-")[-1] - return "{}-{}".format(test, rando) + return f"{test}-{rando}" def create_container(self): """Create a container in lxd.""" diff --git a/pylxd/__init__.py b/pylxd/__init__.py index 0f45161e..c86f6ea4 100644 --- a/pylxd/__init__.py +++ b/pylxd/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at diff --git a/pylxd/client.py b/pylxd/client.py index f8817ca3..fd5ef9a1 100644 --- a/pylxd/client.py +++ b/pylxd/client.py @@ -122,7 +122,7 @@ def __getattr__(self, name): if name in ("storage_pools", "virtual_machines"): name = name.replace("_", "-") return self.__class__( - "{}/{}".format(self._api_endpoint, name), + f"{self._api_endpoint}/{name}", session=self.session, timeout=self._timeout, project=self._project, @@ -137,7 +137,7 @@ def __getitem__(self, item): :rtype: _APINode """ return self.__class__( - "{}/{}".format(self._api_endpoint, item), + f"{self._api_endpoint}/{item}", session=self.session, timeout=self._timeout, project=self._project, @@ -543,7 +543,7 @@ def events(self, websocket_client=None, event_types=None): if event_types and EventType.All not in event_types: query = parse.parse_qs(parsed.query) query.update({"type": ",".join(t.value for t in event_types)}) - resource = "{}?{}".format(resource, parse.urlencode(query)) + resource = f"{resource}?{parse.urlencode(query)}" client.resource = resource diff --git a/pylxd/deprecated/connection.py b/pylxd/deprecated/connection.py index 28f6dc36..f39e4a18 100644 --- a/pylxd/deprecated/connection.py +++ b/pylxd/deprecated/connection.py @@ -192,10 +192,10 @@ def get_ws(self, path): if self.unix_socket: connection_string = "ws+unix://%s" % self.unix_socket else: - connection_string = "wss://%(host)s:%(port)s" % { - "host": self.host, - "port": self.port, - } + connection_string = "wss://{host}:{port}".format( + host=self.host, + port=self.port, + ) ws = WebSocketClient(connection_string) ws.resource = path diff --git a/pylxd/deprecated/container.py b/pylxd/deprecated/container.py index 08c697d8..6a05513e 100644 --- a/pylxd/deprecated/container.py +++ b/pylxd/deprecated/container.py @@ -134,7 +134,7 @@ def container_migrate(self, container): def container_migrate_sync(self, operation_id, container_secret): return self.connection.get_ws( - "/1.0/operations/%s/websocket?secret=%s" % (operation_id, container_secret) + "/1.0/operations/{}/websocket?secret={}".format(operation_id, container_secret) ) def container_local_copy(self, container): @@ -150,7 +150,7 @@ def container_local_move(self, instance, config): # file operations def get_container_file(self, container, filename): return self.connection.get_raw( - "GET", "/1.0/containers/%s/files?path=%s" % (container, filename) + "GET", "/1.0/containers/{}/files?path={}".format(container, filename) ) def put_container_file(self, container, src_file, dst_file, uid, gid, mode): @@ -158,7 +158,7 @@ def put_container_file(self, container, src_file, dst_file, uid, gid, mode): data = f.read() return self.connection.get_object( "POST", - "/1.0/containers/%s/files?path=%s" % (container, dst_file), + "/1.0/containers/{}/files?path={}".format(container, dst_file), body=data, headers={"X-LXD-uid": uid, "X-LXD-gid": gid, "X-LXD-mode": mode}, ) @@ -185,7 +185,7 @@ def snapshot_list(self, container): "GET", "/1.0/containers/%s/snapshots" % container ) return [ - snapshot.split("/1.0/containers/%s/snapshots/%s/" % (container, container))[ + snapshot.split("/1.0/containers/{}/snapshots/{}/".format(container, container))[ -1 ] for snapshot in data["metadata"] @@ -198,17 +198,17 @@ def snapshot_create(self, container, config): def snapshot_info(self, container, snapshot): return self.connection.get_object( - "GET", "/1.0/containers/%s/snapshots/%s" % (container, snapshot) + "GET", "/1.0/containers/{}/snapshots/{}".format(container, snapshot) ) def snapshot_rename(self, container, snapshot, config): return self.connection.get_object( "POST", - "/1.0/containers/%s/snapshots/%s" % (container, snapshot), + "/1.0/containers/{}/snapshots/{}".format(container, snapshot), json.dumps(config), ) def snapshot_delete(self, container, snapshot): return self.connection.get_object( - "DELETE", "/1.0/containers/%s/snapshots/%s" % (container, snapshot) + "DELETE", "/1.0/containers/{}/snapshots/{}".format(container, snapshot) ) diff --git a/pylxd/deprecated/exceptions.py b/pylxd/deprecated/exceptions.py index cd6c8848..4f0b385d 100644 --- a/pylxd/deprecated/exceptions.py +++ b/pylxd/deprecated/exceptions.py @@ -39,7 +39,7 @@ class ImageInvalidSize(PyLXDException): class APIError(PyLXDException): def __init__(self, error, status_code): - msg = "Error %s - %s." % (status_code, error) + msg = "Error {} - {}.".format(status_code, error) super().__init__(msg) self.status_code = status_code self.error = error diff --git a/pylxd/deprecated/hosts.py b/pylxd/deprecated/hosts.py index e3d91370..2ff7fd66 100644 --- a/pylxd/deprecated/hosts.py +++ b/pylxd/deprecated/hosts.py @@ -43,7 +43,7 @@ def get_lxd_api_compat(self, data): data = data.get("metadata") return data["api_compat"] except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_lxd_host_trust(self, data): try: @@ -52,7 +52,7 @@ def get_lxd_host_trust(self, data): data = data.get("metadata") return True if data["auth"] == "trusted" else False except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_lxd_backing_fs(self, data): try: @@ -61,7 +61,7 @@ def get_lxd_backing_fs(self, data): data = data.get("metadata") return data["environment"]["backing_fs"] except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_lxd_driver(self, data): try: @@ -70,7 +70,7 @@ def get_lxd_driver(self, data): data = data.get("metadata") return data["environment"]["driver"] except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_lxc_version(self, data): try: @@ -79,7 +79,7 @@ def get_lxc_version(self, data): data = data.get("metadata") return data["environment"]["lxc_version"] except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_lxd_version(self, data): try: @@ -88,7 +88,7 @@ def get_lxd_version(self, data): data = data.get("metadata") return float(data["environment"]["lxd_version"]) except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_kernel_version(self, data): try: @@ -97,7 +97,7 @@ def get_kernel_version(self, data): data = data.get("metadata") return data["environment"]["kernel_version"] except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def get_certificate(self): try: @@ -105,11 +105,11 @@ def get_certificate(self): data = data.get("metadata") return data["environment"]["certificate"] except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") def host_config(self): try: (state, data) = self.connection.get_object("GET", "/1.0") return data.get("metadata") except exceptions.PyLXDException as e: - print("Handling run-time error: {}".format(e)) + print(f"Handling run-time error: {e}") diff --git a/pylxd/deprecated/image.py b/pylxd/deprecated/image.py index b2d3bb16..f3f8d2aa 100644 --- a/pylxd/deprecated/image.py +++ b/pylxd/deprecated/image.py @@ -40,7 +40,7 @@ def image_list(self): (state, data) = self.connection.get_object("GET", "/1.0/images") return [image.split("/1.0/images/")[-1] for image in data["metadata"]] except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise def image_defined(self, image): @@ -61,7 +61,7 @@ def image_list_by_key(self, params): ) return [image.split("/1.0/images/")[-1] for image in data["metadata"]] except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise # image info @@ -90,7 +90,7 @@ def image_info(self, image): return image except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise def get_image_date(self, image, data, key): @@ -107,7 +107,7 @@ def get_image_date(self, image, data, key): else: return "Unknown" except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise def get_image_permission(self, image, data): @@ -119,7 +119,7 @@ def get_image_permission(self, image, data): data = data.get("metadata") return True if data["public"] == 1 else False except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise def get_image_size(self, image, data): @@ -134,7 +134,7 @@ def get_image_size(self, image, data): raise exceptions.ImageInvalidSize() return image_size // 1024**2 except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise def get_image_fingerprint(self, image, data): @@ -146,7 +146,7 @@ def get_image_fingerprint(self, image, data): data = data.get("metadata") return data["fingerprint"] except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise def get_image_architecture(self, image, data): @@ -158,7 +158,7 @@ def get_image_architecture(self, image, data): data = data.get("metadata") return image_architecture[data["architecture"]] except Exception as e: - print("Unable to fetch image info - {}".format(e)) + print(f"Unable to fetch image info - {e}") raise # image operations @@ -167,21 +167,21 @@ def image_upload(self, path=None, data=None, headers={}): try: return self.connection.get_object("POST", "/1.0/images", data, headers) except Exception as e: - print("Unable to upload image - {}".format(e)) + print(f"Unable to upload image - {e}") raise def image_delete(self, image): try: return self.connection.get_status("DELETE", "/1.0/images/%s" % image) except Exception as e: - print("Unable to delete image - {}".format(e)) + print(f"Unable to delete image - {e}") raise def image_export(self, image): try: return self.connection.get_raw("GET", "/1.0/images/%s/export" % image) except Exception as e: - print("Unable to export image - {}".format(e)) + print(f"Unable to export image - {e}") raise def image_update(self, image, data): @@ -190,7 +190,7 @@ def image_update(self, image, data): "PUT", "/1.0/images/%s" % image, json.dumps(data) ) except Exception as e: - print("Unable to update image - {}".format(e)) + print(f"Unable to update image - {e}") raise def image_rename(self, image, data): @@ -199,7 +199,7 @@ def image_rename(self, image, data): "POST", "/1.0/images/%s" % image, json.dumps(data) ) except Exception as e: - print("Unable to rename image - {}".format(e)) + print(f"Unable to rename image - {e}") raise diff --git a/pylxd/deprecated/operation.py b/pylxd/deprecated/operation.py index 916a7e2d..5bb22d3e 100644 --- a/pylxd/deprecated/operation.py +++ b/pylxd/deprecated/operation.py @@ -60,17 +60,17 @@ def operation_status_code(self, operation, data): def operation_wait(self, operation, status_code, timeout): if timeout == -1: return self.connection.get_status( - "GET", "%s/wait?status_code=%s" % (operation, status_code) + "GET", "{}/wait?status_code={}".format(operation, status_code) ) else: return self.connection.get_status( "GET", - "%s/wait?status_code=%s&timeout=%s" % (operation, status_code, timeout), + "{}/wait?status_code={}&timeout={}".format(operation, status_code, timeout), ) def operation_stream(self, operation, operation_secret): return self.connection.get_ws( - "%s/websocket?secret=%s" % (operation, operation_secret) + "{}/websocket?secret={}".format(operation, operation_secret) ) def operation_delete(self, operation): diff --git a/pylxd/deprecated/tests/test_image.py b/pylxd/deprecated/tests/test_image.py index d83fb573..0369139a 100644 --- a/pylxd/deprecated/tests/test_image.py +++ b/pylxd/deprecated/tests/test_image.py @@ -107,7 +107,7 @@ def test_image_info_fail(self, ms): def test_image_date(self, method, expected, ms): self.assertEqual( expected, - getattr(self.lxd, "image_{}_date".format(method))("test-image", data=None), + getattr(self.lxd, f"image_{method}_date")("test-image", data=None), ) ms.assert_called_once_with("GET", "/1.0/images/test-image") @@ -116,7 +116,7 @@ def test_image_date_fail(self, method, expected, ms): ms.side_effect = exceptions.PyLXDException self.assertRaises( exceptions.PyLXDException, - getattr(self.lxd, "image_{}_date".format(method)), + getattr(self.lxd, f"image_{method}_date"), "test-image", data=None, ) diff --git a/pylxd/exceptions.py b/pylxd/exceptions.py index 5a778dd0..54c06822 100644 --- a/pylxd/exceptions.py +++ b/pylxd/exceptions.py @@ -49,7 +49,7 @@ def __init__(self, name, *args, **kwargs): :type name: str """ super().__init__( - "LXD API extension '{}' is not available".format(name), *args, **kwargs + f"LXD API extension '{name}' is not available", *args, **kwargs ) diff --git a/pylxd/models/_model.py b/pylxd/models/_model.py index f2c8260c..a6cbf9e3 100644 --- a/pylxd/models/_model.py +++ b/pylxd/models/_model.py @@ -101,7 +101,7 @@ def __new__(cls, name, bases, attrs): _seen_attribute_warnings = set() -class Model(object, metaclass=ModelType): +class Model(metaclass=ModelType): """A Base LXD object model. Objects fetched from the LXD API have state, which allows @@ -137,7 +137,7 @@ def __init__(self, client, **kwargs): except AttributeError: global _seen_attribute_warnings env = os.environ.get("PYLXD_WARNINGS", "").lower() - item = "{}.{}".format(self.__class__.__name__, key) + item = f"{self.__class__.__name__}.{key}" if env != "always" and item in _seen_attribute_warnings: continue _seen_attribute_warnings.add(item) diff --git a/pylxd/models/instance.py b/pylxd/models/instance.py index ba44c424..404f97e3 100644 --- a/pylxd/models/instance.py +++ b/pylxd/models/instance.py @@ -156,7 +156,7 @@ def _resolve_headers(headers=None, mode=None, uid=None, gid=None): if not isinstance(mode, str): raise ValueError("'mode' parameter must be int or string") if not mode.startswith("0"): - mode = "0{}".format(mode) + mode = f"0{mode}" headers["X-LXD-mode"] = mode if uid is not None: headers["X-LXD-uid"] = str(uid) @@ -861,7 +861,7 @@ def publish(self, public=False, wait=False): "public": public, "source": { "type": "snapshot", - "name": "{}/{}".format(self.instance.name, self.name), + "name": f"{self.instance.name}/{self.name}", }, } diff --git a/pylxd/models/network.py b/pylxd/models/network.py index 245e868e..0bce7e73 100644 --- a/pylxd/models/network.py +++ b/pylxd/models/network.py @@ -52,7 +52,7 @@ def __str__(self): def __repr__(self): attrs = [] for attribute, value in self.marshall().items(): - attrs.append("{}={}".format(attribute, json.dumps(value, sort_keys=True))) + attrs.append(f"{attribute}={json.dumps(value, sort_keys=True)}") return "{}({})".format(self.__class__.__name__, ", ".join(sorted(attrs))) @@ -193,6 +193,6 @@ def __str__(self): def __repr__(self): attrs = [] for attribute, value in self.marshall().items(): - attrs.append("{}={}".format(attribute, json.dumps(value, sort_keys=True))) + attrs.append(f"{attribute}={json.dumps(value, sort_keys=True)}") return "{}({})".format(self.__class__.__name__, ", ".join(sorted(attrs)))