# HG changeset patch # User Mads Kiilerich # Date 1574549968 -3600 # Node ID ce5d4c582a82a5586b9b3ee72886dc6a5f29ac2c # Parent 4fcf63512b77a166bd6c047c16c55f3a8d1bf085 py3: cleanup map usage and avoid py3 ambiguity Based on 2to3 -f map ... but replace map with something more explicit (unless born and raised in a lisp world) (but sometimes slightly more verbose). diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/bin/kallithea_api.py --- a/kallithea/bin/kallithea_api.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/bin/kallithea_api.py Sat Nov 23 23:59:28 2019 +0100 @@ -101,7 +101,7 @@ parser.error('Please specify method name') try: - margs = dict(map(lambda s: s.split(':', 1), other)) + margs = dict(s.split(':', 1) for s in other) except ValueError: sys.stderr.write('Error parsing arguments \n') sys.exit() diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/controllers/admin/repo_groups.py --- a/kallithea/controllers/admin/repo_groups.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/controllers/admin/repo_groups.py Sat Nov 23 23:59:28 2019 +0100 @@ -25,7 +25,6 @@ :license: GPLv3, see LICENSE.md for more details. """ -import itertools import logging import traceback @@ -42,7 +41,7 @@ from kallithea.lib import helpers as h from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoGroupPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseController, render -from kallithea.lib.utils2 import safe_int +from kallithea.lib.utils2 import safe_int, safe_unicode from kallithea.model.db import RepoGroup, Repository from kallithea.model.forms import RepoGroupForm, RepoGroupPermsForm from kallithea.model.meta import Session @@ -120,9 +119,7 @@ ) for repo_gr in group_iter: - children_groups = map(h.safe_unicode, - itertools.chain((g.name for g in repo_gr.parents), - (x.name for x in [repo_gr]))) + children_groups = [safe_unicode(g.name) for g in repo_gr.parents] + [safe_unicode(repo_gr.name)] repo_count = repo_gr.repositories.count() repo_groups_data.append({ "raw_name": repo_gr.group_name, diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/controllers/api/__init__.py --- a/kallithea/controllers/api/__init__.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/controllers/api/__init__.py Sat Nov 23 23:59:28 2019 +0100 @@ -168,7 +168,7 @@ # self.kargs and dispatch control to WGIController argspec = inspect.getargspec(self._func) arglist = argspec[0][1:] - defaults = map(type, argspec[3] or []) + defaults = [type(arg) for arg in argspec[3] or []] default_empty = type(NotImplemented) # kw arguments required by this method diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/controllers/feed.py --- a/kallithea/controllers/feed.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/controllers/feed.py Sat Nov 23 23:59:28 2019 +0100 @@ -100,7 +100,7 @@ desc_msg.append('\n\n') desc_msg.append(raw_diff) desc_msg.append('') - return map(safe_unicode, desc_msg) + return [safe_unicode(chunk) for chunk in desc_msg] def _feed(self, repo_name, kind, feed_factory): """Produce a simple feed""" diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/lib/helpers.py Sat Nov 23 23:59:28 2019 +0100 @@ -379,7 +379,7 @@ h %= 1 HSV_tuple = [h, 0.95, 0.95] RGB_tuple = hsv_to_rgb(*HSV_tuple) - yield map(lambda x: str(int(x * 256)), RGB_tuple) + yield [str(int(x * 256)) for x in RGB_tuple] cgenerator = gen_color() diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/lib/indexers/daemon.py --- a/kallithea/lib/indexers/daemon.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/lib/indexers/daemon.py Sat Nov 23 23:59:28 2019 +0100 @@ -78,7 +78,7 @@ # filter repo list if repo_list: # Fix non-ascii repo names to unicode - repo_list = map(safe_unicode, repo_list) + repo_list = set(safe_unicode(repo_name) for repo_name in repo_list) self.filtered_repo_paths = {} for repo_name, repo in self.repo_paths.items(): if repo_name in repo_list: diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/lib/vcs/backends/git/inmemory.py --- a/kallithea/lib/vcs/backends/git/inmemory.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/lib/vcs/backends/git/inmemory.py Sat Nov 23 23:59:28 2019 +0100 @@ -47,7 +47,7 @@ for node in self.added + self.changed: # Compute subdirs if needed dirpath, nodename = posixpath.split(node.path) - dirnames = map(safe_str, dirpath and dirpath.split('/') or []) + dirnames = safe_str(dirpath).split('/') if dirpath else [] parent = commit_tree ancestors = [('', parent)] diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/lib/vcs/backends/hg/changeset.py --- a/kallithea/lib/vcs/backends/hg/changeset.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/lib/vcs/backends/hg/changeset.py Sat Nov 23 23:59:28 2019 +0100 @@ -27,7 +27,7 @@ @LazyProperty def tags(self): - return map(safe_unicode, self._ctx.tags()) + return [safe_unicode(tag) for tag in self._ctx.tags()] @LazyProperty def branch(self): @@ -95,7 +95,7 @@ @LazyProperty def bookmarks(self): - return map(safe_unicode, self._ctx.bookmarks()) + return [safe_unicode(bookmark) for bookmark in self._ctx.bookmarks()] @LazyProperty def message(self): diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/model/db.py --- a/kallithea/model/db.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/model/db.py Sat Nov 23 23:59:28 2019 +0100 @@ -1163,7 +1163,7 @@ # names in the database, but that eventually needs to be converted # into a valid system path p += self.repo_name.split(Repository.url_sep()) - return os.path.join(*map(safe_unicode, p)) + return os.path.join(*(safe_unicode(d) for d in p)) @property def cache_keys(self): @@ -2511,8 +2511,7 @@ def scm_instance(self): from kallithea.lib.vcs import get_repo base_path = self.base_path() - return get_repo(os.path.join(*map(safe_str, - [base_path, self.gist_access_id]))) + return get_repo(os.path.join(safe_str(base_path), safe_str(self.gist_access_id))) class UserSshKeys(Base, BaseDbModel): diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/model/permission.py --- a/kallithea/model/permission.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/model/permission.py Sat Nov 23 23:59:28 2019 +0100 @@ -73,8 +73,7 @@ return '.'.join(perm_name.split('.')[:1]) perms = UserToPerm.query().filter(UserToPerm.user == user).all() - defined_perms_groups = map(_get_group, - (x.permission.permission_name for x in perms)) + defined_perms_groups = set(_get_group(x.permission.permission_name) for x in perms) log.debug('GOT ALREADY DEFINED:%s', perms) DEFAULT_PERMS = Permission.DEFAULT_USER_PERMISSIONS diff -r 4fcf63512b77 -r ce5d4c582a82 kallithea/model/repo.py --- a/kallithea/model/repo.py Sat Nov 23 21:40:27 2019 +0100 +++ b/kallithea/model/repo.py Sat Nov 23 23:59:28 2019 +0100 @@ -644,7 +644,7 @@ else: _paths = [self.repos_path, new_parent_path, repo_name] # we need to make it str for mercurial - repo_path = os.path.join(*map(lambda x: safe_str(x), _paths)) + repo_path = os.path.join(*(safe_str(x) for x in _paths)) # check if this path is not a repository if is_valid_repo(repo_path, self.repos_path):