[Python-checkins] r87844 - in python/branches/py3k: Lib/test/test_time.py Modules/timemodule.c
alexander.belopolsky
python-checkins at python.org
Sat Jan 8 02:23:02 CET 2011
Author: alexander.belopolsky
Date: Sat Jan 8 02:23:02 2011
New Revision: 87844
Log:
Fixed error handling branches. Thanks
Victor Stinner for pointing this out.
Modified:
python/branches/py3k/Lib/test/test_time.py
python/branches/py3k/Modules/timemodule.c
Modified: python/branches/py3k/Lib/test/test_time.py
==============================================================================
--- python/branches/py3k/Lib/test/test_time.py (original)
+++ python/branches/py3k/Lib/test/test_time.py Sat Jan 8 02:23:02 2011
@@ -308,13 +308,24 @@
def test_invalid(self):
pass
+class TestAccept2YearBad(TestAccept2Year):
+ class X:
+ def __bool__(self):
+ raise RuntimeError('boo')
+ accept2dyear = X()
+ def test_2dyear(self):
+ pass
+ def test_invalid(self):
+ self.assertRaises(RuntimeError, self.yearstr, 200)
+
+
class TestDontAccept2YearBool(TestDontAccept2Year):
accept2dyear = False
def test_main():
support.run_unittest(TimeTestCase, TestLocale,
- TestAccept2Year, TestAccept2YearBool,
+ TestAccept2Year, TestAccept2YearBool, TestAccept2YearBad,
TestDontAccept2Year, TestDontAccept2YearBool)
if __name__ == "__main__":
Modified: python/branches/py3k/Modules/timemodule.c
==============================================================================
--- python/branches/py3k/Modules/timemodule.c (original)
+++ python/branches/py3k/Modules/timemodule.c Sat Jan 8 02:23:02 2011
@@ -332,23 +332,27 @@
if (y < 1000) {
PyObject *accept = PyDict_GetItemString(moddict,
"accept2dyear");
- int acceptval = accept != NULL && PyObject_IsTrue(accept);
- if (acceptval == -1)
- return 0;
- if (acceptval) {
- if (0 <= y && y < 69)
- y += 2000;
- else if (69 <= y && y < 100)
- y += 1900;
- else {
- PyErr_SetString(PyExc_ValueError,
- "year out of range");
+ if (accept != NULL) {
+ int acceptval = PyObject_IsTrue(accept);
+ if (acceptval == -1)
return 0;
+ if (acceptval) {
+ if (0 <= y && y < 69)
+ y += 2000;
+ else if (69 <= y && y < 100)
+ y += 1900;
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "year out of range");
+ return 0;
+ }
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Century info guessed for a 2-digit year.", 1) != 0)
+ return 0;
}
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "Century info guessed for a 2-digit year.", 1) != 0)
- return 0;
}
+ else
+ return 0;
}
p->tm_year = y - 1900;
p->tm_mon--;
@@ -477,6 +481,7 @@
PyErr_Format(PyExc_ValueError, "year=%d is before 1900; "
"the strftime() method requires year >= 1900",
buf.tm_year + 1900);
+ return NULL;
}
/* Normalize tm_isdst just in case someone foolishly implements %Z
More information about the Python-checkins
mailing list