From 667abbc894ef7e634fa0dc4d6393f420eb970eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louisa=20v=2E=20H=C3=BClsen?= Date: Wed, 28 Feb 2024 15:09:49 +0100 Subject: [PATCH] MAINT: Use f-strings --- core/src/zeit/connector/filesystem.py | 6 +++--- core/src/zeit/connector/mock.py | 8 ++++---- core/src/zeit/connector/postgresql.py | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/zeit/connector/filesystem.py b/core/src/zeit/connector/filesystem.py index deffc0dae5..26f8d87eb2 100644 --- a/core/src/zeit/connector/filesystem.py +++ b/core/src/zeit/connector/filesystem.py @@ -228,7 +228,7 @@ def _get_cannonical_id(self, id): def _path(self, id): if not id.startswith(ID_NAMESPACE): - raise ValueError('The id %r is invalid.' % id) + raise ValueError(f'The id {id} is invalid.') path = id.replace(ID_NAMESPACE, '', 1).rstrip('/') return os.path.join(self.repository_path, path).rstrip('/') @@ -239,8 +239,8 @@ def _get_file(self, id): return open(filename, 'rb') except IOError: if os.path.isdir(filename): - raise ValueError('The path %r points to a directory.' % filename) - raise KeyError("The resource '%s' does not exist." % id) + raise ValueError(f'The path {filename} points to a directory.') + raise KeyError(f'The resource {id} does not exist.') def _get_metadata_file(self, id): filename = self._path(id) + '.meta' diff --git a/core/src/zeit/connector/mock.py b/core/src/zeit/connector/mock.py index 5319d0b738..04d3b3018e 100644 --- a/core/src/zeit/connector/mock.py +++ b/core/src/zeit/connector/mock.py @@ -86,7 +86,7 @@ def _get_collection_names(self, path): def getResourceType(self, id): id = self._get_cannonical_id(id) if id in self._deleted: - raise KeyError("The resource '%s' does not exist." % id) + raise KeyError(f'The resource {id} does not exist.') return super().getResourceType(id) def __getitem__(self, id): @@ -205,7 +205,7 @@ def move(self, old_id, new_id): try: r = self[old_id] except KeyError: - raise MoveError(old_id, 'The resource %s does not exist.', old_id) + raise MoveError(old_id, f'The resource {old_id} does not exist.') if new_id in self: raise MoveError(new_id, f'The resource {new_id} already exists.') r.id = new_id @@ -221,7 +221,7 @@ def move(self, old_id, new_id): def _prevent_overwrite(self, old_id, new_id, exception): if zeit.connector.connector.Connector._is_descendant(new_id, old_id): - raise exception(old_id, 'Could not copy or move %s to a decendant of itself.' % old_id) + raise exception(old_id, f'Could not copy or move {old_id} to a decendant of itself.') if new_id in self: # The target already exists. It's possible that there was a @@ -232,7 +232,7 @@ def _prevent_overwrite(self, old_id, new_id, exception): ): raise exception( old_id, - 'Could not move %s to %s, because target alread exists.' % (old_id, new_id), + f'Could not move {old_id} to {new_id}, because target alread exists.', ) def changeProperties(self, id, properties): diff --git a/core/src/zeit/connector/postgresql.py b/core/src/zeit/connector/postgresql.py index e058e4bf3d..4cacba6912 100644 --- a/core/src/zeit/connector/postgresql.py +++ b/core/src/zeit/connector/postgresql.py @@ -129,7 +129,7 @@ def __getitem__(self, uniqueid): uniqueid = self._normalize(uniqueid) props = self._get_properties(uniqueid) if props is None: - raise KeyError('The resource %s does not exist.' % str(uniqueid)) + raise KeyError(f'The resource {uniqueid} does not exist.') if props.is_collection: _get_body = partial(BytesIO, b'') elif props.binary_body: @@ -240,7 +240,7 @@ def changeProperties(self, uniqueid, properties): uniqueid = self._normalize(uniqueid) props = self._get_properties(uniqueid) if props is None: - raise KeyError('The resource %s does not exist.' % str(uniqueid)) + raise KeyError(f'The resource {uniqueid} does not exist.') current = props.to_webdav() current.update(properties) props.from_webdav(current) @@ -251,7 +251,7 @@ def __delitem__(self, uniqueid): uniqueid = self._normalize(uniqueid) props = self._get_properties(uniqueid) if props is None: - raise KeyError('The resource %s does not exist.' % str(uniqueid)) + raise KeyError(f'The resource {uniqueid} does not exist.') if not props.is_collection and props.binary_body: blob = self.bucket.blob(props.id) with zeit.cms.tracing.use_span( @@ -284,7 +284,7 @@ def copy(self, old_id, new_id): if new_id in self: raise CopyError( old_id, - 'Could not copy %s to %s, ' 'because target alread exists.' % (old_id, new_id), + f'Could not copy {old_id} to {new_id}, because target alread exists.', ) try: old_resource = self[old_id] @@ -315,7 +315,7 @@ def move(self, old_id, new_id): raise MoveError(old_id, f'The resource {old_id} does not exist.') if new_id in self: raise MoveError( - old_id, 'Could not move %s to %s, ' 'because target already exists.', old_id, new_id + old_id, f'Could not move {old_id} to {new_id}, because target already exists.' ) if props.is_collection: for name, _ in self.listCollection(old_id):