Skip to content

Commit

Permalink
Modules: Remove _ldap._forward and _ldap._reverse
Browse files Browse the repository at this point in the history
These were created only as:
forward = {}
reverse = {0: None}

The only use was the function LDAPconstant, equivalent to:

    def LDAPconstant(i):
        return reverse.get(i, i)

It looks like these were prepared for a better future, but python-ldap
has gone for years or decades without needing to actually use them.
Remove both dictionaries and the function.
  • Loading branch information
Petr Viktorin committed Nov 27, 2017
1 parent a72aaac commit 8807e75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
7 changes: 6 additions & 1 deletion Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,12 @@ l_ldap_result4( LDAPObject* self, PyObject *args )

pmsg = LDAPmessage_to_python( self->ldap, msg, add_ctrls, add_intermediates );

result_str = LDAPconstant( res_type );
if (res_type == 0) {
result_str = Py_None;
Py_INCREF(Py_None);
} else {
result_str = PyInt_FromLong( res_type );
}

if (pmsg == NULL) {
retval = NULL;
Expand Down
29 changes: 1 addition & 28 deletions Modules/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,12 @@
#include "lber.h"
#include "ldap.h"

static PyObject* reverse;
static PyObject* forward;

/* convert an result integer into a Python string */

PyObject*
LDAPconstant( int val ) {
PyObject *i = PyInt_FromLong( val );
PyObject *s = PyObject_GetItem( reverse, i );
if (s == NULL) {
PyErr_Clear();
return i;
}
Py_DECREF(i);
return s;
}

/* initialise the module constants */

void
LDAPinit_constants( PyObject* d )
{
PyObject *zero, *author,*obj;

reverse = PyDict_New();
forward = PyDict_New();

PyDict_SetItemString( d, "_reverse", reverse );
PyDict_SetItemString( d, "_forward", forward );
PyObject *obj;

#define add_int(d, name) \
{ \
Expand Down Expand Up @@ -91,10 +68,6 @@ LDAPinit_constants( PyObject* d )

/* reversibles */

zero = PyInt_FromLong( 0 );
PyDict_SetItem( reverse, zero, Py_None );
Py_DECREF( zero );

add_int(d,RES_BIND);
add_int(d,RES_SEARCH_ENTRY);
add_int(d,RES_SEARCH_RESULT);
Expand Down

0 comments on commit 8807e75

Please sign in to comment.