Patchwork [4,of,5] py3: conditionalize SocketServer import

login
register
mail settings
Submitter Pulkit Goyal
Date June 27, 2016, 1:46 p.m.
Message ID <c8e0c9bbb94c18dd71cf.1467035203@pulkit-goyal>
Download mbox | patch
Permalink /patch/15647/
State Accepted
Headers show

Comments

Pulkit Goyal - June 27, 2016, 1:46 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1467026334 -19800
#      Mon Jun 27 16:48:54 2016 +0530
# Node ID c8e0c9bbb94c18dd71cfce4b6223261a7b7097a6
# Parent  1ce001af985fd4012db55f8034addb39234488d8
py3: conditionalize SocketServer import

The SocketServer is renamed to socketserver in python 3

Patch

diff -r 1ce001af985f -r c8e0c9bbb94c hgext/chgserver.py
--- a/hgext/chgserver.py	Mon Jun 27 16:37:37 2016 +0530
+++ b/hgext/chgserver.py	Mon Jun 27 16:48:54 2016 +0530
@@ -40,7 +40,6 @@ 
 
 from __future__ import absolute_import
 
-import SocketServer
 import errno
 import gc
 import hashlib
@@ -67,6 +66,8 @@ 
     util,
 )
 
+socketserver = util.socketserver
+
 # 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
@@ -524,7 +525,7 @@ 
                          'setumask': setumask})
 
 # copied from mercurial/commandserver.py
-class _requesthandler(SocketServer.StreamRequestHandler):
+class _requesthandler(socketserver.StreamRequestHandler):
     def handle(self):
         # use a different process group from the master process, making this
         # process pass kernel "is_current_pgrp_orphaned" check so signals like
@@ -597,7 +598,7 @@ 
 
     def process_request(self, request, address):
         self.lastactive = time.time()
-        return SocketServer.ForkingMixIn.process_request(
+        return socketserver.ForkingMixIn.process_request(
             self, request, address)
 
     def server_bind(self):
@@ -650,8 +651,8 @@ 
             self.repo = None
         self._inithashstate()
         self._checkextensions()
-        class cls(AutoExitMixIn, SocketServer.ForkingMixIn,
-                  SocketServer.UnixStreamServer):
+        class cls(AutoExitMixIn, socketserver.ForkingMixIn,
+                  socketserver.UnixStreamServer):
             ui = self.ui
             repo = self.repo
             hashstate = self.hashstate
diff -r 1ce001af985f -r c8e0c9bbb94c mercurial/commandserver.py
--- a/mercurial/commandserver.py	Mon Jun 27 16:37:37 2016 +0530
+++ b/mercurial/commandserver.py	Mon Jun 27 16:48:54 2016 +0530
@@ -7,7 +7,6 @@ 
 
 from __future__ import absolute_import
 
-import SocketServer
 import errno
 import os
 import struct
@@ -21,6 +20,8 @@ 
     util,
 )
 
+socketserver = util.socketserver
+
 logfile = None
 
 def log(*args):
@@ -330,7 +331,7 @@ 
         finally:
             _restoreio(ui, fin, fout)
 
-class _requesthandler(SocketServer.StreamRequestHandler):
+class _requesthandler(socketserver.StreamRequestHandler):
     def handle(self):
         ui = self.server.ui
         repo = self.server.repo
@@ -366,13 +367,13 @@ 
         self.ui = ui
         self.repo = repo
         self.address = opts['address']
-        if not util.safehasattr(SocketServer, 'UnixStreamServer'):
+        if not util.safehasattr(socketserver, 'UnixStreamServer'):
             raise error.Abort(_('unsupported platform'))
         if not self.address:
             raise error.Abort(_('no socket path specified with --address'))
 
     def init(self):
-        class cls(SocketServer.ForkingMixIn, SocketServer.UnixStreamServer):
+        class cls(socketserver.ForkingMixIn, socketserver.UnixStreamServer):
             ui = self.ui
             repo = self.repo
         self.server = cls(self.address, _requesthandler)
diff -r 1ce001af985f -r c8e0c9bbb94c mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py	Mon Jun 27 16:37:37 2016 +0530
+++ b/mercurial/hgweb/server.py	Mon Jun 27 16:48:54 2016 +0530
@@ -9,7 +9,6 @@ 
 from __future__ import absolute_import
 
 import BaseHTTPServer
-import SocketServer
 import errno
 import os
 import socket
@@ -23,6 +22,7 @@ 
     util,
 )
 
+socketserver = util.socketserver
 urlerr = util.urlerr
 urlreq = util.urlreq
 
@@ -147,9 +147,9 @@ 
         env['wsgi.input'] = self.rfile
         env['wsgi.errors'] = _error_logger(self)
         env['wsgi.multithread'] = isinstance(self.server,
-                                             SocketServer.ThreadingMixIn)
+                                             socketserver.ThreadingMixIn)
         env['wsgi.multiprocess'] = isinstance(self.server,
-                                              SocketServer.ForkingMixIn)
+                                              socketserver.ForkingMixIn)
         env['wsgi.run_once'] = 0
 
         self.saved_status = None
@@ -240,10 +240,10 @@ 
 try:
     import threading
     threading.activeCount() # silence pyflakes and bypass demandimport
-    _mixin = SocketServer.ThreadingMixIn
+    _mixin = socketserver.ThreadingMixIn
 except ImportError:
     if util.safehasattr(os, "fork"):
-        _mixin = SocketServer.ForkingMixIn
+        _mixin = socketserver.ForkingMixIn
     else:
         class _mixin(object):
             pass
diff -r 1ce001af985f -r c8e0c9bbb94c mercurial/pycompat.py
--- a/mercurial/pycompat.py	Mon Jun 27 16:37:37 2016 +0530
+++ b/mercurial/pycompat.py	Mon Jun 27 16:48:54 2016 +0530
@@ -18,6 +18,13 @@ 
     pickle.dumps # silence pyflakes
 
 try:
+    import SocketServer as socketserver
+    socketserver.ThreadingMixIn
+except ImportError:
+    import socketserver
+    socketserver.ThreadingMixIn
+
+try:
     import xmlrpclib
     xmlrpclib.Transport
 except ImportError:
diff -r 1ce001af985f -r c8e0c9bbb94c mercurial/util.py
--- a/mercurial/util.py	Mon Jun 27 16:37:37 2016 +0530
+++ b/mercurial/util.py	Mon Jun 27 16:48:54 2016 +0530
@@ -54,6 +54,7 @@ 
     # we do import urlreq, but we do it outside the loop
     #'urlreq',
     'stringio',
+    'socketserver',
     'xmlrpclib',
 ):
     globals()[attr] = getattr(pycompat, attr)
diff -r 1ce001af985f -r c8e0c9bbb94c tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t	Mon Jun 27 16:37:37 2016 +0530
+++ b/tests/test-check-py3-compat.t	Mon Jun 27 16:48:54 2016 +0530
@@ -28,7 +28,7 @@ 
   hgext/blackbox.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (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/chgserver.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/children.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/churn.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/clonebundles.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
@@ -88,7 +88,6 @@ 
   mercurial/changelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/cmdutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/commands.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
-  mercurial/commandserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
   mercurial/context.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/copies.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/crecord.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
diff -r 1ce001af985f -r c8e0c9bbb94c tests/tinyproxy.py
--- a/tests/tinyproxy.py	Mon Jun 27 16:37:37 2016 +0530
+++ b/tests/tinyproxy.py	Mon Jun 27 16:48:54 2016 +0530
@@ -15,7 +15,6 @@ 
 __version__ = "0.2.1"
 
 import BaseHTTPServer
-import SocketServer
 import os
 import select
 import socket
@@ -24,6 +23,7 @@ 
 from mercurial import util
 
 urlparse = util.urlparse
+socketserver = util.socketserver
 
 class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
     __base = BaseHTTPServer.BaseHTTPRequestHandler
@@ -135,7 +135,7 @@ 
     do_PUT  = do_GET
     do_DELETE = do_GET
 
-class ThreadingHTTPServer (SocketServer.ThreadingMixIn,
+class ThreadingHTTPServer (socketserver.ThreadingMixIn,
                            BaseHTTPServer.HTTPServer):
     def __init__(self, *args, **kwargs):
         BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs)