Patchwork [1,of,2,py3] pycompat: alias urllib symbols directly

login
register
mail settings
Submitter Gregory Szorc
Date March 13, 2017, 7:27 p.m.
Message ID <2b9547ebdfa84c3e96fd.1489433242@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/19298/
State Accepted
Headers show

Comments

Gregory Szorc - March 13, 2017, 7:27 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1489432457 25200
#      Mon Mar 13 12:14:17 2017 -0700
# Node ID 2b9547ebdfa84c3e96fd366e3c09dd24306747d4
# Parent  1c48a8278b2f015fca607dfc652823560a5ac580
pycompat: alias urllib symbols directly

urllib.request imports a bunch of symbols from other urllib
modules. We should map to the original symbols not the
re-exported ones because this is more correct. Also, it
will prevent an import of urllib.request if only one of
the lower-level symbols/modules is needed.

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -267,11 +267,18 @@  if not ispy3:
     ))
 
 else:
+    import urllib.parse
+    urlreq._registeraliases(urllib.parse, (
+        "quote",
+        "splitattr",
+        "splitpasswd",
+        "splitport",
+        "splituser",
+        "unquote",
+    ))
     import urllib.request
     urlreq._registeraliases(urllib.request, (
         "AbstractHTTPHandler",
-        "addclosehook",
-        "addinfourl",
         "BaseHandler",
         "build_opener",
         "FileHandler",
@@ -285,16 +292,15 @@  else:
         "HTTPDigestAuthHandler",
         "HTTPPasswordMgrWithDefaultRealm",
         "ProxyHandler",
-        "quote",
         "Request",
-        "splitattr",
-        "splitpasswd",
-        "splitport",
-        "splituser",
-        "unquote",
         "url2pathname",
         "urlopen",
     ))
+    import urllib.response
+    urlreq._registeraliases(urllib.response, (
+        "addclosehook",
+        "addinfourl",
+    ))
     import urllib.error
     urlerr._registeraliases(urllib.error, (
         "HTTPError",