Example #1
0
 def parse(cls, value, kwds):
     if not value:
         kwds['defects'].append(errors.HeaderMissingRequiredValue())
         kwds['datetime'] = None
         kwds['decoded'] = ''
         kwds['parse_tree'] = parser.TokenList()
         return
     if isinstance(value, str):
         value = utils.parsedate_to_datetime(value)
     kwds['datetime'] = value
     kwds['decoded'] = utils.format_datetime(kwds['datetime'])
     kwds['parse_tree'] = cls.value_parser(kwds['decoded'])
 def test_usegmt_with_non_utc_datetime_raises(self):
     with self.assertRaises(ValueError):
         utils.format_datetime(self.aware_dt, usegmt=True)
 def test_usegmt(self):
     utc_dt = datetime.datetime(*self.dateargs,
                                tzinfo=datetime.timezone.utc)
     self.assertEqual(utils.format_datetime(utc_dt, usegmt=True),
                      self.datestring + ' GMT')
 def test_aware_datetime(self):
     self.assertEqual(utils.format_datetime(self.aware_dt),
                      self.datestring + self.offsetstring)
 def test_naive_datetime(self):
     self.assertEqual(utils.format_datetime(self.naive_dt),
                      self.datestring + ' -0000')
 def test_usegmt_with_non_utc_datetime_raises(self):
     with self.assertRaises(ValueError):
         utils.format_datetime(self.aware_dt, usegmt=True)
 def test_usegmt(self):
     utc_dt = datetime.datetime(*self.dateargs,
                                tzinfo=datetime.timezone.utc)
     self.assertEqual(utils.format_datetime(utc_dt, usegmt=True),
                      self.datestring + ' GMT')
 def test_aware_datetime(self):
     self.assertEqual(utils.format_datetime(self.aware_dt),
                      self.datestring + self.offsetstring)
 def test_naive_datetime(self):
     self.assertEqual(utils.format_datetime(self.naive_dt),
                      self.datestring + ' -0000')