Exemplo n.º 1
0
    def test_http2time_garbage(self):
        from mechanize._util import http2time

        for test in [
                '', 'Garbage', 'Mandag 16. September 1996', '01-00-1980',
                '01-13-1980', '00-01-1980', '32-01-1980',
                '01-01-1980 25:00:00', '01-01-1980 00:61:00',
                '01-01-1980 00:00:62'
        ]:

            bad = False

            if http2time(test) is not None:
                print("http2time(%s) is not None" % (test, ))
                print("http2time(test)", http2time(test))
                bad = True

            assert not bad
Exemplo n.º 2
0
    def test_http2time_formats(self):
        from mechanize._util import http2time, time2isoz

        # test http2time for supported dates.  Test cases with 2 digit year
        # will probably break in year 2044.
        tests = [
            'Thu, 03 Feb 1994 00:00:00 GMT',  # proposed new HTTP format
            'Thursday, 03-Feb-94 00:00:00 GMT',  # old rfc850 HTTP format
            'Thursday, 03-Feb-1994 00:00:00 GMT',  # broken rfc850 HTTP format

            '03 Feb 1994 00:00:00 GMT',  # HTTP format (no weekday)
            '03-Feb-94 00:00:00 GMT',  # old rfc850 (no weekday)
            '03-Feb-1994 00:00:00 GMT',  # broken rfc850 (no weekday)
            '03-Feb-1994 00:00 GMT',  # broken rfc850 (no weekday, no seconds)
            # broken rfc850 (no weekday, no seconds, no tz)
            '03-Feb-1994 00:00',

            '03-Feb-94',  # old rfc850 HTTP format (no weekday, no time)
            '03-Feb-1994',  # broken rfc850 HTTP format (no weekday, no time)
            '03 Feb 1994',  # proposed new HTTP format (no weekday, no time)

            # A few tests with extra space at various places
            '  03   Feb   1994  0:00  ',
            '  03-Feb-1994  ',
        ]

        test_t = 760233600  # assume broken POSIX counting of seconds
        result = time2isoz(test_t)
        expected = "1994-02-03 00:00:00Z"
        assert result == expected, \
            "%s  =>  '%s' (%s)" % (test_t, result, expected)

        for s in tests:
            t = http2time(s)
            t2 = http2time(s.lower())
            t3 = http2time(s.upper())

            assert t == t2 == t3 == test_t, \
                "'%s'  =>  %s, %s, %s (%s)" % (s, t, t2, t3, test_t)
Exemplo n.º 3
0
    def test_http2time_formats(self):
        from mechanize._util import http2time, time2isoz

        # test http2time for supported dates.  Test cases with 2 digit year
        # will probably break in year 2044.
        tests = [
         'Thu, 03 Feb 1994 00:00:00 GMT',  # proposed new HTTP format
         'Thursday, 03-Feb-94 00:00:00 GMT',  # old rfc850 HTTP format
         'Thursday, 03-Feb-1994 00:00:00 GMT',  # broken rfc850 HTTP format

         '03 Feb 1994 00:00:00 GMT',  # HTTP format (no weekday)
         '03-Feb-94 00:00:00 GMT',  # old rfc850 (no weekday)
         '03-Feb-1994 00:00:00 GMT',  # broken rfc850 (no weekday)
         '03-Feb-1994 00:00 GMT',  # broken rfc850 (no weekday, no seconds)
         '03-Feb-1994 00:00',  # broken rfc850 (no weekday, no seconds, no tz)

         '03-Feb-94',  # old rfc850 HTTP format (no weekday, no time)
         '03-Feb-1994',  # broken rfc850 HTTP format (no weekday, no time)
         '03 Feb 1994',  # proposed new HTTP format (no weekday, no time)

         # A few tests with extra space at various places
         '  03   Feb   1994  0:00  ',
         '  03-Feb-1994  ',
        ]

        test_t = 760233600  # assume broken POSIX counting of seconds
        result = time2isoz(test_t)
        expected = "1994-02-03 00:00:00Z"
        assert result == expected, \
               "%s  =>  '%s' (%s)" % (test_t, result, expected)

        for s in tests:
            t = http2time(s)
            t2 = http2time(s.lower())
            t3 = http2time(s.upper())

            assert t == t2 == t3 == test_t, \
                   "'%s'  =>  %s, %s, %s (%s)" % (s, t, t2, t3, test_t)
Exemplo n.º 4
0
    def test_http2time_garbage(self):
        from mechanize._util import http2time

        for test in [
            '', 'Garbage',
            'Mandag 16. September 1996',

            '01-00-1980',
            '01-13-1980',
            '00-01-1980',
            '32-01-1980',
            '01-01-1980 25:00:00',
            '01-01-1980 00:61:00',
            '01-01-1980 00:00:62']:

            bad = False

            if http2time(test) is not None:
                print "http2time(%s) is not None" % (test,)
                print "http2time(test)", http2time(test)
                bad = True

            assert not bad
Exemplo n.º 5
0
 def parse_date(text, http2time=http2time):
     return time.gmtime(http2time(text))[:6]
Exemplo n.º 6
0
 def parse_date(text, http2time=http2time):
     return time.gmtime(http2time(text))[:6]