代码: 全选
#!/usr/bin/python2.4
# -*- coding: utf-8 -*-
#定义8000端口及/www服务目录可自己更改
import SimpleHTTPServer
import SocketServer
import os
PORT = 8000
WEBDIR = "/www"
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def translate_path(self, path):
os.chdir(WEBDIR)
return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self,path)
try:
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "dir %s serving at port %s"%(repr(WEBDIR), PORT)
httpd.serve_forever()
except:pass