libcli/nbt: Additionally accept unicode as string param in Py2
[kai/samba-autobuild/.git] / libcli / nbt / pynbt.c
index 254c98a4b896ac2ec86561b65e1e614c7e0701f8..032561a4bd8a7b062526aa5344576d5913478f52 100644 (file)
@@ -57,7 +57,7 @@ static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *
 
 static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
 {
-       if (PyStr_Check(obj)) {
+       if (PyStr_Check(obj) || PyUnicode_Check(obj)) {
                *dest_addr = PyStr_AsString(obj);
                *dest_port = NBT_NAME_SERVICE_PORT;
                return true;
@@ -69,7 +69,7 @@ static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, u
                        return false;
                }
 
-               if (!PyStr_Check(PyTuple_GetItem(obj, 0))) {
+               if (!(PyStr_Check(PyTuple_GetItem(obj, 0)) || PyUnicode_Check(PyTuple_GetItem(obj, 0)))) {
                        PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string");
                        return false;
                }
@@ -111,7 +111,7 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
                }
        }
 
-       if (PyStr_Check(obj)) {
+       if (PyStr_Check(obj) || PyUnicode_Check(obj)) {
                /* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
                name->name = PyStr_AsString(obj);
                name->scope = NULL;