WSGI servers-wsgiref

2018-03-08  本文已影响0人  可爱喵星人

WSGI 是一种接口规定,服务器程序 只有实现了这种接口规定,才能和应用端程序(框架)很好的结合。
wsgiref就是一种服务端程序的一种,他在python3 里面内嵌了。

服务端程序

def run(application):
    environ = {}
    def start_response(status, response_headers, exc_info=None):
        pass
    result = application(environ, start_response)
    def write(data):
        pass
    for data in result:
        write(data)
def application(environ,start_response)
      pass
run(application)

wsgiref

wsgiref实现了上面 run的功能。wsgiref.simple_server 提供了相关的方法

参考

服务端程序:https://wsgi.readthedocs.io/en/latest/servers.html
wsgiref:https://docs.python.org/3.6/library/wsgiref.html#examples
environ-variables一览:https://www.python.org/dev/peps/pep-0333/#environ-variables

上一篇 下一篇

猜你喜欢

热点阅读