lib/ldb: Use new PYARG_ES format for parseTuple
authorNoel Power <noel.power@suse.com>
Mon, 12 Nov 2018 16:06:10 +0000 (16:06 +0000)
committerKarolin Seeger <kseeger@samba.org>
Mon, 21 Jan 2019 08:48:15 +0000 (09:48 +0100)
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=13616
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas 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

(cherry picked from commit 8900e0b4cb05613df9cbeeb8b8253273b06b3c17)

lib/ldb/pyldb.c
selftest/knownfail

index a6290d9db09f0120f08ecff19a41619e58a466ae..e84cbbb184faa007df4296061087f5981b53974c 100644 (file)
@@ -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"
+
 #else
 #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;
index f5d68d3ce4624d4331d5f1006a516de3e4e432ac..baf3d57a31a0f58e565018ef8709adc3399b42ac 100644 (file)
 # Disabling NTLM means you can't use samr to change the password
 ^samba.tests.ntlmdisabled.python\(ktest\).ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\)
 ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).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)