本文整理匯總了Python中django.utils.http.parse_http_date方法的典型用法代碼示例。如果您正苦於以下問題:Python http.parse_http_date方法的具體用法?Python http.parse_http_date怎麽用?Python http.parse_http_date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.http
的用法示例。
在下文中一共展示了http.parse_http_date方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import parse_http_date [as 別名]
def get(self, request, mode_id=None):
mode_id = int(mode_id)
if not (mode_id in Mode.stat_v1_ids):
return HttpResponse(status=404)
last_updated = to_unix(cache_value("ranking_stats_last_modified", 600, ranking_stats_last_modified))
now = to_unix(utcnow())
try:
if_modified_since = parse_http_date(request.META['HTTP_IF_MODIFIED_SINCE'])
except (ValueError, KeyError):
if_modified_since = 0
if if_modified_since >= last_updated:
response = HttpResponse("", content_type="application/json", status=304)
else:
response = HttpResponse(cache_value("ranking_stats_%d" % mode_id, 600,
rankings_view_client, 'ranking_stats', mode_id),
content_type="application/json")
response['Cache-Control'] = "max-age=86400"
response['Date'] = http_date(now)
response['Expires'] = http_date(now + 86400)
response['Last-Modified'] = http_date(last_updated)
return response
示例2: was_modified_since
# 需要導入模塊: from django.utils import http [as 別名]
# 或者: from django.utils.http import parse_http_date [as 別名]
def was_modified_since(header=None, mtime=0, size=0):
"""
Was something modified since the user last downloaded it?
header
This is the value of the If-Modified-Since header. If this is None,
I'll just return True.
mtime
This is the modification time of the item we're talking about.
size
This is the size of the item we're talking about.
"""
try:
if header is None:
raise ValueError
matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header,
re.IGNORECASE)
header_mtime = parse_http_date(matches.group(1))
header_len = matches.group(3)
if header_len and int(header_len) != size:
raise ValueError
if int(mtime) > header_mtime:
raise ValueError
except (AttributeError, ValueError, OverflowError):
return True
return False