我有 WSGI 中间件,它需要捕获200 OK中间件的内层通过调用返回的 HTTP 状态(例如)start_response。目前我正在做以下事情,但滥用列表对我来说似乎不是“正确”的解决方案:
类 TransactionalMiddlewareInterface(对象):
def __init__(self, application, **config):
self.application = 应用程序
self.config = 配置
def __call__(self, environ, start_response):
状态 = []
def local_start(stat_str, headers=[]):
status.append(int(stat_str.split('')[0]))
返回 start_response(stat_str, headers)
尝试:
结果 = self.application(环境,local_start)
最后:
状态 = 状态 [0] 如果状态为其他 0
如果状态 > 199 和状态
列表滥用的原因是我无法从完全包含的函数中为父命名空间分配新值。