Skip to content

Commit

Permalink
MAINT: Use f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
louika committed Feb 28, 2024
1 parent 7dc7e85 commit 667abbc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions core/src/zeit/connector/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')

Expand All @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions core/src/zeit/connector/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions core/src/zeit/connector/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 667abbc

Please sign in to comment.