本文整理匯總了Python中pyramid.response.FileResponse.md5_etag方法的典型用法代碼示例。如果您正苦於以下問題:Python FileResponse.md5_etag方法的具體用法?Python FileResponse.md5_etag怎麽用?Python FileResponse.md5_etag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyramid.response.FileResponse
的用法示例。
在下文中一共展示了FileResponse.md5_etag方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: whitenoise_tween
# 需要導入模塊: from pyramid.response import FileResponse [as 別名]
# 或者: from pyramid.response.FileResponse import md5_etag [as 別名]
def whitenoise_tween(request):
whn = request.registry.whitenoise
if whn.autorefresh:
static_file = whn.find_file(request.path_info)
else:
static_file = whn.files.get(request.path_info)
# We could not find a static file, so we'll just continue processing
# this as normal.
if static_file is None:
return handler(request)
request_headers = dict(kv for kv in request.environ.items() if kv[0].startswith("HTTP_"))
if request.method not in {"GET", "HEAD"}:
return HTTPMethodNotAllowed()
else:
path, headers = static_file.get_path_and_headers(request_headers)
headers = MultiDict(headers)
resp = FileResponse(
path,
request=request,
content_type=headers.pop("Content-Type", None),
content_encoding=headers.pop("Content-Encoding", None),
)
resp.md5_etag()
resp.headers.update(headers)
return resp