Paste
这个Paste Deploy就是为了从配置文件生成一个WSGI的APP,如果说我有一个pipeline是这个样子滴:
1 | pipeline = filter01 filter02 app |
---|---|
filter01对应的是TEST:filter01_factory
filter02对应的是TEST:filter02_factory
app对应的是TEST:app_factory
相关的代码可以是:
def filter01_factory(global_conf, XXX):
def filter(app):
return Filter01(app)
return filter
class Filter01(object):
def __init__(self, app,):
self.app = app
def __call__(self, environ, start_response):
if "满足某个条件":
return self.app(environ, start_response)
start_response(
'403 Forbidden', [('Content-type', 'text/html')])
return ['You are forbidden to view this resource']
def filter02_factory(global_conf, XXX):
def filter(app):
return Filter02(app)
return filter
class Filter02(object):
def __init__(self, app,):
self.app = app
def __call__(self, environ, start_response):
if "满足某个条件":
return self.app(environ, start_response)
start_response(
'403 Forbidden', [('Content-type', 'text/html')])
return ['You are forbidden to view this resource']
def app_factory(global_config, **local_conf):
return WSGI_APP #一个真正干活的的WSGI APP,符合WSGI的标准
那么根据上面的总结,paste会的生成如下的代码:
WSGI_APP = app_factory(XXX)
FILTER01 = filter01_factory(XXX)
FILTER02 = filter02_factory(XXX)
CALLABLE_WSGI_APP = FILTER02(FILTER01(WSGI_APP))#实际的请求格式会的是CALLABLE_WSGI_APP(XXX,XXX),这里的CALLABLE_WSGI_APP实际上变成了Filter02
s = Server(CALLABLE_WSGI_APP, host=host, port=port)
s.serve_forever()
what is pipeline?
Pipeline模型最早被使用在Unix
中。据称,如果说Unix是计算机文明中最伟大的发明,那么,Unix下的Pipe管道就是跟随Unix所带来的另一个伟大的发明【1】。我认为管道的出现,所要解决的问题,还是软件设计中老生常谈的设计目标——高内聚,低耦合。它以一种“链式模型”来串接不同的程序或者不同的组件,让它们组成一条直线的工作流。这样给定一个完整的输入,经过各个组件的先后协同处理,得到唯一的最终输出。
参考链接:
http://blog.csdn.net/yanghua_kobe/article/details/7561016(Pipeline管道模型)