Patchwork [4,of,8,py3] pycompat: define urlreq.urlparse and urlreq.unparse aliases

login
register
mail settings
Submitter Gregory Szorc
Date March 22, 2017, 5:56 a.m.
Message ID <0082c745f5a97449d8a0.1490162201@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/19555/
State Accepted
Headers show

Comments

Gregory Szorc - March 22, 2017, 5:56 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1490160857 25200
#      Tue Mar 21 22:34:17 2017 -0700
# Node ID 0082c745f5a97449d8a0f9e3bf00db1ebdacedde
# Parent  242fec51a193b396f1783383d830d97babad9208
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.

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -287,6 +287,7 @@  if not ispy3:
     import SimpleHTTPServer
     import urllib2
     import urllib
+    import urlparse
     urlreq._registeraliases(urllib, (
         "addclosehook",
         "addinfourl",
@@ -317,6 +318,10 @@  if not ispy3:
         "Request",
         "urlopen",
     ))
+    urlreq._registeraliases(urlparse, (
+        "urlparse",
+        "urlunparse",
+    ))
     urlerr._registeraliases(urllib2, (
         "HTTPError",
         "URLError",
@@ -339,6 +344,8 @@  else:
         "splitpasswd",
         "splitport",
         "splituser",
+        "urlparse",
+        "urlunparse",
     ))
     urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote")
     import urllib.request