# HG changeset patch # User Gregory Szorc # Date 2017-03-22 05:20:11 # Node ID c6df6a23dfe5f9893173d640a32780be5184d84a # Parent 553ad16b274f578b2cfe0c714113973edba1129e 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",