[PATCH 1 of 8 py3] pycompat: alias urlreq.unquote to unquote_to_bytes
Gregory Szorc
gregory.szorc at gmail.com
Wed Mar 22 05:56:38 UTC 2017
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1490160011 25200
# Tue Mar 21 22:20:11 2017 -0700
# Node ID 285f48d5644ea070f717473af077e6728df6ea82
# Parent 102f291807c92864a2231e5e925d6cd64783bb59
pycompat: alias urlreq.unquote to unquote_to_bytes
Previously, urlreq.unquote aliased to urllib.parse.unquote,
which returned a str/unicode. We like bytes, so switch urlreq.unquote
to dispatch to urllib.parse.unquote_to_bytes.
This required a minor helper function to register an alias under a
different name from which it points. If this turns into a common
pattern, we could likely teach _registeralias to accept tuple
values defining the mapping. Until then, I didn't feel like
adding complexity to _registeralias.
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -268,6 +268,10 @@ class _pycompatstub(object):
(item.replace(sysstr('_'), sysstr('')).lower(), (origin, item))
for item in items)
+ def _registeralias(self, origin, attr, name):
+ """Alias ``origin``.``attr`` as ``name``"""
+ self._aliases[sysstr(name)] = (origin, sysstr(attr))
+
def __getattr__(self, name):
try:
origin, item = self._aliases[name]
@@ -337,8 +341,8 @@ else:
"splitpasswd",
"splitport",
"splituser",
- "unquote",
))
+ urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote")
import urllib.request
urlreq._registeraliases(urllib.request, (
"AbstractHTTPHandler",
More information about the Mercurial-devel
mailing list