一个简单的python语言的http服务器
可以实现远程脚本更新等功能#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os,sys
from wsgiref.simple_server import make_server
from getVersion import getGameVersion
reload(sys)
sys.setdefaultencoding('utf8')
def application(environ, start_response):
if (environ['PATH_INFO'])=="updata":
start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8')])
return '<h1>更新成功!</h1>'
elif (environ['PATH_INFO'])=="getVersion":
channel = environ['QUERY_STRING'].split('=')
ret = getGameVersion(channel)
start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8')])
text = ""
for game,info in ret.items():
text = text + '<tr>'
text = text + '<td>' +str(info['name'])+ '</td>'
text = text + '<td>' +str(game)+ '</td>'
text = text + '<td>' +str(info['ver'])+ '</td>'
text = text + '</tr>'
return '<table><thead><tr><th> 游戏名称 </th><th> 游戏ID </th><th> 版本信息 </th></tr></thead><tbody>'+ text+ '</tbody></table>'
else:
start_response('200 ok', [('Content-Type', 'text/html',)])
return '<h1> urlerror</h1>'
httpd = make_server('', 8000, application)
print "Serving HTTP on port 8000..."
httpd.serve_forever()
页:
[1]