Skip to content

Commit 0cce151

Browse files
committed
WIP+fixup: move feature detection to runtime
1 parent f634ae5 commit 0cce151

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Lib/ldap/ldapobject.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ def connect(self):
176176
connect() -> None
177177
Establishes LDAP connection if needed.
178178
"""
179-
if _ldap.VENDOR_VERSION >= 20500:
180-
return self._ldap_call(self._l.connect)
181-
raise NotImplementedError
179+
return self._ldap_call(self._l.connect)
182180

183181
def abandon_ext(self,msgid,serverctrls=None,clientctrls=None):
184182
"""

Modules/LDAPObject.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,12 +1507,21 @@ l_ldap_extended_operation(LDAPObject *self, PyObject *args)
15071507

15081508
/* ldap_connect */
15091509

1510-
#if LDAP_VENDOR_VERSION >= 20500
15111510
static PyObject *
15121511
l_ldap_connect(LDAPObject *self, PyObject Py_UNUSED(args))
15131512
{
1513+
#if LDAP_VENDOR_VERSION >= 20500
15141514
int ldaperror;
15151515

1516+
if (ldap_version_info.ldapai_vendor_version < 20500)
1517+
#endif
1518+
{
1519+
PyErr_SetString(PyExc_NotImplementedError,
1520+
"loaded libldap doesn't support this feature");
1521+
return NULL;
1522+
}
1523+
1524+
#if LDAP_VENDOR_VERSION >= 20500
15161525
if (not_valid(self))
15171526
return NULL;
15181527

@@ -1525,8 +1534,8 @@ l_ldap_connect(LDAPObject *self, PyObject Py_UNUSED(args))
15251534

15261535
Py_INCREF(Py_None);
15271536
return Py_None;
1528-
}
15291537
#endif
1538+
}
15301539

15311540
/* methods */
15321541

@@ -1557,9 +1566,7 @@ static PyMethodDef methods[] = {
15571566
{"cancel", (PyCFunction)l_ldap_cancel, METH_VARARGS},
15581567
#endif
15591568
{"extop", (PyCFunction)l_ldap_extended_operation, METH_VARARGS},
1560-
#if LDAP_VENDOR_VERSION >= 20500
15611569
{"connect", (PyCFunction)l_ldap_connect, METH_NOARGS},
1562-
#endif
15631570
{NULL, NULL}
15641571
};
15651572

Tests/t_cext.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ def test_simple_anonymous_bind(self):
281281
self.assertEqual(ctrls, [])
282282

283283
@unittest.skipUnless(
284-
_ldap.VENDOR_VERSION >= 20500,
284+
_ldap.VENDOR_VERSION >= 20500 and \
285+
_ldap._VENDOR_VERSION_RUNTIME >= 20500,
285286
reason="Test requires libldap 2.5+"
286287
)
287288
def test_connect(self):
@@ -293,6 +294,15 @@ def test_connect(self):
293294

294295
self._bind_conn(l)
295296

297+
@unittest.skipUnless(
298+
_ldap._VENDOR_VERSION_RUNTIME < 20500,
299+
reason="Test requires linking to libldap < 2.5"
300+
)
301+
def test_connect_notimpl(self):
302+
l = self._open_conn(bind=False)
303+
with self.assertRaises(NotImplementedError):
304+
l.connect()
305+
296306
def test_anon_rootdse_search(self):
297307
l = self._open_conn(bind=False)
298308
# see if we can get the rootdse with anon search (without prior bind)

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