Skip to content

Commit 4820ebe

Browse files
committed
Add .errnum to LDAPExceptions
1 parent dead8ef commit 4820ebe

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
@@ -196,7 +196,7 @@ LDAPerror(LDAP *l, char *msg)
196196
int
197197
LDAPinit_constants(PyObject *m)
198198
{
199-
PyObject *exc;
199+
PyObject *exc, *nobj;
200200

201201
/* simple constants */
202202

@@ -226,6 +226,10 @@ LDAPinit_constants(PyObject *m)
226226
#define add_err(n) do { \
227227
exc = PyErr_NewException("ldap." #n, LDAPexception_class, NULL); \
228228
if (exc == NULL) return -1; \
229+
nobj = PyLong_FromLong(LDAP_##n); \
230+
if (nobj == NULL) return -1; \
231+
if (PyObject_SetAttrString(exc, "errnum", nobj) != 0) return -1; \
232+
Py_DECREF(nobj); \
229233
errobjects[LDAP_##n+LDAP_ERROR_OFFSET] = exc; \
230234
if (PyModule_AddObject(m, #n, exc) != 0) return -1; \
231235
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