diff -r afd3120ec71e -r a34e9f56ddda log_source.py --- a/log_source.py Tue Feb 10 04:27:22 2009 +0200 +++ b/log_source.py Tue Feb 10 05:56:57 2009 +0200 @@ -144,7 +144,7 @@ def get_month_days (self, dt) : """ - Get a set of dates, telling which days in the given month (as a datetime) have logs available + Return a sequence of dates, telling which days in the given month (as a datetime) have logs available """ abstract @@ -294,7 +294,7 @@ # yield the rest a line at a time in reverse order... this looks weird, but that's how slicing works :) # XXX: use something like islice, this has to build a slice object for line in lines[:0:-1] : - yield line.decode(self.charset) + yield self.decoder.decode(line) def read_latest (self, count) : """ @@ -516,28 +516,38 @@ f_begin.read_from(dtz_begin), f_end.read_until(dtz_end) if f_end else [] ) + + def _iter_month_days (self, month) : + """ + Iterates over the days of a month as dt objects with time=0 + """ + + # there's at most 31 days in a month... + for day in xrange(1, 32) : + try : + # try and build the datetime + dt = datetime.datetime(month.year, month.month, day) + + except : + # stop + return + + else : + # fix timezones + yield + yield month.tzinfo.localize(dt) def get_month_days (self, month) : """ Returns a set of dates for which logfiles are available in the given datetime's month """ - # the set of days - days = set() - - # iterate over month's days using Calendar - for date in calendar.Calendar().itermonthdates(month.year, month.month) : - # convert date to target datetime - dtz = month.tzinfo.localize(datetime.datetime.combine(date, datetime.time(0))).astimezone(self.tz) - + # iterate over month's days + for dt in self._iter_month_days(month) : # date in our target timezone - log_date = dtz.date() + log_date = dt.astimezone(self.tz).date() # test for it if self._get_logfile_date(log_date, load=False) : - # add to set - days.add(date) + # valid + yield dt.date() - # return set - return days -