Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 5409:277e91bf7936
Python 3 preparation: update BaseHTTPServer imports.
roundup/anypy/http_.py extended and used in more places. Manual
patch.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 00:17:07 +0000 |
| parents | 56cc58d20add |
| children | d0816d50ee8f |
comparison
equal
deleted
inserted
replaced
| 5408:e46ce04d5bbc | 5409:277e91bf7936 |
|---|---|
| 35 sys.path.insert(0, rootdir) | 35 sys.path.insert(0, rootdir) |
| 36 # --/ | 36 # --/ |
| 37 | 37 |
| 38 | 38 |
| 39 import errno, cgi, getopt, os, socket, sys, traceback, time | 39 import errno, cgi, getopt, os, socket, sys, traceback, time |
| 40 import BaseHTTPServer, SocketServer, StringIO | 40 import SocketServer, StringIO |
| 41 | 41 |
| 42 try: | 42 try: |
| 43 # Python 2. | 43 # Python 2. |
| 44 reload | 44 reload |
| 45 except NameError: | 45 except NameError: |
| 54 # python version check | 54 # python version check |
| 55 from roundup import configuration, version_check | 55 from roundup import configuration, version_check |
| 56 from roundup import __version__ as roundup_version | 56 from roundup import __version__ as roundup_version |
| 57 | 57 |
| 58 # Roundup modules of use here | 58 # Roundup modules of use here |
| 59 from roundup.anypy import urllib_ | 59 from roundup.anypy import http_, urllib_ |
| 60 from roundup.cgi import cgitb, client | 60 from roundup.cgi import cgitb, client |
| 61 from roundup.cgi.PageTemplates.PageTemplate import PageTemplate | 61 from roundup.cgi.PageTemplates.PageTemplate import PageTemplate |
| 62 import roundup.instance | 62 import roundup.instance |
| 63 from roundup.i18n import _ | 63 from roundup.i18n import _ |
| 64 | 64 |
| 114 ctx.use_privatekey(pkey) | 114 ctx.use_privatekey(pkey) |
| 115 ctx.use_certificate(cert) | 115 ctx.use_certificate(cert) |
| 116 | 116 |
| 117 return ctx | 117 return ctx |
| 118 | 118 |
| 119 class SecureHTTPServer(BaseHTTPServer.HTTPServer): | 119 class SecureHTTPServer(http_.server.HTTPServer): |
| 120 def __init__(self, server_address, HandlerClass, ssl_pem=None): | 120 def __init__(self, server_address, HandlerClass, ssl_pem=None): |
| 121 assert SSL, "pyopenssl not installed" | 121 assert SSL, "pyopenssl not installed" |
| 122 BaseHTTPServer.HTTPServer.__init__(self, server_address, HandlerClass) | 122 http_.server.HTTPServer.__init__(self, server_address, HandlerClass) |
| 123 self.socket = socket.socket(self.address_family, self.socket_type) | 123 self.socket = socket.socket(self.address_family, self.socket_type) |
| 124 if ssl_pem: | 124 if ssl_pem: |
| 125 ctx = SSL.Context(SSL.SSLv23_METHOD) | 125 ctx = SSL.Context(SSL.SSLv23_METHOD) |
| 126 ctx.use_privatekey_file(ssl_pem) | 126 ctx.use_privatekey_file(ssl_pem) |
| 127 ctx.use_certificate_file(ssl_pem) | 127 ctx.use_certificate_file(ssl_pem) |
| 175 return getattr(self.__conn, attrib) | 175 return getattr(self.__conn, attrib) |
| 176 | 176 |
| 177 conn = ConnFixer(conn) | 177 conn = ConnFixer(conn) |
| 178 return (conn, info) | 178 return (conn, info) |
| 179 | 179 |
| 180 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): | 180 class RoundupRequestHandler(http_.server.BaseHTTPRequestHandler): |
| 181 TRACKER_HOMES = {} | 181 TRACKER_HOMES = {} |
| 182 TRACKERS = None | 182 TRACKERS = None |
| 183 LOG_IPADDRESS = 1 | 183 LOG_IPADDRESS = 1 |
| 184 DEBUG_MODE = False | 184 DEBUG_MODE = False |
| 185 CONFIG = None | 185 CONFIG = None |
| 455 (self.client_address[0], | 455 (self.client_address[0], |
| 456 self.log_date_time_string(), | 456 self.log_date_time_string(), |
| 457 format%args)) | 457 format%args)) |
| 458 else: | 458 else: |
| 459 try: | 459 try: |
| 460 BaseHTTPServer.BaseHTTPRequestHandler.log_message(self, | 460 http_.server.BaseHTTPRequestHandler.log_message(self, |
| 461 format, *args) | 461 format, *args) |
| 462 except IOError: | 462 except IOError: |
| 463 # stderr is no longer viable | 463 # stderr is no longer viable |
| 464 pass | 464 pass |
| 465 | 465 |
| 700 # time out after a minute if we can | 700 # time out after a minute if we can |
| 701 # This sets the socket to non-blocking. SSL needs a blocking | 701 # This sets the socket to non-blocking. SSL needs a blocking |
| 702 # socket, so we do this only for non-SSL connections. | 702 # socket, so we do this only for non-SSL connections. |
| 703 if hasattr(socket, 'setdefaulttimeout'): | 703 if hasattr(socket, 'setdefaulttimeout'): |
| 704 socket.setdefaulttimeout(60) | 704 socket.setdefaulttimeout(60) |
| 705 base_server = BaseHTTPServer.HTTPServer | 705 base_server = http_.server.HTTPServer |
| 706 | 706 |
| 707 # obtain request server class | 707 # obtain request server class |
| 708 if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES: | 708 if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES: |
| 709 print(_("Multiprocess mode \"%s\" is not available, " | 709 print(_("Multiprocess mode \"%s\" is not available, " |
| 710 "switching to single-process") % self["MULTIPROCESS"]) | 710 "switching to single-process") % self["MULTIPROCESS"]) |
