"""Parse the ``If-Modified-Since`` header."""
__docformat__ = "restructuredtext"
# Created: Thu Apr 28 07:07:09 PDT 2005
# Author: Shannon -jj Behrens
# Email: jjinux@users.sourceforge.net
#
# Copyright (c) Shannon -jj Behrens. All rights reserved.
import re
import rfc822
def wasModifiedSince(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)
headerMTime = rfc822.mktime_tz(rfc822.parsedate_tz(
matches.group(1)))
headerLen = matches.group(3)
if headerLen and int(headerLen) != size:
raise ValueError
if mtime > headerMTime:
raise ValueError
except (AttributeError, ValueError):
return True
return False
|