From: Noel Power Date: Thu, 22 Feb 2018 12:49:36 +0000 (+0000) Subject: s4/dsdb: python3 api should take 'bytes' X-Git-Tag: talloc-2.1.13~257 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0d65c1ef65b1485ae772ac87a52bb58611d45c72;p=thirdparty%2Fsamba.git s4/dsdb: python3 api should take 'bytes' Attributes are properly represented by 'bytes' and *maybe* can be converted into strings (if they are text). py_dsdb_normalise_attributes currently expects strings, this is fine in python2 however in python3 we need to actually pass a 'bytes' class. Signed-off-by: Noel Power Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c index d38d7095efa..8d84a16dd18 100644 --- a/source4/dsdb/pydsdb.c +++ b/source4/dsdb/pydsdb.c @@ -625,7 +625,6 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args) TALLOC_CTX *tmp_ctx; WERROR werr; Py_ssize_t i; - Py_ssize_t _size; PyTypeObject *py_type = NULL; PyObject *module = NULL; @@ -688,13 +687,16 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args) for (i = 0; i < el->num_values; i++) { PyObject *item = PyList_GetItem(el_list, i); - if (!PyStr_Check(item)) { - PyErr_Format(PyExc_TypeError, "ldif_elements should be strings"); + if (!PyBytes_Check(item)) { + PyErr_Format(PyExc_TypeError, + "ldif_element type should be " + PY_DESC_PY3_BYTES + ); talloc_free(tmp_ctx); return NULL; } - el->values[i].data = (uint8_t *)PyStr_AsUTF8AndSize(item, &_size);; - el->values[i].length = _size; + el->values[i].data = (uint8_t *)PyBytes_AsString(item); + el->values[i].length = PyBytes_Size(item); } }