|
6 | 6 | and HEAD requests in a fairly straightforward manner.
|
7 | 7 | """
|
8 | 8 |
|
9 |
| -__version__ = "0.3.0" |
| 9 | +__version__ = "0.3.1" |
10 | 10 | __author__ = "freelamb@126.com"
|
11 | 11 | __all__ = ["SimpleHTTPRequestHandler"]
|
12 | 12 |
|
|
32 | 32 | from http.server import BaseHTTPRequestHandler
|
33 | 33 | else:
|
34 | 34 | # Python2
|
| 35 | + reload(sys) |
| 36 | + sys.setdefaultencoding('utf-8') |
35 | 37 | from urllib import quote
|
36 | 38 | from urllib import unquote
|
37 | 39 | from BaseHTTPServer import HTTPServer
|
@@ -205,8 +207,7 @@ def list_directory(self, path):
|
205 | 207 | if os.path.islink(fullname):
|
206 | 208 | display_name = name + "@"
|
207 | 209 | # Note: a link to a directory displays with @ and links with /
|
208 |
| - f.write(b'<li><a href="%s">%s</a>\n' % |
209 |
| - (quote(linkname).encode('utf-8'), escape(display_name).encode('utf-8'))) |
| 210 | + f.write(b'<li><a href="%s">%s</a>\n' % (quote(linkname).encode('utf-8'), escape(display_name).encode('utf-8'))) |
210 | 211 | f.write(b"</ul>\n<hr>\n</body>\n</html>\n")
|
211 | 212 | length = f.tell()
|
212 | 213 | f.seek(0)
|
@@ -289,6 +290,7 @@ def main():
|
289 | 290 | httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
|
290 | 291 | server = httpd.socket.getsockname()
|
291 | 292 | print("server_version: " + SimpleHTTPRequestHandler.server_version + ", python_version: " + SimpleHTTPRequestHandler.sys_version)
|
| 293 | + print("sys encoding: " + sys.getdefaultencoding()) |
292 | 294 | print("Serving http on: " + str(server[0]) + ", port: " + str(server[1]) + " ... (http://" + server[0] + ":" + str(server[1]) + "/)")
|
293 | 295 | httpd.serve_forever()
|
294 | 296 |
|
|
0 commit comments