Skip to content

Commit 7857291

Browse files
committed
Add .errnum to LDAPExceptions
1 parent 972490c commit 7857291

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Doc/reference/ldap.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ The module defines the following exceptions:
321321
is set to a truncated form of the name provided or alias dereferenced
322322
for the lowest entry (object or alias) that was matched.
323323

324+
Most exceptions from protocol results also carry the :py:attr:`errnum`
325+
attribute.
326+
324327

325328
.. py:exception:: ADMINLIMIT_EXCEEDED
326329

Modules/constants.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ LDAPerror(LDAP *l, char *msg)
198198
int
199199
LDAPinit_constants(PyObject *m)
200200
{
201-
PyObject *exc;
201+
PyObject *exc, *nobj;
202202

203203
/* simple constants */
204204

@@ -228,6 +228,10 @@ LDAPinit_constants(PyObject *m)
228228
#define add_err(n) do { \
229229
exc = PyErr_NewException("ldap." #n, LDAPexception_class, NULL); \
230230
if (exc == NULL) return -1; \
231+
nobj = PyLong_FromLong(LDAP_##n); \
232+
if (nobj == NULL) return -1; \
233+
if (PyObject_SetAttrString(exc, "errnum", nobj) != 0) return -1; \
234+
Py_DECREF(nobj); \
231235
errobjects[LDAP_##n+LDAP_ERROR_OFFSET] = exc; \
232236
if (PyModule_AddObject(m, #n, exc) != 0) return -1; \
233237
Py_INCREF(exc); \

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