Skip to content

Commit 059f0d7

Browse files
committed
WIP+fixup: move feature detection to runtime
1 parent 52b1447 commit 059f0d7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
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
{
15141513
int ldaperror;
15151514

1515+
#if LDAP_VENDOR_VERSION >= 20500
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

0 commit comments

Comments
 (0)