api: modernize code for python3

This commit is contained in:
RhodeCode Admin 2023-07-18 14:16:28 +02:00
parent 80f63bd18b
commit 230f12827e
16 changed files with 113 additions and 143 deletions

View file

@ -1,5 +1,3 @@
# Copyright (C) 2014-2023 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
@ -224,7 +222,7 @@ def get_user_or_error(userid):
if user is None:
raise JSONRPCError(
'user `%s` does not exist' % (userid,))
'user `{}` does not exist'.format(userid))
return user
@ -247,7 +245,7 @@ def get_repo_or_error(repoid):
if repo is None:
raise JSONRPCError(
'repository `%s` does not exist' % (repoid,))
'repository `{}` does not exist'.format(repoid))
return repo
@ -270,7 +268,7 @@ def get_repo_group_or_error(repogroupid):
if repo_group is None:
raise JSONRPCError(
'repository group `%s` does not exist' % (repogroupid,))
'repository group `{}` does not exist'.format(repogroupid))
return repo_group
@ -293,7 +291,7 @@ def get_user_group_or_error(usergroupid):
if user_group is None:
raise JSONRPCError(
'user group `%s` does not exist' % (usergroupid,))
'user group `{}` does not exist'.format(usergroupid))
return user_group
@ -307,9 +305,9 @@ def get_perm_or_error(permid, prefix=None):
perm = PermissionModel.cls.get_by_key(permid)
if perm is None:
msg = 'permission `{}` does not exist.'.format(permid)
msg = f'permission `{permid}` does not exist.'
if prefix:
msg += ' Permission should start with prefix: `{}`'.format(prefix)
msg += f' Permission should start with prefix: `{prefix}`'
raise JSONRPCError(msg)
if prefix:
@ -329,7 +327,7 @@ def get_gist_or_error(gistid):
gist = GistModel.cls.get_by_access_id(gistid)
if gist is None:
raise JSONRPCError('gist `%s` does not exist' % (gistid,))
raise JSONRPCError('gist `{}` does not exist'.format(gistid))
return gist
@ -346,8 +344,8 @@ def get_pull_request_or_error(pullrequestid):
except ValueError:
raise JSONRPCError('pullrequestid must be an integer')
if not pull_request:
raise JSONRPCError('pull request `%s` does not exist' % (
pullrequestid,))
raise JSONRPCError('pull request `{}` does not exist'.format(
pullrequestid))
return pull_request
@ -394,7 +392,7 @@ def get_commit_or_error(ref, repo):
# once get_commit supports ref_types
return get_commit_from_ref_name(repo, ref_hash)
except RepositoryError:
raise JSONRPCError('Ref `{ref}` does not exist'.format(ref=ref))
raise JSONRPCError(f'Ref `{ref}` does not exist')
def _get_ref_hash(repo, type_, name):