Commit 8738db2a authored by Noel Power's avatar Noel Power Committed by Karolin Seeger

lib/ldb: Use new PYARG_ES format for parseTuple

While 'es' format works great for unicode (in python2) and
str (in python3) The behaviour with str (in python2) is unexpected.
In python2 the str type is (re-encoded) with the specified encoding.
In python2 the 'et' type would be a better match, that ensures 'str'
type is treated like it was with 's' (no reencoding) and unicode is
encoded with the specified encoding. However in python3 'et' allows
byte (or bytearray) params to be accepted (with no reencoding), we
don't want this. This patch adds a new PYARG_STR_UNI format code which
is a hybrid, in python2 it evaluates to 'et' and in python3 'es' and
so gives the desired behaviour for each python version.

Additionally remove the associated known fail.

BUG: default avatarNoel Power <>
Reviewed-by: default avatarDouglas Bagnall <>

Autobuild-User(master): Douglas Bagnall <>
Autobuild-Date(master): Sun Jan 13 03:53:00 CET 2019 on sn-devel-144

(cherry picked from commit 8900e0b4)
parent 869ae9a1
......@@ -89,6 +89,9 @@ static struct ldb_message_element *PyObject_AsMessageElement(
#define PyStr_AsUTF8 PyUnicode_AsUTF8
#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
#define PyInt_FromLong PyLong_FromLong
#define PYARG_STR_UNI "es"
#define PyStr_Check PyString_Check
#define PyStr_FromString PyString_FromString
......@@ -97,6 +100,8 @@ static struct ldb_message_element *PyObject_AsMessageElement(
#define PyStr_FromFormatV PyString_FromFormatV
#define PyStr_AsUTF8 PyString_AsString
#define PYARG_STR_UNI "et"
const char *PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr);
const char *
PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr)
......@@ -865,7 +870,7 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa
PyLdbDnObject *py_ret = NULL;
const char * const kwnames[] = { "ldb", "dn", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oes",
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O"PYARG_STR_UNI,
discard_const_p(char *, kwnames),
&py_ldb, "utf8", &str))
goto out;
......@@ -349,5 +349,3 @@
# Disabling NTLM means you can't use samr to change the password
# Ldb test api.SimpleLdb.test_utf8_ldb_Dn is expected to fail
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment