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: https://bugzilla.samba.org/show_bug.cgi?id=13616Signed-off-by: default avatarNoel Power <noel.power@suse.com>
Reviewed-by: default avatarDouglas Bagnall <douglas.bagnall@catalyst.net.nz>

Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
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 @@
^samba.tests.ntlmdisabled.python\(ktest\).python2.ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\)
^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python3.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python2.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
# Ldb test api.SimpleLdb.test_utf8_ldb_Dn is expected to fail
^ldb.python.api.SimpleLdb.test_utf8_encoded_ldb_Dn(none)
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