[python]代码库
from wsgiref.simple_server import make_server
from webob import Request,Response,dec
def index(request:Request) -> Response:
res = Response()
res.body = "<h1>马哥教育欢迎你们大家</h1>".encode()
return res
def showpython(request:Request):
res = Response()
res.body = "<h1>马哥教育Python欢迎你们大家</h1>".encode()
return res
def notfound(request:Request):
res = Response()
res.status_code = 404
res.body = "Not Found".encode()
return res
ROUTETABLE = {
"/" : index,
"/python" : showpython,
}
@dec.wsgify
def app(request:Request) -> Response:
ROUTETABLE.get(request.path,notfound)(request)
if __name__ == '__main__':
ip = '127.0.0.1'
port = 9999
server = make_server(ip,port,app)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
finally:
server.server_close()