本文整理汇总了Python中swift.common.swob.Response.headers["etag"]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers["etag"]方法的具体用法?Python Response.headers["etag"]怎么用?Python Response.headers["etag"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.Response
的用法示例。
在下文中一共展示了Response.headers["etag"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: best_response
# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["etag"] [as 别名]
def best_response(self, req, statuses, reasons, bodies, server_type, etag=None, headers=None):
"""
Given a list of responses from several servers, choose the best to
return to the API.
:param req: swob.Request object
:param statuses: list of statuses returned
:param reasons: list of reasons for each status
:param bodies: bodies of each response
:param server_type: type of server the responses came from
:param etag: etag
:param headers: headers of each response
:returns: swob.Response object with the correct status, body, etc. set
"""
resp = Response(request=req)
if len(statuses):
for hundred in (HTTP_OK, HTTP_MULTIPLE_CHOICES, HTTP_BAD_REQUEST):
hstatuses = [s for s in statuses if hundred <= s < hundred + 100]
if len(hstatuses) >= quorum_size(len(statuses)):
status = max(hstatuses)
status_index = statuses.index(status)
resp.status = "%s %s" % (status, reasons[status_index])
resp.body = bodies[status_index]
if headers:
update_headers(resp, headers[status_index])
if etag:
resp.headers["etag"] = etag.strip('"')
return resp
self.app.logger.error(_("%(type)s returning 503 for %(statuses)s"), {"type": server_type, "statuses": statuses})
resp.status = "503 Internal Server Error"
return resp