changeset 29432:34b914ac573e

py3: conditionalize xmlrpclib import The xmlrpclib library is renamed to xmlrpc.client in python 3
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 27 Jun 2016 16:37:37 +0530
parents 80880ad3fccd
children 33770d2b6cf9
files hgext/bugzilla.py mercurial/pycompat.py mercurial/util.py tests/test-check-py3-compat.t
diffstat 4 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/bugzilla.py	Mon Jun 27 16:16:10 2016 +0530
+++ b/hgext/bugzilla.py	Mon Jun 27 16:37:37 2016 +0530
@@ -281,7 +281,6 @@
 
 import re
 import time
-import xmlrpclib
 
 from mercurial.i18n import _
 from mercurial.node import short
@@ -293,6 +292,7 @@
 )
 
 urlparse = util.urlparse
+xmlrpclib = util.xmlrpclib
 
 # Note for extension authors: ONLY specify testedwith = 'internal' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
--- a/mercurial/pycompat.py	Mon Jun 27 16:16:10 2016 +0530
+++ b/mercurial/pycompat.py	Mon Jun 27 16:37:37 2016 +0530
@@ -18,6 +18,13 @@
     pickle.dumps # silence pyflakes
 
 try:
+    import xmlrpclib
+    xmlrpclib.Transport
+except ImportError:
+    import xmlrpc.client as xmlrpclib
+    xmlrpclib.Transport
+
+try:
     import urlparse
     urlparse.urlparse
 except ImportError:
--- a/mercurial/util.py	Mon Jun 27 16:16:10 2016 +0530
+++ b/mercurial/util.py	Mon Jun 27 16:37:37 2016 +0530
@@ -54,6 +54,7 @@
     # we do import urlreq, but we do it outside the loop
     #'urlreq',
     'stringio',
+    'xmlrpclib',
 ):
     globals()[attr] = getattr(pycompat, attr)
 
--- a/tests/test-check-py3-compat.t	Mon Jun 27 16:16:10 2016 +0530
+++ b/tests/test-check-py3-compat.t	Mon Jun 27 16:37:37 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 'xmlrpclib' (line *) (glob)
+  hgext/bugzilla.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (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)