diff --git a/vcsserver/base.py b/vcsserver/base.py --- a/vcsserver/base.py +++ b/vcsserver/base.py @@ -64,7 +64,7 @@ def obfuscate_qs(query_string): parsed.append((k, v)) return '&'.join('{}{}'.format( - k, '={}'.format(v) if v else '') for k, v in parsed) + k, f'={v}' if v else '') for k, v in parsed) def raise_from_original(new_type, org_exc: Exception): diff --git a/vcsserver/exceptions.py b/vcsserver/exceptions.py --- a/vcsserver/exceptions.py +++ b/vcsserver/exceptions.py @@ -109,7 +109,7 @@ class HTTPRepoLocked(HTTPLocked): def __init__(self, title, status_code=None, **kwargs): self.code = status_code or HTTPLocked.code self.title = title - super(HTTPRepoLocked, self).__init__(**kwargs) + super().__init__(**kwargs) class HTTPRepoBranchProtected(HTTPForbidden): diff --git a/vcsserver/hooks.py b/vcsserver/hooks.py --- a/vcsserver/hooks.py +++ b/vcsserver/hooks.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # RhodeCode VCSServer provides access to different vcs backends via network. # Copyright (C) 2014-2020 RhodeCode GmbH # @@ -553,7 +551,7 @@ def git_pre_receive(unused_repo_path, re if type_ == 'heads' and not (new_branch or delete_branch): old_rev = push_ref['old_rev'] new_rev = push_ref['new_rev'] - cmd = [settings.GIT_EXECUTABLE, 'rev-list', old_rev, '^{}'.format(new_rev)] + cmd = [settings.GIT_EXECUTABLE, 'rev-list', old_rev, f'^{new_rev}'] stdout, stderr = subprocessio.run_command( cmd, env=os.environ.copy()) # means we're having some non-reachable objects, this forced push was used diff --git a/vcsserver/http_main.py b/vcsserver/http_main.py --- a/vcsserver/http_main.py +++ b/vcsserver/http_main.py @@ -206,7 +206,7 @@ class VCSViewPredicate(object): self.remotes = val def text(self): - return 'vcs view method = %s' % (list(self.remotes.keys()),) + return f'vcs view method = {list(self.remotes.keys())}' phash = text @@ -368,7 +368,7 @@ class HTTPApplication(object): if statsd: statsd.incr( 'vcsserver_method_total', tags=[ - "method:{}".format(method), + f"method:{method}", ]) return payload, remote, method, args, kwargs @@ -673,9 +673,9 @@ class HTTPApplication(object): statsd = request.registry.statsd if statsd: - exc_type = "{}.{}".format(exception.__class__.__module__, exception.__class__.__name__) + exc_type = f"{exception.__class__.__module__}.{exception.__class__.__name__}" statsd.incr('vcsserver_exception_total', - tags=["type:{}".format(exc_type)]) + tags=[f"type:{exc_type}"]) raise exception diff --git a/vcsserver/lib/exc_tracking.py b/vcsserver/lib/exc_tracking.py --- a/vcsserver/lib/exc_tracking.py +++ b/vcsserver/lib/exc_tracking.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # RhodeCode VCSServer provides access to different vcs backends via network. # Copyright (C) 2014-2020 RhodeCode GmbH # @@ -126,10 +124,10 @@ def store_exception(exc_id, exc_info, pr def _find_exc_file(exc_id, prefix=global_prefix): exc_store_path = get_exc_store() if prefix: - exc_id = '{}_{}'.format(exc_id, prefix) + exc_id = f'{exc_id}_{prefix}' else: # search without a prefix - exc_id = '{}'.format(exc_id) + exc_id = f'{exc_id}' # we need to search the store for such start pattern as above for fname in os.listdir(exc_store_path): diff --git a/vcsserver/lib/memory_lru_dict.py b/vcsserver/lib/memory_lru_dict.py --- a/vcsserver/lib/memory_lru_dict.py +++ b/vcsserver/lib/memory_lru_dict.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # RhodeCode VCSServer provides access to different vcs backends via network. # Copyright (C) 2014-2020 RhodeCode GmbH # @@ -53,11 +51,11 @@ class LRUDictDebug(LRUDict): Wrapper to provide some debug options """ def _report_keys(self): - elems_cnt = '%s/%s' % (len(list(self.keys())), self.size) + elems_cnt = '{}/{}'.format(len(list(self.keys())), self.size) # trick for pformat print it more nicely fmt = '\n' for cnt, elem in enumerate(self.keys()): - fmt += '%s - %s\n' % (cnt+1, safe_str(elem)) + fmt += '{} - {}\n'.format(cnt+1, safe_str(elem)) log.debug('current LRU keys (%s):%s', elems_cnt, fmt) def __getitem__(self, key): diff --git a/vcsserver/lib/rc_cache/__init__.py b/vcsserver/lib/rc_cache/__init__.py --- a/vcsserver/lib/rc_cache/__init__.py +++ b/vcsserver/lib/rc_cache/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # RhodeCode VCSServer provides access to different vcs backends via network. # Copyright (C) 2014-2020 RhodeCode GmbH # diff --git a/vcsserver/lib/rc_cache/backends.py b/vcsserver/lib/rc_cache/backends.py --- a/vcsserver/lib/rc_cache/backends.py +++ b/vcsserver/lib/rc_cache/backends.py @@ -58,7 +58,7 @@ class LRUMemoryBackend(memory_backend.Me LRUDictClass = LRUDictDebug arguments['cache_dict'] = LRUDictClass(self.max_size) - super(LRUMemoryBackend, self).__init__(arguments) + super().__init__(arguments) def __repr__(self): return f'{self.__class__}(maxsize=`{self.max_size}`)' @@ -79,19 +79,19 @@ class LRUMemoryBackend(memory_backend.Me class PickleSerializer: - serializer: Union[None, Serializer] = staticmethod( # type: ignore + serializer: None | Serializer = staticmethod( # type: ignore functools.partial(pickle.dumps, protocol=pickle.HIGHEST_PROTOCOL) ) - deserializer: Union[None, Deserializer] = staticmethod( # type: ignore + deserializer: None | Deserializer = staticmethod( # type: ignore functools.partial(pickle.loads) ) class MsgPackSerializer(object): - serializer: Union[None, Serializer] = staticmethod( # type: ignore + serializer: None | Serializer = staticmethod( # type: ignore msgpack.packb ) - deserializer: Union[None, Deserializer] = staticmethod( # type: ignore + deserializer: None | Deserializer = staticmethod( # type: ignore functools.partial(msgpack.unpackb, use_list=False) ) @@ -114,7 +114,7 @@ class FileNamespaceBackend(PickleSeriali os.makedirs(db_file_dir) try: - super(FileNamespaceBackend, self).__init__(arguments) + super().__init__(arguments) except Exception: log.exception('Failed to initialize db at: %s', db_file) raise @@ -152,7 +152,7 @@ class BaseRedisBackend(redis_backend.Red def __init__(self, arguments): self.db_conn = arguments.get('host', '') or arguments.get('url', '') or 'redis-host' - super(BaseRedisBackend, self).__init__(arguments) + super().__init__(arguments) self._lock_timeout = self.lock_timeout self._lock_auto_renewal = str2bool(arguments.pop("lock_auto_renewal", True)) diff --git a/vcsserver/lib/rc_cache/utils.py b/vcsserver/lib/rc_cache/utils.py --- a/vcsserver/lib/rc_cache/utils.py +++ b/vcsserver/lib/rc_cache/utils.py @@ -168,7 +168,7 @@ def get_or_create_region(region_name, re region_obj = region_meta.dogpile_cache_regions.get(region_name) if not region_obj: reg_keys = list(region_meta.dogpile_cache_regions.keys()) - raise EnvironmentError(f'Region `{region_name}` not in configured: {reg_keys}.') + raise OSError(f'Region `{region_name}` not in configured: {reg_keys}.') region_uid_name = f'{region_name}:{region_namespace}' diff --git a/vcsserver/lib/request_counter.py b/vcsserver/lib/request_counter.py --- a/vcsserver/lib/request_counter.py +++ b/vcsserver/lib/request_counter.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # RhodeCode VCSServer provides access to different vcs backends via network. # Copyright (C) 2014-2020 RhodeCode GmbH # diff --git a/vcsserver/lib/statsd_client.py b/vcsserver/lib/statsd_client.py --- a/vcsserver/lib/statsd_client.py +++ b/vcsserver/lib/statsd_client.py @@ -29,7 +29,7 @@ class _Singleton(type): def __call__(cls, *args, **kwargs): if cls not in cls._instances: - cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs) + cls._instances[cls] = super().__call__(*args, **kwargs) return cls._instances[cls] @@ -47,13 +47,13 @@ class StatsdClientClass(Singleton): if name.startswith("statsd"): if self.setup_run: - return super(StatsdClientClass, self).__getattribute__(name) + return super().__getattribute__(name) else: if self.strict_mode_init: raise StatsdClientNotInitialised(f"requested key was {name}") return None - return super(StatsdClientClass, self).__getattribute__(name) + return super().__getattribute__(name) def setup(self, settings): """ diff --git a/vcsserver/pygrack.py b/vcsserver/pygrack.py --- a/vcsserver/pygrack.py +++ b/vcsserver/pygrack.py @@ -56,7 +56,7 @@ class FileWrapper(object): return data def __repr__(self): - return '' % ( + return ''.format( self.fd, self.content_length, self.content_length - self.remain ) @@ -66,7 +66,7 @@ class GitRepository(object): git_folder_signature = frozenset(('config', 'head', 'info', 'objects', 'refs')) commands = frozenset(('git-upload-pack', 'git-receive-pack')) - valid_accepts = frozenset(('application/x-{}-result'.format(c) for c in commands)) + valid_accepts = frozenset(f'application/x-{c}-result' for c in commands) # The last bytes are the SHA1 of the first 12 bytes. EMPTY_PACK = ( @@ -330,7 +330,7 @@ class GitRepository(object): inputstream = request.body_file_seekable resp = Response() - resp.content_type = 'application/x-{}-result'.format(git_command) + resp.content_type = f'application/x-{git_command}-result' resp.charset = None pre_pull_messages = '' diff --git a/vcsserver/remote/git.py b/vcsserver/remote/git.py --- a/vcsserver/remote/git.py +++ b/vcsserver/remote/git.py @@ -142,7 +142,7 @@ class GitRemote(RemoteBase): def _wire_to_config(self, wire): if 'config' in wire: - return dict([(x[0] + '_' + x[1], x[2]) for x in wire['config']]) + return {x[0] + '_' + x[1]: x[2] for x in wire['config']} return {} def _remote_conf(self, config): @@ -151,7 +151,7 @@ class GitRemote(RemoteBase): ] ssl_cert_dir = config.get('vcs_ssl_dir') if ssl_cert_dir: - params.extend(['-c', 'http.sslCAinfo={}'.format(ssl_cert_dir)]) + params.extend(['-c', f'http.sslCAinfo={ssl_cert_dir}']) return params @reraise_safe_exceptions @@ -321,7 +321,7 @@ class GitRemote(RemoteBase): store = LFSOidStore( oid=oid, repo=repo_name, store_location=store_location) return store.oid_path - raise ValueError('Unable to fetch oid with path {}'.format(oid)) + raise ValueError(f'Unable to fetch oid with path {oid}') @reraise_safe_exceptions def bulk_request(self, wire, rev, pre_load): @@ -383,7 +383,7 @@ class GitRemote(RemoteBase): q = {"service": 'git-upload-pack'} qs = '?%s' % urllib.parse.urlencode(q) - cu = "%s%s" % (test_uri, qs) + cu = "{}{}".format(test_uri, qs) req = urllib.request.Request(cu, None, {}) try: @@ -394,7 +394,7 @@ class GitRemote(RemoteBase): except Exception as e: log.warning("URL cannot be opened: %s", cleaned_uri, exc_info=True) # means it cannot be cloned - raise exceptions.URLError(e)("[%s] org_exc: %s" % (cleaned_uri, e)) + raise exceptions.URLError(e)("[{}] org_exc: {}".format(cleaned_uri, e)) # now detect if it's proper git repo gitdata = resp.read() @@ -405,7 +405,7 @@ class GitRemote(RemoteBase): pass else: raise exceptions.URLError()( - "url [%s] does not look like an git" % (cleaned_uri,)) + "url [{}] does not look like an git".format(cleaned_uri)) return True @@ -943,12 +943,12 @@ class GitRemote(RemoteBase): author = commit.get_object().author if author.email: - return "{} <{}>".format(author.name, author.email) + return f"{author.name} <{author.email}>" try: - return "{}".format(author.name) + return f"{author.name}" except Exception: - return "{}".format(safe_str(author.raw_name)) + return f"{safe_str(author.raw_name)}" return _author(repo_id, commit_id) @@ -997,7 +997,7 @@ class GitRemote(RemoteBase): wire, ['rev-list', '--all', '--children', f'{commit_id}^..{head}']) child_ids = [] - pat = re.compile(r'^{}'.format(commit_id)) + pat = re.compile(fr'^{commit_id}') for line in output.splitlines(): line = safe_str(line) if pat.match(line): @@ -1036,7 +1036,7 @@ class GitRemote(RemoteBase): def tag_remove(self, wire, tag_name): repo_init = self._factory.repo_libgit2(wire) with repo_init as repo: - key = 'refs/tags/{}'.format(tag_name) + key = f'refs/tags/{tag_name}' repo.references.delete(key) @reraise_safe_exceptions @@ -1081,7 +1081,7 @@ class GitRemote(RemoteBase): try: tree = repo[tree_id] except KeyError: - raise ObjectMissing('No tree with id: {}'.format(tree_id)) + raise ObjectMissing(f'No tree with id: {tree_id}') result = [] for item in tree: @@ -1363,7 +1363,7 @@ class GitRemote(RemoteBase): try: tree = repo[tree_id] except KeyError: - raise ObjectMissing('No tree with id: {}'.format(tree_id)) + raise ObjectMissing(f'No tree with id: {tree_id}') index = LibGit2Index.Index() index.read_tree(tree) diff --git a/vcsserver/remote/hg.py b/vcsserver/remote/hg.py --- a/vcsserver/remote/hg.py +++ b/vcsserver/remote/hg.py @@ -431,9 +431,9 @@ class HgRemote(RemoteBase): ('Accept', 'application/mercurial-0.1')] q = {"cmd": 'between'} - q.update({'pairs': "%s-%s" % ('0' * 40, '0' * 40)}) + q.update({'pairs': "{}-{}".format('0' * 40, '0' * 40)}) qs = '?%s' % urllib.parse.urlencode(q) - cu = "%s%s" % (test_uri, qs) + cu = "{}{}".format(test_uri, qs) req = urllib.request.Request(cu, None, {}) try: @@ -444,7 +444,7 @@ class HgRemote(RemoteBase): except Exception as e: log.warning("URL cannot be opened: %s", cleaned_uri, exc_info=True) # means it cannot be cloned - raise exceptions.URLError(e)("[%s] org_exc: %s" % (cleaned_uri, e)) + raise exceptions.URLError(e)("[{}] org_exc: {}".format(cleaned_uri, e)) # now check if it's a proper hg repo, but don't do it for svn try: diff --git a/vcsserver/remote/svn.py b/vcsserver/remote/svn.py --- a/vcsserver/remote/svn.py +++ b/vcsserver/remote/svn.py @@ -138,7 +138,7 @@ class SvnRemote(RemoteBase): tb = traceback.format_exc() log.debug("Invalid Subversion url: `%s`, tb: %s", url, tb) raise URLError( - '"%s" is not a valid Subversion source url.' % (url, )) + '"{}" is not a valid Subversion source url.'.format(url)) return True def is_path_valid_repository(self, wire, path): @@ -239,7 +239,7 @@ class SvnRemote(RemoteBase): removed.append(path) else: raise NotImplementedError( - "Action %s not supported on path %s" % ( + "Action {} not supported on path {}".format( change.action, path)) changes = { @@ -418,10 +418,10 @@ class SvnRemote(RemoteBase): reason = 'INVALID_CERTIFICATE' if reason == 'UNKNOWN': - reason = 'UNKNOWN:{}'.format(safe_str(errors)) + reason = f'UNKNOWN:{safe_str(errors)}' raise Exception( - 'Failed to dump the remote repository from %s. Reason:%s' % ( + 'Failed to dump the remote repository from {}. Reason:{}'.format( src_url, reason)) if load.returncode != 0: raise Exception( @@ -575,8 +575,7 @@ class SvnRemote(RemoteBase): # return only DIR, and then all entries in that dir yield os.path.join(root_dir, f_name), {'mode': filemode_default}, f_type new_root = os.path.join(root_dir, f_name) - for _f_name, _f_data, _f_type in walk_tree(root, new_root, _commit_id): - yield _f_name, _f_data, _f_type + yield from walk_tree(root, new_root, _commit_id) else: f_path = os.path.join(root_dir, f_name).rstrip(b'/') @@ -723,10 +722,10 @@ class SvnDiffer(object): buf.write("=" * 67 + '\n') buf.write("Cannot display: file marked as a binary type.\n") buf.write("svn:mime-type = %s\n" % mime_type) - buf.write("Index: %s\n" % (tgt_path, )) + buf.write("Index: {}\n".format(tgt_path)) buf.write("=" * 67 + '\n') - buf.write("diff --git a/%(tgt_path)s b/%(tgt_path)s\n" % { - 'tgt_path': tgt_path}) + buf.write("diff --git a/{tgt_path} b/{tgt_path}\n".format( + tgt_path=tgt_path)) if change == 'add': # TODO: johbo: SVN is missing a zero here compared to git @@ -746,15 +745,15 @@ class SvnDiffer(object): # if self.binary_content: # buf.write('GIT binary patch\n') - buf.write("--- a/%s\t(revision %s)\n" % ( + buf.write("--- a/{}\t(revision {})\n".format( src_path, self.src_rev)) src_lines = self._svn_readlines(self.src_root, src_full_path) if change == 'delete': - buf.write("+++ /dev/null\t(revision %s)\n" % (self.tgt_rev, )) + buf.write("+++ /dev/null\t(revision {})\n".format(self.tgt_rev)) tgt_lines = [] else: - buf.write("+++ b/%s\t(revision %s)\n" % ( + buf.write("+++ b/{}\t(revision {})\n".format( tgt_path, self.tgt_rev)) tgt_lines = self._svn_readlines(self.tgt_root, tgt_full_path) diff --git a/vcsserver/scm_app.py b/vcsserver/scm_app.py --- a/vcsserver/scm_app.py +++ b/vcsserver/scm_app.py @@ -104,7 +104,7 @@ class HgWeb(mercurial.hgweb.hgweb_mod.hg res.setbodybytes(b'') return res.sendresponse() - return super(HgWeb, self)._runwsgi(req, res, repo) + return super()._runwsgi(req, res, repo) def make_hg_ui_from_config(repo_config): diff --git a/vcsserver/str_utils.py b/vcsserver/str_utils.py --- a/vcsserver/str_utils.py +++ b/vcsserver/str_utils.py @@ -44,7 +44,7 @@ def base64_to_str(text) -> str: return safe_str(base64.encodebytes(safe_bytes(text))).strip() -def get_default_encodings() -> typing.List[str]: +def get_default_encodings() -> list[str]: return ['utf8'] diff --git a/vcsserver/svn_diff.py b/vcsserver/svn_diff.py --- a/vcsserver/svn_diff.py +++ b/vcsserver/svn_diff.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2004-2009 Edgewall Software # Copyright (C) 2004-2006 Christopher Lenz @@ -174,7 +173,7 @@ def unified_diff(fromlines, tolines, con i1, i2 = -1, -1 # support for Add changes if j1 == 0 and j2 == 0: j1, j2 = -1, -1 # support for Delete changes - yield '@@ -%s +%s @@%s' % ( + yield '@@ -{} +{} @@{}'.format( _hunk_range(i1 + 1, i2 - i1), _hunk_range(j1 + 1, j2 - j1), lineterm) diff --git a/vcsserver/utils.py b/vcsserver/utils.py --- a/vcsserver/utils.py +++ b/vcsserver/utils.py @@ -41,7 +41,7 @@ class StrictAttributeDict(AttributeDictB try: return self[attr] except KeyError: - raise AttributeError('%s object has no attribute %s' % ( + raise AttributeError('{} object has no attribute {}'.format( self.__class__, attr)) diff --git a/vcsserver/vcs_base.py b/vcsserver/vcs_base.py --- a/vcsserver/vcs_base.py +++ b/vcsserver/vcs_base.py @@ -28,7 +28,7 @@ class RemoteBase(object): def _cache_on(self, wire): context = wire.get('context', '') - context_uid = '{}'.format(context) + context_uid = f'{context}' repo_id = wire.get('repo_id', '') cache = wire.get('cache', True) cache_on = context and cache