1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

s4-librpc: Simplify bytes or unicode input checking in python GUID() bindings

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
This commit is contained in:
Andrew Bartlett 2020-03-15 10:47:32 +13:00 committed by Noel Power
parent a7633deb89
commit 4d65e3ad21

View File

@ -97,20 +97,19 @@ static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs)
DATA_BLOB guid_val;
Py_ssize_t _size;
if (!(PyUnicode_Check(str) || PyBytes_Check(str)) && !PyUnicode_Check(str)) {
PyErr_SetString(PyExc_TypeError, "Expected a string or bytes argument to GUID()");
return -1;
}
if (!PyBytes_Check(str)) {
if (PyUnicode_Check(str)) {
guid_val.data =
discard_const_p(uint8_t,
PyUnicode_AsUTF8AndSize(str, &_size));
} else {
} else if (PyBytes_Check(str)) {
guid_val.data =
discard_const_p(uint8_t,
PyBytes_AsString(str));
_size = PyBytes_Size(str);
} else {
PyErr_SetString(PyExc_TypeError,
"Expected a string or bytes argument to GUID()");
return -1;
}
guid_val.length = _size;
status = GUID_from_data_blob(&guid_val, guid);