Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r62259:be62e7062dea Date: 2013-03-08 17:51 -0500 http://bitbucket.org/pypy/pypy/changeset/be62e7062dea/
Log: merge heads diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -236,11 +236,6 @@ newformat = "".join(newformat) return _time.strftime(newformat, timetuple) -def _call_tzinfo_method(tzinfo, methname, tzinfoarg): - if tzinfo is None: - return None - return getattr(tzinfo, methname)(tzinfoarg) - # Just raise TypeError if the arg isn't None or a string. def _check_tzname(name): if name is not None and not isinstance(name, str): @@ -1336,7 +1331,9 @@ def utcoffset(self): """Return the timezone offset in minutes east of UTC (negative west of UTC).""" - offset = _call_tzinfo_method(self._tzinfo, "utcoffset", None) + if self._tzinfo is None: + return None + offset = self._tzinfo.utcoffset(None) offset = _check_utc_offset("utcoffset", offset) if offset is not None: offset = timedelta(minutes=offset) @@ -1344,7 +1341,9 @@ # Return an integer (or None) instead of a timedelta (or None). def _utcoffset(self): - offset = _call_tzinfo_method(self._tzinfo, "utcoffset", None) + if self._tzinfo is None: + return None + offset = self._tzinfo.utcoffset(None) offset = _check_utc_offset("utcoffset", offset) return offset @@ -1355,7 +1354,9 @@ it mean anything in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies. """ - name = _call_tzinfo_method(self._tzinfo, "tzname", None) + if self._tzinfo is None: + return None + name = self._tzinfo.tzname(None) _check_tzname(name) return name @@ -1368,7 +1369,9 @@ need to consult dst() unless you're interested in displaying the DST info. """ - offset = _call_tzinfo_method(self._tzinfo, "dst", None) + if self._tzinfo is None: + return None + offset = self._tzinfo.dst(None) offset = _check_utc_offset("dst", offset) if offset is not None: offset = timedelta(minutes=offset) @@ -1376,7 +1379,9 @@ # Return an integer (or None) instead of a timedelta (or None). def _dst(self): - offset = _call_tzinfo_method(self._tzinfo, "dst", None) + if self._tzinfo is None: + return None + offset = self._tzinfo.dst(None) offset = _check_utc_offset("dst", offset) return offset @@ -1420,7 +1425,10 @@ ord(string[0]), ord(string[1]), ord(string[2]), ord(string[3]), ord(string[4]), ord(string[5])) self._microsecond = (((us1 << 8) | us2) << 8) | us3 - self._tzinfo = tzinfo + if tzinfo is None or isinstance(tzinfo, _tzinfo_class): + self._tzinfo = tzinfo + else: + raise TypeError("bad tzinfo state arg") def __reduce__(self): return (time, self._getstate()) @@ -1710,7 +1718,9 @@ def utcoffset(self): """Return the timezone offset in minutes east of UTC (negative west of UTC).""" - offset = _call_tzinfo_method(self._tzinfo, "utcoffset", self) + if self._tzinfo is None: + return None + offset = self._tzinfo.utcoffset(self) offset = _check_utc_offset("utcoffset", offset) if offset is not None: offset = timedelta(minutes=offset) @@ -1718,7 +1728,9 @@ # Return an integer (or None) instead of a timedelta (or None). def _utcoffset(self): - offset = _call_tzinfo_method(self._tzinfo, "utcoffset", self) + if self._tzinfo is None: + return None + offset = self._tzinfo.utcoffset(self) offset = _check_utc_offset("utcoffset", offset) return offset @@ -1729,7 +1741,9 @@ it mean anything in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies. """ - name = _call_tzinfo_method(self._tzinfo, "tzname", self) + if self._tzinfo is None: + return None + name = self._tzinfo.tzname(self) _check_tzname(name) return name @@ -1742,7 +1756,9 @@ need to consult dst() unless you're interested in displaying the DST info. """ - offset = _call_tzinfo_method(self._tzinfo, "dst", self) + if self._tzinfo is None: + return None + offset = self._tzinfo.dst(self) offset = _check_utc_offset("dst", offset) if offset is not None: offset = timedelta(minutes=offset) @@ -1750,7 +1766,9 @@ # Return an integer (or None) instead of a timedelta (or None). def _dst(self): - offset = _call_tzinfo_method(self._tzinfo, "dst", self) + if self._tzinfo is None: + return None + offset = self._tzinfo.dst(self) offset = _check_utc_offset("dst", offset) return offset @@ -1907,7 +1925,10 @@ ord(string[7]), ord(string[8]), ord(string[9])) self._year = yhi * 256 + ylo self._microsecond = (((us1 << 8) | us2) << 8) | us3 - self._tzinfo = tzinfo + if tzinfo is None or isinstance(tzinfo, _tzinfo_class): + self._tzinfo = tzinfo + else: + raise TypeError("bad tzinfo state arg") def __reduce__(self): return (self.__class__, self._getstate()) diff --git a/pypy/module/test_lib_pypy/test_datetime.py b/pypy/module/test_lib_pypy/test_datetime.py --- a/pypy/module/test_lib_pypy/test_datetime.py +++ b/pypy/module/test_lib_pypy/test_datetime.py @@ -25,6 +25,16 @@ e = raises(TypeError, datetime.datetime, '123') assert e.value.args[0] == 'an integer is required' + datetime.time('\x01' * 6, None) + with raises(TypeError) as e: + datetime.time('\x01' * 6, 123) + assert str(e.value) == "bad tzinfo state arg" + + datetime.datetime('\x01' * 10, None) + with raises(TypeError) as e: + datetime.datetime('\x01' * 10, 123) + assert str(e.value) == "bad tzinfo state arg" + def test_strptime(): import time, sys if sys.version_info < (2, 6): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit