Fix httpserver and socketserver compatibility with py3

This commit is contained in:
sloria
2014-07-10 21:42:40 -04:00
parent 6ff32de768
commit 5fe3c93476
3 changed files with 15 additions and 6 deletions

View File

@@ -10,6 +10,11 @@ if PY2:
urlparse = urlparse
urlunparse = urlunparse
import SimpleHTTPServer as httpserver
httpserver = httpserver
import SocketServer
socketserver = SocketServer
text_type = unicode
binary_type = str
string_types = (str, unicode)
@@ -21,6 +26,11 @@ else: # PY3
urlparse = urlparse
urlunparse = urlunparse
import http.server as httpserver
httpserver = httpserver
import socketserver
socketserver = socketserver
text_type = str
binary_type = bytes
string_types = (str,)

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env python
#coding: utf-8
from __future__ import print_function
from mkdocs.build import build
from mkdocs.config import load_config
@@ -36,8 +37,7 @@ def main(cmd, args, options=None):
elif cmd == 'new':
new(args, options)
else:
print 'mkdocs [help|new|build|serve|gh-deploy] {options}'
print('mkdocs [help|new|build|serve|gh-deploy] {options}')
if __name__ == '__main__':
cmd = sys.argv[1] if len(sys.argv) >= 2 else None

View File

@@ -3,11 +3,10 @@ from __future__ import print_function
from watchdog import events, observers
from mkdocs.build import build
from mkdocs.compat import httpserver, socketserver
from mkdocs.config import load_config
import os
import posixpath
import SimpleHTTPServer
import SocketServer
import shutil
import sys
import tempfile
@@ -39,7 +38,7 @@ class ConfigEventHandler(BuildEventHandler):
super(ConfigEventHandler, self).on_any_event(event)
class FixedDirectoryHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class FixedDirectoryHandler(httpserver.SimpleHTTPRequestHandler):
"""
Override the default implementation to allow us to specify the served
directory, instead of being hardwired to the current working directory.
@@ -89,7 +88,7 @@ def serve(config, options=None):
observer.schedule(config_event_handler, '.')
observer.start()
class TCPServer(SocketServer.TCPServer):
class TCPServer(socketserver.TCPServer):
allow_reuse_address = True
class DocsDirectoryHandler(FixedDirectoryHandler):