pycompat: alias urlreq.unquote to unquote_to_bytes
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 21 Mar 2017 22:20:11 -0700
changeset 31572 c6df6a23dfe5
parent 31571 553ad16b274f
child 31573 4ebecf331d7d
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.
mercurial/pycompat.py
--- a/mercurial/pycompat.py	Sun Mar 19 01:03:53 2017 -0400
+++ b/mercurial/pycompat.py	Tue Mar 21 22:20:11 2017 -0700
@@ -268,6 +268,10 @@
             (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 @@
         "splitpasswd",
         "splitport",
         "splituser",
-        "unquote",
     ))
+    urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote")
     import urllib.request
     urlreq._registeraliases(urllib.request, (
         "AbstractHTTPHandler",