Skip to content

Commit

Permalink
Add .errnum to LDAPExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Kuzník committed May 7, 2020
1 parent 972490c commit 7857291
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Doc/reference/ldap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ The module defines the following exceptions:
is set to a truncated form of the name provided or alias dereferenced
for the lowest entry (object or alias) that was matched.

Most exceptions from protocol results also carry the :py:attr:`errnum`
attribute.


.. py:exception:: ADMINLIMIT_EXCEEDED
Expand Down
6 changes: 5 additions & 1 deletion Modules/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ LDAPerror(LDAP *l, char *msg)
int
LDAPinit_constants(PyObject *m)
{
PyObject *exc;
PyObject *exc, *nobj;

/* simple constants */

Expand Down Expand Up @@ -228,6 +228,10 @@ LDAPinit_constants(PyObject *m)
#define add_err(n) do { \
exc = PyErr_NewException("ldap." #n, LDAPexception_class, NULL); \
if (exc == NULL) return -1; \
nobj = PyLong_FromLong(LDAP_##n); \
if (nobj == NULL) return -1; \
if (PyObject_SetAttrString(exc, "errnum", nobj) != 0) return -1; \
Py_DECREF(nobj); \
errobjects[LDAP_##n+LDAP_ERROR_OFFSET] = exc; \
if (PyModule_AddObject(m, #n, exc) != 0) return -1; \
Py_INCREF(exc); \
Expand Down

0 comments on commit 7857291

Please sign in to comment.