Commit 8900e0b4 authored by Noel Power's avatar Noel Power Committed by Douglas Bagnall

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
parent 45f5337f
......@@ -91,6 +91,8 @@ static PyTypeObject PyLdbBytesType;
#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
#define PyInt_FromLong PyLong_FromLong
#define PYARG_STR_UNI "es"
static PyObject *PyLdbBytes_FromStringAndSize(const char *msg, int size)
PyObject* result = NULL;
......@@ -109,6 +111,8 @@ static PyObject *PyLdbBytes_FromStringAndSize(const char *msg, int size)
#define PyStr_AsUTF8 PyString_AsString
#define PyLdbBytes_FromStringAndSize PyString_FromStringAndSize
#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)
......@@ -901,7 +905,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;
......@@ -363,6 +363,3 @@
# 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