[Py3] Fix C extension: use Unicode/Long.
Replaces String(Bytes) and Int.
This commit is contained in:
parent
5248df94d3
commit
9fa6cd4168
|
@ -105,7 +105,7 @@ Tuple_to_LDAPMod( PyObject* tup, int no_op )
|
|||
{
|
||||
int op;
|
||||
char *type;
|
||||
PyObject *list, *item;
|
||||
PyObject *list, *item, *bytes;
|
||||
LDAPMod *lm = NULL;
|
||||
Py_ssize_t i, len, nstrs;
|
||||
|
||||
|
@ -139,7 +139,7 @@ Tuple_to_LDAPMod( PyObject* tup, int no_op )
|
|||
|
||||
if (list == Py_None) {
|
||||
/* None indicates a NULL mod_bvals */
|
||||
} else if (PyString_Check(list)) {
|
||||
} else if (PyUnicode_Check(list)) {
|
||||
/* Single string is a singleton list */
|
||||
lm->mod_bvalues = PyMem_NEW(struct berval *, 2);
|
||||
if (lm->mod_bvalues == NULL)
|
||||
|
@ -147,9 +147,10 @@ Tuple_to_LDAPMod( PyObject* tup, int no_op )
|
|||
lm->mod_bvalues[0] = PyMem_NEW(struct berval, 1);
|
||||
if (lm->mod_bvalues[0] == NULL)
|
||||
goto nomem;
|
||||
bytes = PyUnicode_AsUTF8String(list);
|
||||
lm->mod_bvalues[1] = NULL;
|
||||
lm->mod_bvalues[0]->bv_len = PyString_Size(list);
|
||||
lm->mod_bvalues[0]->bv_val = PyString_AsString(list);
|
||||
lm->mod_bvalues[0]->bv_len = PyBytes_Size(bytes);
|
||||
lm->mod_bvalues[0]->bv_val = PyBytes_AsString(bytes);
|
||||
} else if (PySequence_Check(list)) {
|
||||
nstrs = PySequence_Length(list);
|
||||
lm->mod_bvalues = PyMem_NEW(struct berval *, nstrs + 1);
|
||||
|
@ -163,14 +164,15 @@ Tuple_to_LDAPMod( PyObject* tup, int no_op )
|
|||
item = PySequence_GetItem(list, i);
|
||||
if (item == NULL)
|
||||
goto error;
|
||||
if (!PyString_Check(item)) {
|
||||
if (!PyUnicode_Check(item)) {
|
||||
PyErr_SetObject( PyExc_TypeError, Py_BuildValue( "sO",
|
||||
"expected a string in the list", item));
|
||||
Py_DECREF(item);
|
||||
goto error;
|
||||
}
|
||||
lm->mod_bvalues[i]->bv_len = PyString_Size(item);
|
||||
lm->mod_bvalues[i]->bv_val = PyString_AsString(item);
|
||||
bytes = PyUnicode_AsUTF8String(item);
|
||||
lm->mod_bvalues[i]->bv_len = PyBytes_Size(bytes);
|
||||
lm->mod_bvalues[i]->bv_val = PyBytes_AsString(bytes);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
if (nstrs == 0)
|
||||
|
@ -260,11 +262,11 @@ attrs_from_List( PyObject *attrlist, char***attrsp ) {
|
|||
|
||||
char **attrs = NULL;
|
||||
Py_ssize_t i, len;
|
||||
PyObject *item;
|
||||
PyObject *item, *bytes;
|
||||
|
||||
if (attrlist == Py_None) {
|
||||
/* None means a NULL attrlist */
|
||||
} else if (PyString_Check(attrlist)) {
|
||||
} else if (PyUnicode_Check(attrlist)) {
|
||||
/* caught by John Benninghoff <johnb@netscape.com> */
|
||||
PyErr_SetObject( PyExc_TypeError, Py_BuildValue("sO",
|
||||
"expected *list* of strings, not a string", attrlist ));
|
||||
|
@ -280,13 +282,14 @@ attrs_from_List( PyObject *attrlist, char***attrsp ) {
|
|||
item = PySequence_GetItem(attrlist, i);
|
||||
if (item == NULL)
|
||||
goto error;
|
||||
if (!PyString_Check(item)) {
|
||||
if (!PyUnicode_Check(item)) {
|
||||
PyErr_SetObject(PyExc_TypeError, Py_BuildValue("sO",
|
||||
"expected string in list", item));
|
||||
Py_DECREF(item);
|
||||
goto error;
|
||||
}
|
||||
attrs[i] = PyString_AsString(item);
|
||||
bytes = PyUnicode_AsUTF8String(item);
|
||||
attrs[i] = PyBytes_AsString(bytes);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
attrs[len] = NULL;
|
||||
|
@ -445,7 +448,7 @@ l_ldap_add_ext( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_add_ext" );
|
||||
|
||||
return PyInt_FromLong(msgid);
|
||||
return PyLong_FromLong(msgid);
|
||||
}
|
||||
|
||||
/* ldap_simple_bind */
|
||||
|
@ -488,7 +491,7 @@ l_ldap_simple_bind( LDAPObject* self, PyObject* args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_simple_bind" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
|
||||
|
@ -567,7 +570,7 @@ static int interaction ( unsigned flags,
|
|||
if (result == NULL)
|
||||
/*searching for a better error code */
|
||||
return LDAP_OPERATIONS_ERROR;
|
||||
c_result = PyString_AsString(result); /*xxx Error checking?? */
|
||||
c_result = PyBytes_AsString(result); /*xxx Error checking?? */
|
||||
|
||||
/* according to the sasl docs, we should malloc() the returned
|
||||
string only for calls where interact->id == SASL_CB_PASS, so we
|
||||
|
@ -715,7 +718,7 @@ l_ldap_sasl_interactive_bind_s( LDAPObject* self, PyObject* args )
|
|||
/* now we extract the sasl mechanism from the SASL Object */
|
||||
mechanism = PyObject_GetAttrString(SASLObject, "mech");
|
||||
if (mechanism == NULL) return NULL;
|
||||
c_mechanism = PyString_AsString(mechanism);
|
||||
c_mechanism = PyBytes_AsString(mechanism);
|
||||
Py_DECREF(mechanism);
|
||||
mechanism = NULL;
|
||||
|
||||
|
@ -738,7 +741,7 @@ l_ldap_sasl_interactive_bind_s( LDAPObject* self, PyObject* args )
|
|||
|
||||
if (msgid != LDAP_SUCCESS)
|
||||
return LDAPerror( self->ldap, "ldap_sasl_interactive_bind_s" );
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -782,7 +785,7 @@ l_ldap_cancel( LDAPObject* self, PyObject* args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_cancel" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -828,7 +831,7 @@ l_ldap_compare_ext( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_compare_ext" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
|
||||
|
@ -869,7 +872,7 @@ l_ldap_delete_ext( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_delete_ext" );
|
||||
|
||||
return PyInt_FromLong(msgid);
|
||||
return PyLong_FromLong(msgid);
|
||||
}
|
||||
|
||||
|
||||
|
@ -917,7 +920,7 @@ l_ldap_modify_ext( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_modify_ext" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
|
||||
|
@ -961,7 +964,7 @@ l_ldap_rename( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_rename" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1156,7 +1159,7 @@ l_ldap_search_ext( LDAPObject* self, PyObject* args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_search_ext" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1310,7 +1313,7 @@ l_ldap_passwd( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_passwd" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1358,7 +1361,7 @@ l_ldap_extended_operation( LDAPObject* self, PyObject *args )
|
|||
if ( ldaperror!=LDAP_SUCCESS )
|
||||
return LDAPerror( self->ldap, "ldap_extended_operation" );
|
||||
|
||||
return PyInt_FromLong( msgid );
|
||||
return PyLong_FromLong( msgid );
|
||||
}
|
||||
|
||||
/* methods */
|
||||
|
|
|
@ -90,7 +90,7 @@ LDAPberval_to_object(const struct berval *bv)
|
|||
Py_INCREF(ret);
|
||||
}
|
||||
else {
|
||||
ret = PyString_FromStringAndSize(bv->bv_val, bv->bv_len);
|
||||
ret = PyUnicode_FromStringAndSize(bv->bv_val, bv->bv_len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -35,5 +35,12 @@ typedef int Py_ssize_t;
|
|||
void LDAPadd_methods( PyObject*d, PyMethodDef*methods );
|
||||
#define PyNone_Check(o) ((o) == Py_None)
|
||||
|
||||
/* Py2/3 compatibility */
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
#define PyBytes_Check PyString_Check
|
||||
#define PyBytes_Size PyString_Size
|
||||
#define PyBytes_AsString PyString_AsString
|
||||
#endif
|
||||
|
||||
#endif /* __h_common_ */
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ static PyObject* forward;
|
|||
|
||||
PyObject*
|
||||
LDAPconstant( int val ) {
|
||||
PyObject *i = PyInt_FromLong( val );
|
||||
PyObject *i = PyLong_FromLong( val );
|
||||
PyObject *s = PyObject_GetItem( reverse, i );
|
||||
if (s == NULL) {
|
||||
PyErr_Clear();
|
||||
|
@ -39,7 +39,7 @@ LDAPinit_constants( PyObject* d )
|
|||
|
||||
#define add_int(d, name) \
|
||||
{ \
|
||||
PyObject *i = PyInt_FromLong(LDAP_##name); \
|
||||
PyObject *i = PyLong_FromLong(LDAP_##name); \
|
||||
PyDict_SetItemString( d, #name, i ); \
|
||||
Py_DECREF(i); \
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ LDAPinit_constants( PyObject* d )
|
|||
|
||||
/* reversibles */
|
||||
|
||||
zero = PyInt_FromLong( 0 );
|
||||
zero = PyLong_FromLong( 0 );
|
||||
PyDict_SetItem( reverse, zero, Py_None );
|
||||
Py_DECREF( zero );
|
||||
|
||||
|
@ -266,11 +266,11 @@ LDAPinit_constants( PyObject* d )
|
|||
add_int(d,AVA_NONPRINTABLE);
|
||||
|
||||
/*add_int(d,OPT_ON);*/
|
||||
obj = PyInt_FromLong(1);
|
||||
obj = PyLong_FromLong(1);
|
||||
PyDict_SetItemString( d, "OPT_ON", obj );
|
||||
Py_DECREF(obj);
|
||||
/*add_int(d,OPT_OFF);*/
|
||||
obj = PyInt_FromLong(0);
|
||||
obj = PyLong_FromLong(0);
|
||||
PyDict_SetItemString( d, "OPT_OFF", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
|
@ -283,102 +283,102 @@ LDAPinit_constants( PyObject* d )
|
|||
|
||||
/* author */
|
||||
|
||||
author = PyString_FromString("python-ldap Project");
|
||||
author = PyUnicode_FromString("python-ldap Project");
|
||||
PyDict_SetItemString(d, "__author__", author);
|
||||
Py_DECREF(author);
|
||||
|
||||
/* add_int(d,LIBLDAP_R); */
|
||||
#ifdef HAVE_LIBLDAP_R
|
||||
obj = PyInt_FromLong(1);
|
||||
obj = PyLong_FromLong(1);
|
||||
#else
|
||||
obj = PyInt_FromLong(0);
|
||||
obj = PyLong_FromLong(0);
|
||||
#endif
|
||||
PyDict_SetItemString( d, "LIBLDAP_R", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
/* add_int(d,SASL); */
|
||||
#ifdef HAVE_SASL
|
||||
obj = PyInt_FromLong(1);
|
||||
obj = PyLong_FromLong(1);
|
||||
#else
|
||||
obj = PyInt_FromLong(0);
|
||||
obj = PyLong_FromLong(0);
|
||||
#endif
|
||||
PyDict_SetItemString( d, "SASL_AVAIL", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
/* add_int(d,TLS); */
|
||||
#ifdef HAVE_TLS
|
||||
obj = PyInt_FromLong(1);
|
||||
obj = PyLong_FromLong(1);
|
||||
#else
|
||||
obj = PyInt_FromLong(0);
|
||||
obj = PyLong_FromLong(0);
|
||||
#endif
|
||||
PyDict_SetItemString( d, "TLS_AVAIL", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_MANAGEDSAIT);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_MANAGEDSAIT);
|
||||
PyDict_SetItemString( d, "CONTROL_MANAGEDSAIT", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_PROXY_AUTHZ);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_PROXY_AUTHZ);
|
||||
PyDict_SetItemString( d, "CONTROL_PROXY_AUTHZ", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_SUBENTRIES);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_SUBENTRIES);
|
||||
PyDict_SetItemString( d, "CONTROL_SUBENTRIES", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_VALUESRETURNFILTER);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_VALUESRETURNFILTER);
|
||||
PyDict_SetItemString( d, "CONTROL_VALUESRETURNFILTER", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_ASSERT);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_ASSERT);
|
||||
PyDict_SetItemString( d, "CONTROL_ASSERT", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_PRE_READ);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_PRE_READ);
|
||||
PyDict_SetItemString( d, "CONTROL_PRE_READ", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_POST_READ);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_POST_READ);
|
||||
PyDict_SetItemString( d, "CONTROL_POST_READ", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_SORTREQUEST);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_SORTREQUEST);
|
||||
PyDict_SetItemString( d, "CONTROL_SORTREQUEST", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_SORTRESPONSE);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_SORTRESPONSE);
|
||||
PyDict_SetItemString( d, "CONTROL_SORTRESPONSE", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_PAGEDRESULTS);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_PAGEDRESULTS);
|
||||
PyDict_SetItemString( d, "CONTROL_PAGEDRESULTS", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_SYNC);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_SYNC);
|
||||
PyDict_SetItemString( d, "CONTROL_SYNC", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_SYNC_STATE);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_SYNC_STATE);
|
||||
PyDict_SetItemString( d, "CONTROL_SYNC_STATE", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_SYNC_DONE);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_SYNC_DONE);
|
||||
PyDict_SetItemString( d, "CONTROL_SYNC_DONE", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_SYNC_INFO);
|
||||
obj = PyUnicode_FromString(LDAP_SYNC_INFO);
|
||||
PyDict_SetItemString( d, "SYNC_INFO", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_PASSWORDPOLICYREQUEST);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_PASSWORDPOLICYREQUEST);
|
||||
PyDict_SetItemString( d, "CONTROL_PASSWORDPOLICYREQUEST", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_PASSWORDPOLICYRESPONSE);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_PASSWORDPOLICYRESPONSE);
|
||||
PyDict_SetItemString( d, "CONTROL_PASSWORDPOLICYRESPONSE", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
obj = PyString_FromString(LDAP_CONTROL_RELAX);
|
||||
obj = PyUnicode_FromString(LDAP_CONTROL_RELAX);
|
||||
PyDict_SetItemString( d, "CONTROL_RELAX", obj );
|
||||
Py_DECREF(obj);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ LDAPerror( LDAP *l, char *msg )
|
|||
if (info == NULL)
|
||||
return NULL;
|
||||
|
||||
str = PyString_FromString(ldap_err2string(errnum));
|
||||
str = PyUnicode_FromString(ldap_err2string(errnum));
|
||||
if (str)
|
||||
PyDict_SetItemString( info, "desc", str );
|
||||
Py_XDECREF(str);
|
||||
|
@ -83,7 +83,7 @@ LDAPerror( LDAP *l, char *msg )
|
|||
if (ldap_get_option(l, LDAP_OPT_MATCHED_DN, &matched) >= 0
|
||||
&& matched != NULL) {
|
||||
if (*matched != '\0') {
|
||||
str = PyString_FromString(matched);
|
||||
str = PyUnicode_FromString(matched);
|
||||
if (str)
|
||||
PyDict_SetItemString( info, "matched", str );
|
||||
Py_XDECREF(str);
|
||||
|
@ -92,14 +92,14 @@ LDAPerror( LDAP *l, char *msg )
|
|||
}
|
||||
|
||||
if (errnum == LDAP_REFERRAL) {
|
||||
str = PyString_FromString(msg);
|
||||
str = PyUnicode_FromString(msg);
|
||||
if (str)
|
||||
PyDict_SetItemString( info, "info", str );
|
||||
Py_XDECREF(str);
|
||||
} else if (ldap_get_option(l, LDAP_OPT_ERROR_STRING, &error) >= 0
|
||||
&& error != NULL) {
|
||||
if (error != '\0') {
|
||||
str = PyString_FromString(error);
|
||||
str = PyUnicode_FromString(error);
|
||||
if (str)
|
||||
PyDict_SetItemString( info, "info", str );
|
||||
Py_XDECREF(str);
|
||||
|
|
|
@ -69,6 +69,7 @@ Tuple_to_LDAPControl( PyObject* tup )
|
|||
char iscritical;
|
||||
struct berval berbytes;
|
||||
PyObject *bytes;
|
||||
PyObject *bytes_utf8;
|
||||
LDAPControl *lc = NULL;
|
||||
Py_ssize_t len;
|
||||
|
||||
|
@ -103,9 +104,10 @@ Tuple_to_LDAPControl( PyObject* tup )
|
|||
berbytes.bv_len = 0;
|
||||
berbytes.bv_val = NULL;
|
||||
}
|
||||
else if (PyString_Check(bytes)) {
|
||||
berbytes.bv_len = PyString_Size(bytes);
|
||||
berbytes.bv_val = PyString_AsString(bytes);
|
||||
else if (PyUnicode_Check(bytes)) {
|
||||
bytes_utf8 = PyUnicode_AsUTF8String(bytes);
|
||||
berbytes.bv_len = PyBytes_Size(bytes);
|
||||
berbytes.bv_val = PyBytes_AsString(bytes);
|
||||
}
|
||||
else {
|
||||
PyErr_SetObject(PyExc_TypeError, Py_BuildValue("sO",
|
||||
|
|
|
@ -192,7 +192,7 @@ LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls, int add_intermedi
|
|||
if (refs) {
|
||||
Py_ssize_t i;
|
||||
for (i=0; refs[i] != NULL; i++) {
|
||||
PyObject *refstr = PyString_FromString(refs[i]);
|
||||
PyObject *refstr = PyUnicode_FromString(refs[i]);
|
||||
PyList_Append(reflist, refstr);
|
||||
Py_DECREF(refstr);
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ LDAP_get_option(LDAPObject *self, int option)
|
|||
extensions = PyTuple_New(num_extensions);
|
||||
for (i = 0; i < num_extensions; i++)
|
||||
PyTuple_SET_ITEM(extensions, i,
|
||||
PyString_FromString(apiinfo.ldapai_extensions[i]));
|
||||
PyUnicode_FromString(apiinfo.ldapai_extensions[i]));
|
||||
|
||||
/* return api info as a dictionary */
|
||||
v = Py_BuildValue("{s:i, s:i, s:i, s:s, s:i, s:O}",
|
||||
|
@ -272,7 +272,7 @@ LDAP_get_option(LDAPObject *self, int option)
|
|||
if (self) LDAP_END_ALLOW_THREADS(self);
|
||||
if (res != LDAP_OPT_SUCCESS)
|
||||
return option_error(res, "ldap_get_option");
|
||||
return PyInt_FromLong(intval);
|
||||
return PyLong_FromLong(intval);
|
||||
|
||||
case LDAP_OPT_HOST_NAME:
|
||||
case LDAP_OPT_URI:
|
||||
|
@ -322,7 +322,7 @@ LDAP_get_option(LDAPObject *self, int option)
|
|||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
v = PyString_FromString(strval);
|
||||
v = PyUnicode_FromString(strval);
|
||||
ldap_memfree(strval);
|
||||
return v;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ PyObject* c_string_array_to_python(char **string_array)
|
|||
py_list = PyList_New(count);
|
||||
count = 0;
|
||||
for (s=string_array; *s != 0; s++){
|
||||
PyList_SetItem(py_list, count, PyString_FromString(*s));
|
||||
PyList_SetItem(py_list, count, PyUnicode_FromString(*s));
|
||||
count++;
|
||||
}
|
||||
} else py_list=PyList_New(0);
|
||||
|
@ -52,7 +52,7 @@ PyObject* schema_extension_to_python(LDAPSchemaExtensionItem **extensions)
|
|||
for (e = extensions; *e !=0; e++) {
|
||||
item_tuple = PyTuple_New(2);
|
||||
PyTuple_SetItem(item_tuple, 0,
|
||||
PyString_FromString((*e)->lsei_name));
|
||||
PyUnicode_FromString((*e)->lsei_name));
|
||||
PyTuple_SetItem(item_tuple, 1,
|
||||
c_string_array_to_python((*e)->lsei_values));
|
||||
PyList_SetItem(py_list, count, item_tuple);
|
||||
|
@ -89,7 +89,7 @@ l_ldap_str2objectclass(PyObject* self, PyObject *args)
|
|||
return NULL;
|
||||
o = ldap_str2objectclass( oc_string, &ret, &errp, flag);
|
||||
if (ret) {
|
||||
py_ret = PyInt_FromLong(ret);
|
||||
py_ret = PyLong_FromLong(ret);
|
||||
return py_ret;
|
||||
}
|
||||
|
||||
|
@ -98,16 +98,16 @@ l_ldap_str2objectclass(PyObject* self, PyObject *args)
|
|||
oc_at_oids_must = c_string_array_to_python(o->oc_at_oids_must);
|
||||
oc_at_oids_may = c_string_array_to_python(o->oc_at_oids_may);
|
||||
py_ret = PyList_New(9);
|
||||
PyList_SetItem(py_ret, 0, PyString_FromString(o->oc_oid));
|
||||
PyList_SetItem(py_ret, 0, PyUnicode_FromString(o->oc_oid));
|
||||
PyList_SetItem(py_ret, 1, oc_names);
|
||||
if (o->oc_desc) {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(o->oc_desc));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(o->oc_desc));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(""));
|
||||
}
|
||||
PyList_SetItem(py_ret, 3, PyInt_FromLong(o->oc_obsolete));
|
||||
PyList_SetItem(py_ret, 3, PyLong_FromLong(o->oc_obsolete));
|
||||
PyList_SetItem(py_ret, 4, oc_sup_oids);
|
||||
PyList_SetItem(py_ret, 5, PyInt_FromLong(o->oc_kind));
|
||||
PyList_SetItem(py_ret, 5, PyLong_FromLong(o->oc_kind));
|
||||
PyList_SetItem(py_ret, 6, oc_at_oids_must);
|
||||
PyList_SetItem(py_ret, 7, oc_at_oids_may);
|
||||
|
||||
|
@ -136,50 +136,50 @@ l_ldap_str2attributetype(PyObject* self, PyObject *args)
|
|||
return NULL;
|
||||
a = ldap_str2attributetype( at_string, &ret, &errp, flag);
|
||||
if (ret) {
|
||||
py_ret = PyInt_FromLong(ret);
|
||||
py_ret = PyLong_FromLong(ret);
|
||||
return py_ret;
|
||||
}
|
||||
|
||||
py_ret = PyList_New(15);
|
||||
PyList_SetItem(py_ret, 0, PyString_FromString(a->at_oid));
|
||||
PyList_SetItem(py_ret, 0, PyUnicode_FromString(a->at_oid));
|
||||
at_names = c_string_array_to_python(a->at_names);
|
||||
PyList_SetItem(py_ret, 1, at_names);
|
||||
if (a->at_desc) {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(a->at_desc));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(a->at_desc));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(""));
|
||||
}
|
||||
PyList_SetItem(py_ret, 3, PyInt_FromLong(a->at_obsolete));
|
||||
PyList_SetItem(py_ret, 3, PyLong_FromLong(a->at_obsolete));
|
||||
if (a->at_sup_oid) {
|
||||
PyList_SetItem(py_ret, 4, PyString_FromString(a->at_sup_oid));
|
||||
PyList_SetItem(py_ret, 4, PyUnicode_FromString(a->at_sup_oid));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 4, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 4, PyUnicode_FromString(""));
|
||||
}
|
||||
if (a->at_equality_oid) {
|
||||
PyList_SetItem(py_ret, 5, PyString_FromString(a->at_equality_oid));
|
||||
PyList_SetItem(py_ret, 5, PyUnicode_FromString(a->at_equality_oid));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 5, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 5, PyUnicode_FromString(""));
|
||||
}
|
||||
if (a->at_ordering_oid) {
|
||||
PyList_SetItem(py_ret, 6, PyString_FromString(a->at_ordering_oid));
|
||||
PyList_SetItem(py_ret, 6, PyUnicode_FromString(a->at_ordering_oid));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 6, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 6, PyUnicode_FromString(""));
|
||||
}
|
||||
if (a->at_substr_oid) {
|
||||
PyList_SetItem(py_ret, 7, PyString_FromString(a->at_substr_oid));
|
||||
PyList_SetItem(py_ret, 7, PyUnicode_FromString(a->at_substr_oid));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 7, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 7, PyUnicode_FromString(""));
|
||||
}
|
||||
if (a->at_syntax_oid) {
|
||||
PyList_SetItem(py_ret, 8, PyString_FromString(a->at_syntax_oid));
|
||||
PyList_SetItem(py_ret, 8, PyUnicode_FromString(a->at_syntax_oid));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 8, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 8, PyUnicode_FromString(""));
|
||||
}
|
||||
PyList_SetItem(py_ret, 9, PyInt_FromLong(a->at_syntax_len));
|
||||
PyList_SetItem(py_ret,10, PyInt_FromLong(a->at_single_value));
|
||||
PyList_SetItem(py_ret,11, PyInt_FromLong(a->at_collective));
|
||||
PyList_SetItem(py_ret,12, PyInt_FromLong(a->at_no_user_mod));
|
||||
PyList_SetItem(py_ret,13, PyInt_FromLong(a->at_usage));
|
||||
PyList_SetItem(py_ret, 9, PyLong_FromLong(a->at_syntax_len));
|
||||
PyList_SetItem(py_ret,10, PyLong_FromLong(a->at_single_value));
|
||||
PyList_SetItem(py_ret,11, PyLong_FromLong(a->at_collective));
|
||||
PyList_SetItem(py_ret,12, PyLong_FromLong(a->at_no_user_mod));
|
||||
PyList_SetItem(py_ret,13, PyLong_FromLong(a->at_usage));
|
||||
|
||||
PyList_SetItem(py_ret, 14,
|
||||
schema_extension_to_python(a->at_extensions));
|
||||
|
@ -204,17 +204,17 @@ l_ldap_str2syntax(PyObject* self, PyObject *args)
|
|||
return NULL;
|
||||
s = ldap_str2syntax(syn_string, &ret, &errp, flag);
|
||||
if (ret) {
|
||||
py_ret = PyInt_FromLong(ret);
|
||||
py_ret = PyLong_FromLong(ret);
|
||||
return py_ret;
|
||||
}
|
||||
py_ret = PyList_New(4);
|
||||
PyList_SetItem(py_ret, 0, PyString_FromString(s->syn_oid));
|
||||
PyList_SetItem(py_ret, 0, PyUnicode_FromString(s->syn_oid));
|
||||
syn_names = c_string_array_to_python(s->syn_names);
|
||||
PyList_SetItem(py_ret, 1, syn_names);
|
||||
if (s->syn_desc) {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(s->syn_desc));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(s->syn_desc));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(""));
|
||||
}
|
||||
PyList_SetItem(py_ret, 3,
|
||||
schema_extension_to_python(s->syn_extensions));
|
||||
|
@ -238,23 +238,23 @@ l_ldap_str2matchingrule(PyObject* self, PyObject *args)
|
|||
return NULL;
|
||||
m = ldap_str2matchingrule(mr_string, &ret, &errp, flag);
|
||||
if (ret) {
|
||||
py_ret = PyInt_FromLong(ret);
|
||||
py_ret = PyLong_FromLong(ret);
|
||||
return py_ret;
|
||||
}
|
||||
py_ret = PyList_New(6);
|
||||
PyList_SetItem(py_ret, 0, PyString_FromString(m->mr_oid));
|
||||
PyList_SetItem(py_ret, 0, PyUnicode_FromString(m->mr_oid));
|
||||
mr_names = c_string_array_to_python(m->mr_names);
|
||||
PyList_SetItem(py_ret, 1, mr_names);
|
||||
if (m->mr_desc) {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(m->mr_desc));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(m->mr_desc));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 2, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 2, PyUnicode_FromString(""));
|
||||
}
|
||||
PyList_SetItem(py_ret, 3, PyInt_FromLong(m->mr_obsolete));
|
||||
PyList_SetItem(py_ret, 3, PyLong_FromLong(m->mr_obsolete));
|
||||
if (m->mr_syntax_oid) {
|
||||
PyList_SetItem(py_ret, 4, PyString_FromString(m->mr_syntax_oid));
|
||||
PyList_SetItem(py_ret, 4, PyUnicode_FromString(m->mr_syntax_oid));
|
||||
} else {
|
||||
PyList_SetItem(py_ret, 4, PyString_FromString(""));
|
||||
PyList_SetItem(py_ret, 4, PyUnicode_FromString(""));
|
||||
}
|
||||
PyList_SetItem(py_ret, 5,
|
||||
schema_extension_to_python(m->mr_extensions));
|
||||
|
|
|
@ -14,7 +14,7 @@ LDAPinit_version( PyObject* d )
|
|||
{
|
||||
PyObject *version;
|
||||
|
||||
version = PyString_FromString(version_str);
|
||||
version = PyUnicode_FromString(version_str);
|
||||
PyDict_SetItemString( d, "__version__", version );
|
||||
Py_DECREF(version);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue