py3: conditionalize SocketServer import
The SocketServer is renamed to socketserver in python 3
--- 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
@@ -68,6 +67,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
@@ -530,7 +531,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
@@ -603,7 +604,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):
@@ -656,8 +657,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
--- 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)
--- 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
--- 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:
--- 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)
--- 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)
--- 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)