Mercurial > hg
changeset 31566:c6df6a23dfe5
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 21 Mar 2017 22:20:11 -0700 |
parents | 553ad16b274f |
children | 4ebecf331d7d |
files | mercurial/pycompat.py |
diffstat | 1 files changed, 5 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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",