mirror of
https://github.com/samba-team/samba.git
synced 2025-01-26 10:04:02 +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:
parent
a7633deb89
commit
4d65e3ad21
@ -97,20 +97,19 @@ static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||||||
DATA_BLOB guid_val;
|
DATA_BLOB guid_val;
|
||||||
Py_ssize_t _size;
|
Py_ssize_t _size;
|
||||||
|
|
||||||
if (!(PyUnicode_Check(str) || PyBytes_Check(str)) && !PyUnicode_Check(str)) {
|
if (PyUnicode_Check(str)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "Expected a string or bytes argument to GUID()");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyBytes_Check(str)) {
|
|
||||||
guid_val.data =
|
guid_val.data =
|
||||||
discard_const_p(uint8_t,
|
discard_const_p(uint8_t,
|
||||||
PyUnicode_AsUTF8AndSize(str, &_size));
|
PyUnicode_AsUTF8AndSize(str, &_size));
|
||||||
} else {
|
} else if (PyBytes_Check(str)) {
|
||||||
guid_val.data =
|
guid_val.data =
|
||||||
discard_const_p(uint8_t,
|
discard_const_p(uint8_t,
|
||||||
PyBytes_AsString(str));
|
PyBytes_AsString(str));
|
||||||
_size = PyBytes_Size(str);
|
_size = PyBytes_Size(str);
|
||||||
|
} else {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"Expected a string or bytes argument to GUID()");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
guid_val.length = _size;
|
guid_val.length = _size;
|
||||||
status = GUID_from_data_blob(&guid_val, guid);
|
status = GUID_from_data_blob(&guid_val, guid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user