[PATCH 3 of 3] util: make util.py more demandimport friendly

Pulkit Goyal 7895pulkit at gmail.com
Thu Jul 14 05:05:09 EDT 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1468438157 -19800
#      Thu Jul 14 00:59:17 2016 +0530
# Node ID 98d10404151317b62c84832111f851e89c29214f
# Parent  9f7d3de1e00bb71977e58990d637ceb590993fee
util: make util.py more demandimport friendly

There are modules which are renamed it Python 3, we used to add a hack in pycompat.py
and then import it in util, now we have a if-else which checks the python version and imports
 the required module.

diff -r 9f7d3de1e00b -r 98d104041513 mercurial/util.py
--- a/mercurial/util.py	Wed Jul 13 23:38:29 2016 +0530
+++ b/mercurial/util.py	Thu Jul 14 00:59:17 2016 +0530
@@ -45,19 +45,37 @@
     pycompat,
 )
 
+if sys.version_info[0] < 3:
+    import cPickle as pickle
+    import cStringIO as io
+    import httplib
+    import Queue as _queue
+    import SocketServer as socketserver
+    import urlparse
+    import xmlrpclib
+else:
+    import http.client as httplib
+    import io
+    import pickle
+    import queue as _queue
+    import socketserver
+    import urllib.parse as urlparse
+    import xmlrpc.client as xmlrpclib
+
+empty = _queue.Empty
+queue = _queue.Queue
+stringio = io.StringIO
+pickle.dumps
+httplib.HTTPException
+socketserver.ThreadingMixIn
+xmlrpclib.Transport
+urlparse.urlparse
+
 for attr in (
-    'empty',
-    'httplib',
     'httpserver',
-    'pickle',
-    'queue',
     'urlerr',
-    'urlparse',
     # we do import urlreq, but we do it outside the loop
     #'urlreq',
-    'stringio',
-    'socketserver',
-    'xmlrpclib',
 ):
     globals()[attr] = getattr(pycompat, attr)
 


More information about the Mercurial-devel mailing list