changeset 31575:e68932dfbb55

pycompat: define urlreq.urlparse and urlreq.unparse aliases Currently, we export urlparse via util.urlparse then call util.urlparse.urlparse() and util.urlparse.urlunparse() in a few places. This is the only url* module exported from pycompat, making it a one-off. So let's transition to urlreq to match everything else. Yes, we double import "urlparse" now on Python 2. This will be cleaned up in a subsequent patch. Also, the Python 3 functions trade in str/unicode not bytes. So we'll likely need to write a custom implementation that speaks bytes. But moving everyone to an abstracted API is a good first step.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 21 Mar 2017 22:34:17 -0700
parents 6c9772867344
children 29fcfb981324
files mercurial/pycompat.py
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pycompat.py	Tue Mar 21 22:28:16 2017 -0700
+++ b/mercurial/pycompat.py	Tue Mar 21 22:34:17 2017 -0700
@@ -287,6 +287,7 @@
     import SimpleHTTPServer
     import urllib2
     import urllib
+    import urlparse
     urlreq._registeraliases(urllib, (
         "addclosehook",
         "addinfourl",
@@ -317,6 +318,10 @@
         "Request",
         "urlopen",
     ))
+    urlreq._registeraliases(urlparse, (
+        "urlparse",
+        "urlunparse",
+    ))
     urlerr._registeraliases(urllib2, (
         "HTTPError",
         "URLError",
@@ -339,6 +344,8 @@
         "splitpasswd",
         "splitport",
         "splituser",
+        "urlparse",
+        "urlunparse",
     ))
     urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote")
     import urllib.request