Skip to content

Commit 12f193e

Browse files
committed
In timeout options, reword the message only of TypeError
1 parent a8b2748 commit 12f193e

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Modules/options.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,22 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
136136
break;
137137
case LDAP_OPT_TIMEOUT:
138138
case LDAP_OPT_NETWORK_TIMEOUT:
139-
/* Float valued timeval options, 'd' also handles int/long */
140-
if (!PyArg_Parse(value, "d:set_option", &doubleval)) {
141-
/* clear error and try again with None */
142-
PyErr_Clear();
143-
if (PyNone_Check(value)) {
144-
/* None is mapped to infinity timeout */
145-
doubleval = -1;
146-
}
147-
else {
148-
PyErr_Format(
149-
PyExc_TypeError,
150-
"A float or None is expected for timeout, got %.100s",
151-
Py_TYPE(value)->tp_name
152-
);
139+
/* Float valued timeval options */
140+
if (value == Py_None) {
141+
/* None is mapped to infinity timeout */
142+
doubleval = -1;
143+
} else {
144+
/* 'd' handles int/long */
145+
if (!PyArg_Parse(value, "d:set_option", &doubleval)) {
146+
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
147+
/* TypeError: mention either float or None is expected */
148+
PyErr_Clear();
149+
PyErr_Format(
150+
PyExc_TypeError,
151+
"A float or None is expected for timeout, got %.100s",
152+
Py_TYPE(value)->tp_name
153+
);
154+
}
153155
return 0;
154156
}
155157
}

Tests/t_ldap_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def _test_timeout(self, option):
6464
self._check_option(option, -5)
6565
with self.assertRaises(TypeError):
6666
self.set_option(option, object)
67+
with self.assertRaises(OverflowError):
68+
self._check_option(option, 10**1000)
6769
old = self.get_option(option)
6870
try:
6971
self.set_option(option, None)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy