diff options
author | Noel Power <noel.power@suse.com> | 2018-11-12 16:06:10 +0000 |
---|---|---|
committer | Douglas Bagnall <dbagnall@samba.org> | 2019-01-13 03:53:00 +0100 |
commit | 8900e0b4cb05613df9cbeeb8b8253273b06b3c17 (patch) | |
tree | 3e823760f5e0dc88672997bf3c9ce52da1c7e49d /lib | |
parent | 45f5337f9f02faa9bc8f5501601df399c229732e (diff) | |
download | samba-8900e0b4cb05613df9cbeeb8b8253273b06b3c17.tar.gz |
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=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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ldb/pyldb.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index b417d4cf754..c98ce5d1b2b 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -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; |