Commit 0dd06f40 authored by Alexander Belopolsky's avatar Alexander Belopolsky

Fixed error handling branches. Thanks

Victor Stinner for pointing this out.
parent b8bb4664
......@@ -308,13 +308,24 @@ class TestDontAccept2Year(TestAccept2Year):
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__":
......
......@@ -332,7 +332,8 @@ gettmarg(PyObject *args, struct tm *p)
if (y < 1000) {
PyObject *accept = PyDict_GetItemString(moddict,
"accept2dyear");
int acceptval = accept != NULL && PyObject_IsTrue(accept);
if (accept != NULL) {
int acceptval = PyObject_IsTrue(accept);
if (acceptval == -1)
return 0;
if (acceptval) {
......@@ -350,6 +351,9 @@ gettmarg(PyObject *args, struct tm *p)
return 0;
}
}
else
return 0;
}
p->tm_year = y - 1900;
p->tm_mon--;
p->tm_wday = (p->tm_wday + 1) % 7;
......@@ -477,6 +481,7 @@ time_strftime(PyObject *self, PyObject *args)
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment