def test_parse_date_overflows(self): self.assertEqual( http.parse_date(' Sun 02 Feb 1343 08:49:37 GMT'), datetime(1343, 2, 2, 8, 49, 37) ) self.assertEqual( http.parse_date('Thu, 01 Jan 1970 00:00:00 GMT'), datetime(1970, 1, 1, 0, 0) ) self.assertIs(http.parse_date('Thu, 33 Jan 1970 00:00:00 GMT'), None)
def test_parse_date(self): self.assertEqual( http.parse_date('Sun, 06 Nov 1994 08:49:37 GMT '), datetime(1994, 11, 6, 8, 49, 37) ) self.assertEqual( http.parse_date('Sunday, 06-Nov-94 08:49:37 GMT'), datetime(1994, 11, 6, 8, 49, 37) ) self.assertEqual(http.parse_date( ' Sun Nov 6 08:49:37 1994'), datetime(1994, 11, 6, 8, 49, 37) ) self.assertIs(http.parse_date('foo'), None)
def _get_retry_after(self): value = self.headers.get('retry-after') if value is None: return elif value.isdigit(): return datetime.utcnow() + timedelta(seconds=int(value)) return parse_date(value)
def date(self): """The Date general-header field represents the date and time at which the message was originated, having the same semantics as orig-date in RFC 822. """ return parse_date(self.environ.get('HTTP_DATE'))
def if_unmodified_since(self): """The parsed `If-Unmodified-Since` header as datetime object.""" return parse_date(self.environ.get('HTTP_IF_UNMODIFIED_SINCE'))