def test_parse(self): self.assertEqual(dateutil.parse_iso8601_date('1234-06-18'), datetime(1234,6,18)) self.assertEqual(dateutil.parse_iso8601_date('1234-06-18T12:34:56'), datetime(1234,6,18,12,34,56)) self.assertEqual(dateutil.parse_iso8601_date('1234-06-18T12:34:56Z'), datetime(1234,6,18,12,34,56)) self.assertRaises( ValueError, dateutil.parse_iso8601_date, '') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '1234-06-18 12:34:56..') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '1234/06/18 12:34:56') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '1234-06-18 12.34.56') self.assertRaises( ValueError, dateutil.parse_iso8601_date, 'abcd-06-18 12:34:56') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '9999-99-99 99:99:99')
def _interpretHeaderRecord(self, lineno, line): """ @params lineno - 1 based for error reporting @params line """ pair = line.split(':',1) if len(pair) != 2: raise SyntaxError('Invalid header (format=name: value) - "%s"' % line) name = pair[0].strip().lower() value = pair[1].strip() # borrow decode_dsv() to decode \ and line breaks. value0 = decode_dsv(value)[0] # support these headers if name == 'weblib-version': self.wlib.version = value0 elif name == 'date': try: self.wlib.date = dateutil.parse_iso8601_date(value0) except ValueError: self.wlib.date = datetime.datetime(1,1,1) # default date elif name == 'tag-columns': self.tag_column_index = parse_header(lineno, value, expected_col=self.TAG_COLUMNS) elif name == 'url-columns': self.url_column_index = parse_header(lineno, value, expected_col=self.URL_COLUMNS)
def load(self): # note: this is designed to work even if all upgrade.* fields are not specified self.current_version = cfg.get ('_system.version') self.feed_url = cfg.get ('upgrade_notification.feed_url','') _fetch_date_str = cfg.get ('upgrade_notification.fetch_date','') self.fetch_frequency = cfg.getint('upgrade_notification.fetch_frequency',10) self.last_entry_date = cfg.get ('upgrade_notification.last_entry_date','') try: fdate = dateutil.parse_iso8601_date(_fetch_date_str).date() except ValueError: self.fetch_date = today_func() self.next_fetch = today_func() else: self._set_fetch_date(fdate)
def test_parse(self): self.assertEqual(dateutil.parse_iso8601_date('2003-09-15T10:34:54Z'), datetime(2003,9,15,10,34,54)) self.assertEqual(dateutil.parse_iso8601_date('2003-09-15 10:34:54Z'), datetime(2003,9,15,10,34,54)) self.assertEqual(dateutil.parse_iso8601_date('2003-09-15T10:34:54' ), datetime(2003,9,15,10,34,54)) self.assertEqual(dateutil.parse_iso8601_date('20030915T103454' ), datetime(2003,9,15,10,34,54)) self.assertEqual(dateutil.parse_iso8601_date('2003-09-15' ), datetime(2003,9,15, 0, 0, 0)) self.assertEqual(dateutil.parse_iso8601_date('20030915' ), datetime(2003,9,15, 0, 0, 0)) self.assertRaises( ValueError, dateutil.parse_iso8601_date, '') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '1234-06-18 12:34:56..') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '1234/06/18 12:34:56') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '1234-06-18 12.34.56') self.assertRaises( ValueError, dateutil.parse_iso8601_date, 'abcd-06-18 12:34:56') self.assertRaises( ValueError, dateutil.parse_iso8601_date, '9999-99-99 99:99:99')