Skip to content

Commit

Permalink
In timeout options, reword the message only of TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Viktorin committed Dec 7, 2017
1 parent a8b2748 commit 12f193e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Modules/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,22 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
break;
case LDAP_OPT_TIMEOUT:
case LDAP_OPT_NETWORK_TIMEOUT:
/* Float valued timeval options, 'd' also handles int/long */
if (!PyArg_Parse(value, "d:set_option", &doubleval)) {
/* clear error and try again with None */
PyErr_Clear();
if (PyNone_Check(value)) {
/* None is mapped to infinity timeout */
doubleval = -1;
}
else {
PyErr_Format(
PyExc_TypeError,
"A float or None is expected for timeout, got %.100s",
Py_TYPE(value)->tp_name
);
/* Float valued timeval options */
if (value == Py_None) {
/* None is mapped to infinity timeout */
doubleval = -1;
} else {
/* 'd' handles int/long */
if (!PyArg_Parse(value, "d:set_option", &doubleval)) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
/* TypeError: mention either float or None is expected */
PyErr_Clear();
PyErr_Format(
PyExc_TypeError,
"A float or None is expected for timeout, got %.100s",
Py_TYPE(value)->tp_name
);
}
return 0;
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/t_ldap_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def _test_timeout(self, option):
self._check_option(option, -5)
with self.assertRaises(TypeError):
self.set_option(option, object)
with self.assertRaises(OverflowError):
self._check_option(option, 10**1000)
old = self.get_option(option)
try:
self.set_option(option, None)
Expand Down

0 comments on commit 12f193e

Please sign in to comment.