def parse_date(value): date_tuple = lib_parsedate(value) if date_tuple is None: raise ValueError if date_tuple[0] < 100: if date_tuple[0] > 68: date_tuple = (date_tuple[0] + 1900, ) + date_tuple[1:] # type: ignore else: date_tuple = (date_tuple[0] + 2000, ) + date_tuple[1:] # type: ignore return calendar.timegm(date_tuple)
def parse_date(value): """Parse a HTTP date. Raises ValueError if it's bad.""" if not re.match(r"%s$" % syntax.DATE, value, re.VERBOSE): raise ValueError date_tuple = lib_parsedate(value) if date_tuple is None: raise ValueError # http://sourceforge.net/tracker/index.php?func=detail&aid=1194222&group_id=5470&atid=105470 if date_tuple[0] < 100: if date_tuple[0] > 68: date_tuple = (date_tuple[0]+1900,)+date_tuple[1:] else: date_tuple = (date_tuple[0]+2000,)+date_tuple[1:] date = calendar.timegm(date_tuple) return date
def parse_date(value: str, add_note: AddNoteMethodType) -> int: """Parse a HTTP date. Raises ValueError if it's bad.""" if not re.match(r"^%s$" % rfc7231.HTTP_date, value, RE_FLAGS): add_note(BAD_DATE_SYNTAX) raise ValueError if re.match(r"^%s$" % rfc7231.obs_date, value, RE_FLAGS): add_note(DATE_OBSOLETE) date_tuple = lib_parsedate(value) if date_tuple is None: raise ValueError # http://sourceforge.net/tracker/index.php?func=detail&aid=1194222&group_id=5470&atid=105470 if date_tuple[0] < 100: if date_tuple[0] > 68: date_tuple = (date_tuple[0]+1900,) + date_tuple[1:] # type: ignore else: date_tuple = (date_tuple[0]+2000,) + date_tuple[1:] # type: ignore return calendar.timegm(date_tuple)
def parse_date(value: str, add_note: AddNoteMethodType) -> int: """Parse a HTTP date. Raises ValueError if it's bad.""" if not re.match(r"^%s$" % rfc7231.HTTP_date, value, RE_FLAGS): add_note(BAD_DATE_SYNTAX) raise ValueError if re.match(r"^%s$" % rfc7231.obs_date, value, RE_FLAGS): add_note(DATE_OBSOLETE) date_tuple = lib_parsedate(value) if date_tuple is None: raise ValueError # http://sourceforge.net/tracker/index.php?func=detail&aid=1194222&group_id=5470&atid=105470 if date_tuple[0] < 100: if date_tuple[0] > 68: date_tuple = (date_tuple[0] + 1900, ) + date_tuple[1:] # type: ignore else: date_tuple = (date_tuple[0] + 2000, ) + date_tuple[1:] # type: ignore return calendar.timegm(date_tuple)