百度空间 | 百度首页 
 
查看文章
 
PYTHON 指定目录的WEB服务器
2008年12月22日 星期一 12:16
#!/usr/bin/env python
#coding=utf-8
####################################################
#文件文明:pp2pwebserver.py
#创建时间:2008年12月15日
#程序功能:初始化一个p2p网络web服务器
#文件作者:ixafei
#联系方式:ixafei@gmail.com
#####################################################
def makeWS(WSDIR = "G:/pp2p/src",WSPORT=9090):
    import SimpleHTTPServer
    import SocketServer
    import os
    class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
        def translate_path(self, path):
            os.chdir(WSDIR)
            return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self,path)
       
    try:
        httpd = SocketServer.TCPServer(("", WSPORT), Handler)
        print "dir %s serving at port %s"%(repr(WSDIR), WSPORT)
        httpd.serve_forever()
    except:
        pass

makeWS()

类别:Python | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu