我可以移动 beaker.SessionMiddleware 以某种方式处理方法吗?
很多行代码落入 "__main__"
中,这有点难看。 有人可以给我一些关于如何将 SessionMiddleware 移动到句柄方法中的提示吗? 我应该注意到我在 CoreXmlParser 中使用了会话。 提前致谢 !
def handle(environ, start_response):
req = webob.Request(environ)
c = CoreXmlParser(req)
resp = webob.Response(body=c(), charset = 'utf-8', status='200 OK', \
request=req, content_type='text/xml')
resp(environ, start_response)
return resp.app_iter
if __name__ == '__main__':
#parse config file for session options
app = SessionMiddleware(handle, some_session_opts_here)
from flup.server.fcgi import WSGIServer
WSGIServer(app).run()
It's a bit ugly that many lines of code fall into "__main__"
.
Can someone give me a tip of how to move SessionMiddleware into handle method?
I should notice that I use session in CoreXmlParser.
Thanks in advance !
def handle(environ, start_response):
req = webob.Request(environ)
c = CoreXmlParser(req)
resp = webob.Response(body=c(), charset = 'utf-8', status='200 OK', \
request=req, content_type='text/xml')
resp(environ, start_response)
return resp.app_iter
if __name__ == '__main__':
#parse config file for session options
app = SessionMiddleware(handle, some_session_opts_here)
from flup.server.fcgi import WSGIServer
WSGIServer(app).run()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解您为什么要尝试只移动一行。如果您想减少“
__main__
”中的内容量,为什么不将所有“#parse config file
”内容移至单独的函数中呢?I'm not sure I understand why you're trying to move just one line. If you want to reduce the amount of stuff in "
__main__
", why not just move all that "#parse config file
" stuff into a separate function?