diff options
author | Graydon, Tracy <tracy.graydon@intel.com> | 2012-11-30 12:11:38 -0800 |
---|---|---|
committer | Graydon, Tracy <tracy.graydon@intel.com> | 2012-11-30 12:11:38 -0800 |
commit | 1a48cb6e7504163228442a2894af21af66e93eb2 (patch) | |
tree | 8d117e9778e44c485d187679bf5250c52e02975d /gio/pygio-utils.c | |
parent | e319390cebb45884f62ca3c2b22984d8ed82b941 (diff) | |
download | pygobject2-1a48cb6e7504163228442a2894af21af66e93eb2.tar.gz pygobject2-1a48cb6e7504163228442a2894af21af66e93eb2.tar.bz2 pygobject2-1a48cb6e7504163228442a2894af21af66e93eb2.zip |
Update to 2.28 for TINF-96
Diffstat (limited to 'gio/pygio-utils.c')
-rw-r--r-- | gio/pygio-utils.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/gio/pygio-utils.c b/gio/pygio-utils.c index be41453..f89c4b9 100644 --- a/gio/pygio-utils.c +++ b/gio/pygio-utils.c @@ -22,6 +22,7 @@ */ #include "pygio-utils.h" +#include <pyglib-python-compat.h> /** * pygio_check_cancellable: @@ -115,14 +116,28 @@ pygio_pylist_to_uri_glist(PyObject *pyfile_list) len = PySequence_Size(pyfile_list); for (i = 0; i < len; i++) { - item = PySequence_GetItem(pyfile_list, i); - if (!PyString_Check(item)) { + item = PySequence_GetItem(pyfile_list, i); + if (!PYGLIB_PyUnicode_Check(item)) { PyErr_SetString(PyExc_TypeError, "files must be strings"); g_list_free(file_list); return NULL; } - file_list = g_list_prepend(file_list, PyString_AsString(item)); + +#if PY_VERSION_HEX < 0x03000000 + file_list = g_list_prepend(file_list, g_strdup(PyString_AsString(item))); +#else + { + PyObject *utf8_bytes_obj = PyUnicode_AsUTF8String (item); + if (!utf8_bytes_obj) { + g_list_free(file_list); + return NULL; + } + file_list = g_list_prepend(file_list, g_strdup(PyBytes_AsString(utf8_bytes_obj))); + Py_DECREF (utf8_bytes_obj); + } +#endif + } file_list = g_list_reverse(file_list); @@ -144,9 +159,9 @@ strv_to_pylist (char **strv) len = strv ? g_strv_length (strv) : 0; list = PyList_New (len); - for (i = 0; i < len; i++) - PyList_SetItem (list, i, PyString_FromString (strv[i])); - + for (i = 0; i < len; i++) { + PyList_SetItem (list, i, PYGLIB_PyUnicode_FromString (strv[i])); + } return list; } @@ -191,7 +206,7 @@ pylist_to_strv (PyObject *list, return FALSE; } - if (!PyString_Check (item)) + if (!PYGLIB_PyUnicode_Check (item)) { Py_DECREF (item); g_strfreev (ret); @@ -199,7 +214,20 @@ pylist_to_strv (PyObject *list, return FALSE; } +#if PY_VERSION_HEX < 0x03000000 ret[i] = g_strdup (PyString_AsString (item)); +#else + { + PyObject *utf8_bytes_obj = PyUnicode_AsUTF8String (item); + if (!utf8_bytes_obj) { + Py_DECREF (item); + g_strfreev (ret); + return FALSE; + } + ret[i] = g_strdup (PyBytes_AsString(utf8_bytes_obj)); + Py_DECREF (utf8_bytes_obj); + } +#endif Py_DECREF (item); } |