[PATCH 2 of 5] py3: conditionalize the urlparse import

Pulkit Goyal 7895pulkit at gmail.com
Mon Jun 27 09:46:41 EDT 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1467024370 -19800
#      Mon Jun 27 16:16:10 2016 +0530
# Node ID dd47675f5ea2c782b2ef09a7bd0dcec18757d374
# Parent  491b9dd3ec4d6567358122b3008a7821f18d9a15
py3: conditionalize the urlparse import

The urlparse library is renamed to urllib.parse in python 3

diff -r 491b9dd3ec4d -r dd47675f5ea2 hgext/bugzilla.py
--- a/hgext/bugzilla.py	Mon Jun 27 15:53:38 2016 +0530
+++ b/hgext/bugzilla.py	Mon Jun 27 16:16:10 2016 +0530
@@ -281,7 +281,6 @@
 
 import re
 import time
-import urlparse
 import xmlrpclib
 
 from mercurial.i18n import _
@@ -293,6 +292,8 @@
     util,
 )
 
+urlparse = util.urlparse
+
 # Note for extension authors: ONLY specify testedwith = 'internal' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
diff -r 491b9dd3ec4d -r dd47675f5ea2 mercurial/pycompat.py
--- a/mercurial/pycompat.py	Mon Jun 27 15:53:38 2016 +0530
+++ b/mercurial/pycompat.py	Mon Jun 27 16:16:10 2016 +0530
@@ -18,6 +18,13 @@
     pickle.dumps # silence pyflakes
 
 try:
+    import urlparse
+    urlparse.urlparse
+except ImportError:
+    import urllib.parse as urlparse
+    urlparse.urlparse
+
+try:
     import cStringIO as io
     stringio = io.StringIO
 except ImportError:
diff -r 491b9dd3ec4d -r dd47675f5ea2 mercurial/util.py
--- a/mercurial/util.py	Mon Jun 27 15:53:38 2016 +0530
+++ b/mercurial/util.py	Mon Jun 27 16:16:10 2016 +0530
@@ -50,6 +50,7 @@
     'pickle',
     'queue',
     'urlerr',
+    'urlparse',
     # we do import urlreq, but we do it outside the loop
     #'urlreq',
     'stringio',
diff -r 491b9dd3ec4d -r dd47675f5ea2 tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t	Mon Jun 27 15:53:38 2016 +0530
+++ b/tests/test-check-py3-compat.t	Mon Jun 27 16:16:10 2016 +0530
@@ -26,7 +26,7 @@
   doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
   hgext/automv.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
   hgext/blackbox.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
-  hgext/bugzilla.py: error importing module: <ImportError> No module named 'urlparse' (line *) (glob)
+  hgext/bugzilla.py: error importing module: <ImportError> No module named 'xmlrpclib' (line *) (glob)
   hgext/censor.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/chgserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
   hgext/children.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
diff -r 491b9dd3ec4d -r dd47675f5ea2 tests/tinyproxy.py
--- a/tests/tinyproxy.py	Mon Jun 27 15:53:38 2016 +0530
+++ b/tests/tinyproxy.py	Mon Jun 27 16:16:10 2016 +0530
@@ -20,7 +20,10 @@
 import select
 import socket
 import sys
-import urlparse
+
+from mercurial import util
+
+urlparse = util.urlparse
 
 class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
     __base = BaseHTTPServer.BaseHTTPRequestHandler


More information about the Mercurial-devel mailing list