[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.116,1.117 test_datetime.py,1.74,1.75
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 21 Dec 2002 09:41:37 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv11752
Modified Files:
datetime.py test_datetime.py
Log Message:
Always catch non-string results from indirect tzinfo.dst() calls.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.116
retrieving revision 1.117
diff -C2 -d -r1.116 -r1.117
*** datetime.py 21 Dec 2002 17:21:01 -0000 1.116
--- datetime.py 21 Dec 2002 17:41:35 -0000 1.117
***************
*** 221,231 ****
if offset is None:
return
! if not isinstance(offset, (int, long)):
! raise TypeError("%s() must return None, int or long, not %s" %
! (name, type(offset)))
if -1440 < offset < 1440:
return
raise ValueError("%s()=%d, must be in -1439..1439" % (name, offset))
# This is a start at a struct tm workalike. Goals:
#
--- 221,236 ----
if offset is None:
return
! if not isinstance(offset, (int, long, timedelta)):
! raise TypeError("tzinfo.%s() must return None, integer "
! "or timedelta, not '%s'" % (name, type(offset)))
if -1440 < offset < 1440:
return
raise ValueError("%s()=%d, must be in -1439..1439" % (name, offset))
+ def _check_tzname(name):
+ if name is not None and not isinstance(name, str):
+ raise TypeError("tzinfo.tzname() must return None or string, "
+ "not '%s'" % type(name))
+
# This is a start at a struct tm workalike. Goals:
#
***************
*** 1081,1084 ****
--- 1086,1090 ----
"""
name = _call_tzinfo_method(self, self.__tzinfo, "tzname")
+ _check_tzname(name)
return name
***************
*** 1484,1487 ****
--- 1490,1494 ----
"""
name = _call_tzinfo_method(self, self.__tzinfo, "tzname")
+ _check_tzname(name)
return name
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.74
retrieving revision 1.75
diff -C2 -d -r1.74 -r1.75
*** test_datetime.py 21 Dec 2002 05:03:14 -0000 1.74
--- test_datetime.py 21 Dec 2002 17:41:35 -0000 1.75
***************
*** 1574,1577 ****
--- 1574,1583 ----
"23:59 %Z='%z %Z %%z%%Z' %z='-2359'")
+ # Check that an invalid tzname result raises an exception.
+ class Badtzname(tzinfo):
+ def tzname(self, dt): return 42
+ t = timetz(2, 3, 4, tzinfo=Badtzname())
+ self.assertEqual(t.strftime("%H:%M:%S"), "02:03:04")
+ self.assertRaises(TypeError, t.strftime, "%Z")
def test_hash_edge_cases(self):