# HG changeset patch # User timeless <timeless@gmail.com> # Date 1583511586 -3600 # Fri Mar 06 17:19:46 2020 +0100 # Node ID 8a327480a72014b1d1868ea2fc894b40cb12bc55 # Parent 771ff61ff20b9a687307833c50289539fd46fdcf py3: replace urllib.quote and urllib.unquote diff --git a/hggit/compat.py b/hggit/compat.py --- a/hggit/compat.py +++ b/hggit/compat.py @@ -42,6 +42,9 @@ except NameError: from mercurial.pycompat import unicode +quote = hgutil.urlreq.quote +unquote = hgutil.urlreq.unquote + def gitvfs(repo): """return a vfs suitable to read git related data""" diff --git a/hggit/git2hg.py b/hggit/git2hg.py --- a/hggit/git2hg.py +++ b/hggit/git2hg.py @@ -2,7 +2,6 @@ from __future__ import absolute_import, print_function -import urllib from dulwich.objects import Commit, Tag from . import compat @@ -129,7 +128,7 @@ branch = data if command == b'extra': k, v = data.split(b" : ", 1) - extra[k] = urllib.unquote(v) + extra[k] = compat.unquote(v) git_fn = 0 for field, data in git_extra: @@ -139,16 +138,16 @@ command = field[3:] if command == b'rename': before, after = data.split(b':', 1) - renames[urllib.unquote(after)] = urllib.unquote(before) + renames[compat.unquote(after)] = compat.unquote(before) elif command == b'extra': k, v = data.split(b':', 1) - extra[urllib.unquote(k)] = urllib.unquote(v) + extra[compat.unquote(k)] = compat.unquote(v) else: # preserve ordering in Git by using an incrementing integer for # each field. Note that extra metadata in Git is an ordered list # of pairs. hg_field = b'GIT%d-%s' % (git_fn, field) git_fn += 1 - extra[urllib.quote(hg_field)] = urllib.quote(data) + extra[compat.quote(hg_field)] = compat.quote(data) return (message, renames, branch, extra) diff --git a/hggit/git_handler.py b/hggit/git_handler.py --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -4,7 +4,6 @@ import itertools import io import os -import urllib import re from dulwich.errors import HangupException, GitProtocolError @@ -686,7 +685,7 @@ name = self.get_valid_git_username_email(a.group(1)) email = self.get_valid_git_username_email(a.group(2)) if a.group(3) is not None and len(a.group(3)) != 0: - name += b' ext:(' + urllib.quote(a.group(3)) + b')' + name += b' ext:(' + compat.quote(a.group(3)) + b')' author = b'%s <%s>'\ % (self.get_valid_git_username_email(name), self.get_valid_git_username_email(email)) @@ -751,7 +750,7 @@ git_extraitems.sort() for i, field, value in git_extraitems: - git_extra.append((urllib.unquote(field), urllib.unquote(value))) + git_extra.append((compat.unquote(field), compat.unquote(value))) if extra.get(b'hg-git-rename-source', None) != b'git': renames = [] @@ -768,8 +767,8 @@ extra_message += (b"rename : " + oldfile + b" => " + newfile + b"\n") else: - spec = b'%s:%s' % (urllib.quote(oldfile), - urllib.quote(newfile)) + spec = b'%s:%s' % (compat.quote(oldfile), + compat.quote(newfile)) git_extra.append((b'HG:rename', spec)) # hg extra items always go at the end @@ -780,10 +779,10 @@ else: if extra_in_message: extra_message += (b"extra : " + key + b" : " + - urllib.quote(value) + b"\n") + compat.quote(value) + b"\n") else: - spec = b'%s:%s' % (urllib.quote(key), - urllib.quote(value)) + spec = b'%s:%s' % (compat.quote(key), + compat.quote(value)) git_extra.append((b'HG:extra', spec)) if extra_message: @@ -925,7 +924,7 @@ m = RE_GIT_AUTHOR_EXTRA.match(commit.author) if m: name = m.group(1) - ex = urllib.unquote(m.group(2)) + ex = compat.unquote(m.group(2)) email = m.group(3) author = name + b' <' + email + b'>' + ex diff --git a/hggit/util.py b/hggit/util.py --- a/hggit/util.py +++ b/hggit/util.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, print_function import re -import urllib try: from collections import OrderedDict @@ -146,7 +145,7 @@ Raises an error.Abort when the url is unsafe. """ - host = urllib.unquote(host) + host = compat.unquote(host) if host.startswith(b'-'): raise error.Abort(_(b'potentially unsafe hostname: %r') % (host,))