python3: make coffee build

add polyglot.socketserver wrapper and fix BaseHTTPServer.HTTPServer
This commit is contained in:
Eli Schwartz 2019-03-21 00:24:47 -04:00
parent c940d9941a
commit 45f68f552b
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
5 changed files with 21 additions and 14 deletions

View File

@ -241,9 +241,9 @@ class Manual(Command):
def serve_manual(self, root): def serve_manual(self, root):
os.chdir(root) os.chdir(root)
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer ServerClass = HTTPServer
Protocol = "HTTP/1.0" Protocol = "HTTP/1.0"
server_address = ('127.0.0.1', 8000) server_address = ('127.0.0.1', 8000)

View File

@ -8,8 +8,8 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, shutil, tempfile import os, shutil, tempfile
import SocketServer
from polyglot import socketserver
from polyglot.http_server import SimpleHTTPRequestHandler from polyglot.http_server import SimpleHTTPRequestHandler
@ -29,7 +29,7 @@ def run_devel_server():
js.write(compile_pyj(f.read()).encode('utf-8')) js.write(compile_pyj(f.read()).encode('utf-8'))
PORT = 8000 PORT = 8000
Handler = SimpleHTTPRequestHandler Handler = SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler) httpd = socketserver.TCPServer(("", PORT), Handler)
print('Serving CFI test at http://localhost:%d' % PORT) print('Serving CFI test at http://localhost:%d' % PORT)
try: try:
httpd.serve_forever() httpd.serve_forever()

View File

@ -13,14 +13,11 @@ A coffeescript compiler and a simple web server that automatically serves
coffeescript files as javascript. coffeescript files as javascript.
''' '''
import sys, traceback, io import sys, traceback, io
if sys.version_info.major > 2: import time, os, sys, re
print('This script is not Python 3 compatible. Run it with Python 2',
file=sys.stderr)
raise SystemExit(1)
import time, os, sys, re, SocketServer
from threading import Lock, local from threading import Lock, local
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler
from polyglot import socketserver
from polyglot.http_server import HTTPServer, SimpleHTTPRequestHandler
# Compiler {{{ # Compiler {{{
@ -255,7 +252,7 @@ class Handler(HTTPRequestHandler): # {{{
# }}} # }}}
class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): # {{{ class Server(socketserver.ThreadingMixIn, HTTPServer): # {{{
daemon_threads = True daemon_threads = True
def handle_error(self, request, client_address): def handle_error(self, request, client_address):

View File

@ -7,7 +7,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
from polyglot.builtins import is_py3 from polyglot.builtins import is_py3
if is_py3: if is_py3:
from http.server import BaseHTTPServer, SimpleHTTPRequestHandler from http.server import HTTPServer, SimpleHTTPRequestHandler
else: else:
import BaseHTTPServer # noqa from BaseHTTPServer import HTTPServer # noqa
from SimpleHTTPServer import SimpleHTTPRequestHandler # noqa from SimpleHTTPServer import SimpleHTTPRequestHandler # noqa

10
src/polyglot/socketserver.py Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
from polyglot.builtins import is_py3
if is_py3:
from socketserver import TCPServer, ThreadingMixIn # noqa
else:
from SocketServer import TCPServer, ThreadingMixIn # noqa