# HG changeset patch # User Marcin Kuzminski # Date 2020-06-10 12:04:17 # Node ID 1d5adfe8ab3aac5c4b3ac4fcbb9e793c3cc888c4 # Parent 5009dce2a2ab55926e82364ea434acb3af14b0d8 py3: import/code fixes diff --git a/pkgs/overlays.nix b/pkgs/overlays.nix --- a/pkgs/overlays.nix +++ b/pkgs/overlays.nix @@ -28,7 +28,7 @@ self: super: { owner = "libgit2"; repo = "libgit2"; rev = "v1.0.1"; - sha256 = "1cm8fvs05rj0baigs2133q5a0sm3pa234y8h6hmwhl2bz9xq3k4b"; + sha256 = "0xqdnvrq1bnf8hxh9xjw25y2cg91agvd9jr5qwd30z2a0dzll22v"; }; cmakeFlags = [ "-DTHREADSAFE=ON" "-DUSE_HTTPS=no"]; @@ -40,13 +40,10 @@ self: super: { super.curl ]; - }); - - # Override subversion derivation to - # - activate python bindings + # - activate special python bindings subversionrc = let py3c = self.python37Packages.buildPythonPackage rec { diff --git a/vcsserver/base.py b/vcsserver/base.py --- a/vcsserver/base.py +++ b/vcsserver/base.py @@ -18,7 +18,7 @@ import sys import traceback import logging -import urlparse +import urllib.parse from vcsserver.lib.rc_cache import region_meta log = logging.getLogger(__name__) @@ -52,7 +52,7 @@ def obfuscate_qs(query_string): return None parsed = [] - for k, v in urlparse.parse_qsl(query_string, keep_blank_values=True): + for k, v in urllib.parse.parse_qsl(query_string, keep_blank_values=True): if k in ['auth_token', 'api_key']: v = "*****" parsed.append((k, v)) @@ -71,6 +71,6 @@ def raise_from_original(new_type): new_exc._org_exc_tb = traceback.format_exc(exc_traceback) try: - raise new_exc, None, exc_traceback + raise new_exc.with_traceback(exc_traceback) finally: del exc_traceback diff --git a/vcsserver/git.py b/vcsserver/git.py --- a/vcsserver/git.py +++ b/vcsserver/git.py @@ -22,8 +22,8 @@ import posixpath as vcspath import re import stat import traceback -import urllib -import urllib2 +import urllib.request, urllib.parse, urllib.error +import urllib.request, urllib.error, urllib.parse from functools import wraps import more_itertools @@ -327,13 +327,13 @@ class GitRemote(RemoteBase): if authinfo: # create a password manager - passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() + passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() passmgr.add_password(*authinfo) handlers.extend((httpbasicauthhandler(passmgr), httpdigestauthhandler(passmgr))) - return urllib2.build_opener(*handlers) + return urllib.request.build_opener(*handlers) def _type_id_to_name(self, type_id): return { @@ -359,9 +359,9 @@ class GitRemote(RemoteBase): o.addheaders = [('User-Agent', 'git/1.7.8.0')] # fake some git q = {"service": 'git-upload-pack'} - qs = '?%s' % urllib.urlencode(q) + qs = '?%s' % urllib.parse.urlencode(q) cu = "%s%s" % (test_uri, qs) - req = urllib2.Request(cu, None, {}) + req = urllib.request.Request(cu, None, {}) try: log.debug("Trying to open URL %s", cleaned_uri) @@ -415,7 +415,7 @@ class GitRemote(RemoteBase): def filter_with(ref): return regex.match(ref[0]) and ref[1] == _commit_id - branches = filter(filter_with, self.get_refs(wire).items()) + branches = list(filter(filter_with, list(self.get_refs(wire).items()))) return [x[0].split('refs/heads/')[-1] for x in branches] return _branch(context_uid, repo_id, commit_id) @@ -453,7 +453,7 @@ class GitRemote(RemoteBase): for node in updated: # Compute subdirs if needed dirpath, nodename = vcspath.split(node['path']) - dirnames = map(safe_str, dirpath and dirpath.split('/') or []) + dirnames = list(map(safe_str, dirpath and dirpath.split('/') or [])) parent = commit_tree ancestors = [('', parent)] @@ -519,7 +519,7 @@ class GitRemote(RemoteBase): except KeyError: break # Cut down the blob and all rotten trees on the way back... - for path, tree in reversed(zip(paths, trees)): + for path, tree in reversed(list(zip(paths, trees))): del tree[path] if tree: # This tree still has elements - don't remove it or any @@ -531,7 +531,7 @@ class GitRemote(RemoteBase): # Create commit commit = objects.Commit() commit.tree = commit_tree.id - for k, v in commit_data.iteritems(): + for k, v in commit_data.items(): setattr(commit, k, v) object_store.add_object(commit) @@ -733,7 +733,7 @@ class GitRemote(RemoteBase): raise exceptions.LookupException(e)(missing_commit_err) commit_id = commit.hex - type_id = commit.type + type_id = commit.type_str return { 'id': commit_id, @@ -754,7 +754,7 @@ class GitRemote(RemoteBase): with repo_init as repo: regex = re.compile('^refs/(heads|tags)/') return {x.name: x.target.hex for x in - filter(lambda ref: regex.match(ref.name) ,repo.listall_reference_objects())} + [ref for ref in repo.listall_reference_objects() if regex.match(ref.name)]} return _get_refs(context_uid, repo_id) @@ -767,7 +767,7 @@ class GitRemote(RemoteBase): repo_init = self._factory.repo_libgit2(wire) regex = re.compile('^refs/heads') with repo_init as repo: - branches = filter(lambda ref: regex.match(ref.name), repo.listall_reference_objects()) + branches = [ref for ref in repo.listall_reference_objects() if regex.match(ref.name)] return {x.target.hex: x.shorthand for x in branches} return _get_branch_pointers(context_uid, repo_id) @@ -849,12 +849,12 @@ class GitRemote(RemoteBase): author = commit.get_object().author if author.email: - return u"{} <{}>".format(author.name, author.email) + return "{} <{}>".format(author.name, author.email) try: - return u"{}".format(author.name) + return "{}".format(author.name) except Exception: - return u"{}".format(safe_unicode(author.raw_name)) + return "{}".format(safe_unicode(author.raw_name)) return _author(repo_id, commit_id) @@ -958,7 +958,7 @@ class GitRemote(RemoteBase): except KeyError: return None, None, None - return tree.id.hex, tree.type, tree.filemode + return tree.id.hex, tree.type_str, tree.filemode return _tree_and_type_for_path(context_uid, repo_id, commit_id, path) @reraise_safe_exceptions @@ -978,7 +978,7 @@ class GitRemote(RemoteBase): for item in tree: item_sha = item.hex item_mode = item.filemode - item_type = item.type + item_type = item.type_str if item_type == 'commit': # NOTE(marcink): submodules we translate to 'link' for backward compat diff --git a/vcsserver/git_lfs/__init__.py b/vcsserver/git_lfs/__init__.py --- a/vcsserver/git_lfs/__init__.py +++ b/vcsserver/git_lfs/__init__.py @@ -16,4 +16,4 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -from app import create_app +from .app import create_app diff --git a/vcsserver/hg.py b/vcsserver/hg.py --- a/vcsserver/hg.py +++ b/vcsserver/hg.py @@ -18,8 +18,8 @@ import io import logging import stat -import urllib -import urllib2 +import urllib.request, urllib.parse, urllib.error +import urllib.request, urllib.error, urllib.parse import traceback from hgext import largefiles, rebase, purge @@ -402,21 +402,21 @@ class HgRemote(RemoteBase): if authinfo: # create a password manager - passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() + passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() passmgr.add_password(*authinfo) handlers.extend((httpbasicauthhandler(passmgr), httpdigestauthhandler(passmgr))) - o = urllib2.build_opener(*handlers) + o = urllib.request.build_opener(*handlers) o.addheaders = [('Content-Type', 'application/mercurial-0.1'), ('Accept', 'application/mercurial-0.1')] q = {"cmd": 'between'} q.update({'pairs': "%s-%s" % ('0' * 40, '0' * 40)}) - qs = '?%s' % urllib.urlencode(q) + qs = '?%s' % urllib.parse.urlencode(q) cu = "%s%s" % (test_uri, qs) - req = urllib2.Request(cu, None, {}) + req = urllib.request.Request(cu, None, {}) try: log.debug("Trying to open URL %s", cleaned_uri) @@ -564,7 +564,7 @@ class HgRemote(RemoteBase): def _get_all_commit_ids(_context_uid, _repo_id, _name): repo = self._factory.repo(wire) repo = repo.filtered(name) - revs = map(lambda x: hex(x[7]), repo.changelog.index) + revs = [hex(x[7]) for x in repo.changelog.index] return revs return _get_all_commit_ids(context_uid, repo_id, name) @@ -663,7 +663,7 @@ class HgRemote(RemoteBase): # Disable any prompts for this repo repo.ui.setconfig('ui', 'interactive', 'off', '-y') - bookmarks = dict(repo._bookmarks).keys() + bookmarks = list(dict(repo._bookmarks).keys()) remote = peer(repo, {}, url) # Disable any prompts for this remote remote.ui.setconfig('ui', 'interactive', 'off', '-y') diff --git a/vcsserver/hgpatches.py b/vcsserver/hgpatches.py --- a/vcsserver/hgpatches.py +++ b/vcsserver/hgpatches.py @@ -62,7 +62,7 @@ def _dynamic_capabilities_wrapper(lfprot def patch_subrepo_type_mapping(): from collections import defaultdict - from hgcompat import subrepo, subrepoutil + from .hgcompat import subrepo, subrepoutil from vcsserver.exceptions import SubrepoMergeException class NoOpSubrepo(subrepo.abstractsubrepo): diff --git a/vcsserver/hooks.py b/vcsserver/hooks.py --- a/vcsserver/hooks.py +++ b/vcsserver/hooks.py @@ -25,7 +25,7 @@ import collections import importlib import base64 -from httplib import HTTPConnection +from http.client import HTTPConnection import mercurial.scmutil diff --git a/vcsserver/svn.py b/vcsserver/svn.py --- a/vcsserver/svn.py +++ b/vcsserver/svn.py @@ -15,16 +15,16 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -from __future__ import absolute_import + import os import subprocess -from urllib2 import URLError -import urlparse +from urllib.error import URLError +import urllib.parse import logging import posixpath as vcspath -import StringIO -import urllib +import io +import urllib.request, urllib.parse, urllib.error import traceback import svn.client @@ -224,7 +224,7 @@ class SvnRemote(RemoteBase): removed = [] # TODO: CHANGE_ACTION_REPLACE: Figure out where it belongs - for path, change in editor.changes.iteritems(): + for path, change in editor.changes.items(): # TODO: Decide what to do with directory nodes. Subversion can add # empty directories. @@ -282,7 +282,7 @@ class SvnRemote(RemoteBase): return _node_properties(repo_id, path, revision) def file_annotate(self, wire, path, revision): - abs_path = 'file://' + urllib.pathname2url( + abs_path = 'file://' + urllib.request.pathname2url( vcspath.join(wire['path'], path)) file_uri = svn.core.svn_path_canonicalize(abs_path) @@ -334,7 +334,7 @@ class SvnRemote(RemoteBase): root = svn.fs.revision_root(fsobj, _revision) entries = svn.fs.dir_entries(root, path) result = [] - for entry_path, entry_info in entries.iteritems(): + for entry_path, entry_info in entries.items(): result.append( (entry_path, NODE_TYPE_MAPPING.get(entry_info.kind, None))) return result @@ -369,7 +369,7 @@ class SvnRemote(RemoteBase): compatible_version=compatible_version) def get_url_and_credentials(self, src_url): - obj = urlparse.urlparse(src_url) + obj = urllib.parse.urlparse(src_url) username = obj.username or None password = obj.password or None return username, password, src_url @@ -568,7 +568,7 @@ class SvnDiffer(object): (self.src_kind, self.tgt_kind)) def generate_diff(self): - buf = StringIO.StringIO() + buf = io.StringIO() if self.tgt_kind == svn.core.svn_node_dir: self._generate_dir_diff(buf) else: @@ -767,7 +767,7 @@ class TxnNodeProcessor(object): def _update_file_properties(self): properties = self.node.get('properties', {}) - for key, value in properties.iteritems(): + for key, value in properties.items(): svn.fs.change_node_prop( self.txn_root, self.node['path'], key, value) diff --git a/vcsserver/tests/test_hooks.py b/vcsserver/tests/test_hooks.py --- a/vcsserver/tests/test_hooks.py +++ b/vcsserver/tests/test_hooks.py @@ -18,8 +18,8 @@ import contextlib import io import threading -from BaseHTTPServer import BaseHTTPRequestHandler -from SocketServer import TCPServer +from http.server import BaseHTTPRequestHandler +from socketserver import TCPServer import mercurial.ui import mock