Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/server.py @ 29566:075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
The BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer has been merged into
http.server in python 3. All of them has been merged as util.httpserver to use
in both python 2 and 3. This patch adds a regex to check-code to warn against
the use of BaseHTTPServer. Moreover this patch also includes updates to lower
part of test-check-py3-compat.t which used to remain unchanged.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 13 Jul 2016 23:38:29 +0530 |
parents | 121d11814c62 |
children | ebc03e64548a |
comparison
equal
deleted
inserted
replaced
29565:143d21a7343e | 29566:075146e85bb6 |
---|---|
6 # This software may be used and distributed according to the terms of the | 6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
8 | 8 |
9 from __future__ import absolute_import | 9 from __future__ import absolute_import |
10 | 10 |
11 import BaseHTTPServer | |
12 import errno | 11 import errno |
13 import os | 12 import os |
14 import socket | 13 import socket |
15 import sys | 14 import sys |
16 import traceback | 15 import traceback |
20 from .. import ( | 19 from .. import ( |
21 error, | 20 error, |
22 util, | 21 util, |
23 ) | 22 ) |
24 | 23 |
24 httpservermod = util.httpserver | |
25 socketserver = util.socketserver | 25 socketserver = util.socketserver |
26 urlerr = util.urlerr | 26 urlerr = util.urlerr |
27 urlreq = util.urlreq | 27 urlreq = util.urlreq |
28 | 28 |
29 from . import ( | 29 from . import ( |
51 self.writelines(str.split('\n')) | 51 self.writelines(str.split('\n')) |
52 def writelines(self, seq): | 52 def writelines(self, seq): |
53 for msg in seq: | 53 for msg in seq: |
54 self.handler.log_error("HG error: %s", msg) | 54 self.handler.log_error("HG error: %s", msg) |
55 | 55 |
56 class _httprequesthandler(BaseHTTPServer.BaseHTTPRequestHandler): | 56 class _httprequesthandler(httpservermod.basehttprequesthandler): |
57 | 57 |
58 url_scheme = 'http' | 58 url_scheme = 'http' |
59 | 59 |
60 @staticmethod | 60 @staticmethod |
61 def preparehttpserver(httpserver, ui): | 61 def preparehttpserver(httpserver, ui): |
62 """Prepare .socket of new HTTPServer instance""" | 62 """Prepare .socket of new HTTPServer instance""" |
63 pass | 63 pass |
64 | 64 |
65 def __init__(self, *args, **kargs): | 65 def __init__(self, *args, **kargs): |
66 self.protocol_version = 'HTTP/1.1' | 66 self.protocol_version = 'HTTP/1.1' |
67 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kargs) | 67 httpservermod.basehttprequesthandler.__init__(self, *args, **kargs) |
68 | 68 |
69 def _log_any(self, fp, format, *args): | 69 def _log_any(self, fp, format, *args): |
70 fp.write("%s - - [%s] %s\n" % (self.client_address[0], | 70 fp.write("%s - - [%s] %s\n" % (self.client_address[0], |
71 self.log_date_time_string(), | 71 self.log_date_time_string(), |
72 format % args)) | 72 format % args)) |
261 def openlog(opt, default): | 261 def openlog(opt, default): |
262 if opt and opt != '-': | 262 if opt and opt != '-': |
263 return open(opt, 'a') | 263 return open(opt, 'a') |
264 return default | 264 return default |
265 | 265 |
266 class MercurialHTTPServer(object, _mixin, BaseHTTPServer.HTTPServer): | 266 class MercurialHTTPServer(object, _mixin, httpservermod.httpserver): |
267 | 267 |
268 # SO_REUSEADDR has broken semantics on windows | 268 # SO_REUSEADDR has broken semantics on windows |
269 if os.name == 'nt': | 269 if os.name == 'nt': |
270 allow_reuse_address = 0 | 270 allow_reuse_address = 0 |
271 | 271 |
272 def __init__(self, ui, app, addr, handler, **kwargs): | 272 def __init__(self, ui, app, addr, handler, **kwargs): |
273 BaseHTTPServer.HTTPServer.__init__(self, addr, handler, **kwargs) | 273 httpservermod.httpserver.__init__(self, addr, handler, **kwargs) |
274 self.daemon_threads = True | 274 self.daemon_threads = True |
275 self.application = app | 275 self.application = app |
276 | 276 |
277 handler.preparehttpserver(self, ui) | 277 handler.preparehttpserver(self, ui) |
278 | 278 |