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)
committerDouglas Bagnall <dbagnall@samba.org>
Sun, 13 Jan 2019 02:53:00 +0000 (03:53 +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

lib/ldb/pyldb.c
selftest/knownfail

index b417d4cf754d8add2b94ffcbabcc2407a119ad0c..c98ce5d1b2b5b239cd42ca572f9ce8111b6ae180 100644 (file)
@@ -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;
index 254b61edf5eb3355021ee854362eaf743b2675dc..abbbd889c7109f96766f67b833e164980230c531 100644 (file)
 ^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)
-