From: Adam Sampson Date: Sun, 12 Jul 2015 17:03:27 +0000 (+0100) Subject: Handle timestamps that don't fit in the platform's time_t. X-Git-Tag: v2.21~2 X-Git-Url: http://git.ozo.com/?a=commitdiff_plain;h=ac886c82798b18d15a5966b8637a369fd0450fa7;p=rawdog%2F.git Handle timestamps that don't fit in the platform's time_t. On a 32-bit platform, time.localtime can only deal with 32-bit inputs. This adds a more thorough set of tests for weird article dates, and exercises DayWriter as well as article dates. --- diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index c75bd65..684a0f9 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -81,7 +81,10 @@ def safe_ftime(format, t): def format_time(secs, config): """Format a time and date nicely.""" - t = time.localtime(secs) + try: + t = time.localtime(secs) + except ValueError, e: + return u"(bad time %s; %s)" % (repr(secs), str(e)) format = config["datetimeformat"] if format is None: format = config["timeformat"] + ", " + config["dayformat"] @@ -775,7 +778,11 @@ class DayWriter: self.counter += 1 def time(self, s): - tm = time.localtime(s) + try: + tm = time.localtime(s) + except ValueError: + # e.g. "timestamp out of range for platform time_t" + return if tm[:3] != self.lasttime[:3] and self.config["daysections"]: self.close(0) self.start_day(tm) diff --git a/test-rawdog b/test-rawdog index 7b3f77e..7d3a953 100755 --- a/test-rawdog +++ b/test-rawdog @@ -1298,10 +1298,15 @@ if [ -n "$ja_LC_ALL" ]; then contains $statedir/output.html "HEADING-Tuesday" "ITEMDATE-Tuesday" fi -begin "two-digit year with timezone" -# As of 2015-07, feedparser treats the time zone as the year number in the date -# below -- seen in the real world in . -# But time.strftime doesn't know how to format dates in the year 300 AD! +begin "strange dates in feeds" +# Python's time.strftime can't handle all possible dates, and the range of +# dates that Python can work with in time_t format varies between platforms. +# rawdog won't be able to display dates that Python can't handle, but it +# should at least not crash if feedparser decides to present them +# (for example, if feedparser misparses a timezone as a feed). +echo "__date__" >$statedir/item +add "itemtemplate item" +add "sortbyfeeddate true" cat >$httpdir/feed.rss < @@ -1309,8 +1314,23 @@ cat >$httpdir/feed.rss <http://example.org/ example-feed-description - example-item-title + Date in 300 outside 32-bit time_t range + http://example.org/item + Mon, 1 Jan 0300 01:23:45 +0000 + + + Date in 1750 using Julian calendar + http://example.org/item + Mon, 1 Jan 1750 01:23:45 +0000 + + + Date in 1969 with negative time_t http://example.org/item + Wed, 1 Jan 1969 01:23:45 +0000 + + + Date in 2015 that feedparser 5.2.0 misparses as 300 + http://zeptobars.ru/en/rss Fri, 20 Mar 15 17:32:14 +0300 @@ -1319,18 +1339,6 @@ EOF add "feed 0 $httpurl/feed.rss" runs -uw -begin "year before 1000" -make_atom10 $httpdir/feed.atom -add "feed 0 $httpurl/feed.atom" -cat >$statedir/plugins/mangle.py <$httpdir/feed.atom <