summaryrefslogtreecommitdiff
path: root/gio
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:35:07 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:35:08 +0900
commitdf82aa0a770d4b3e52e96eb5c60b528ddcdb2343 (patch)
treebbf6d1c2270fe7057773ff1c2cf578ff40f704da /gio
parent095413828bd9b33e57b352f9ca80473172611202 (diff)
downloadpygobject2-df82aa0a770d4b3e52e96eb5c60b528ddcdb2343.tar.gz
pygobject2-df82aa0a770d4b3e52e96eb5c60b528ddcdb2343.tar.bz2
pygobject2-df82aa0a770d4b3e52e96eb5c60b528ddcdb2343.zip
Imported Upstream version 2.26.0upstream/2.26.0
Change-Id: I616aeca320e366d54dd6e188c260b64639305c49 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gio')
-rw-r--r--gio/Makefile.in1
-rw-r--r--gio/gappinfo.override5
-rw-r--r--gio/gfile.override8
-rw-r--r--gio/gio.override7
-rw-r--r--gio/giomodule.c153
-rw-r--r--gio/pygio-utils.c42
6 files changed, 129 insertions, 87 deletions
diff --git a/gio/Makefile.in b/gio/Makefile.in
index f7bf2eb..5315074 100644
--- a/gio/Makefile.in
+++ b/gio/Makefile.in
@@ -169,6 +169,7 @@ GIOUNIX_LIBS = @GIOUNIX_LIBS@
GIO_CFLAGS = @GIO_CFLAGS@
GIO_LIBS = @GIO_LIBS@
GI_CFLAGS = @GI_CFLAGS@
+GI_DATADIR = @GI_DATADIR@
GI_LIBS = @GI_LIBS@
GLIB_CFLAGS = @GLIB_CFLAGS@
GLIB_GENMARSHAL = @GLIB_GENMARSHAL@
diff --git a/gio/gappinfo.override b/gio/gappinfo.override
index 414769b..7f09ce8 100644
--- a/gio/gappinfo.override
+++ b/gio/gappinfo.override
@@ -106,6 +106,11 @@ _wrap_g_app_info_launch_uris(PyGObject *self, PyObject *args, PyObject *kwargs)
ret = g_app_info_launch_uris(G_APP_INFO(self->obj),
file_list, ctx, &error);
+ /* in python 3 the C strings are not internal to the Unicode string object
+ * so we now strdup when adding element to the list and must free them here
+ */
+ g_list_foreach (file_list,
+ (GFunc) g_free, NULL);
g_list_free(file_list);
if (pyg_error_check(&error))
diff --git a/gio/gfile.override b/gio/gfile.override
index 71e2d98..b50130c 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -1155,7 +1155,7 @@ _wrap_g_file_append_to_async(PyGObject *self, PyObject *args, PyObject *kwargs)
"O|OiOO:File.append_to_async",
kwlist,
&notify->callback,
- &flags, &io_priority,
+ &py_flags, &io_priority,
&pycancellable,
&notify->data))
goto error;
@@ -1203,7 +1203,7 @@ _wrap_g_file_create_async(PyGObject *self, PyObject *args, PyObject *kwargs)
"O|OiOO:File.create_async",
kwlist,
&notify->callback,
- &flags, &io_priority,
+ &py_flags, &io_priority,
&pycancellable,
&notify->data))
goto error;
@@ -1253,7 +1253,7 @@ _wrap_g_file_create_readwrite_async(PyGObject *self,
"O|OiOO:File.create_readwrite_async",
kwlist,
&notify->callback,
- &flags, &io_priority,
+ &py_flags, &io_priority,
&pycancellable,
&notify->data))
goto error;
@@ -1405,7 +1405,7 @@ _wrap_g_file_replace_async(PyGObject *self, PyObject *args, PyObject *kwargs)
kwlist,
&notify->callback,
&etag, &py_backup,
- &flags, &io_priority,
+ &py_flags, &io_priority,
&pycancellable,
&notify->data))
goto error;
diff --git a/gio/gio.override b/gio/gio.override
index 6d001b9..7fdcb1c 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -141,7 +141,7 @@ pygio_notify_allocate_buffer(PyGIONotify *notify, gsize buffer_size)
if (buffer_size > 0) {
notify->buffer = g_slice_alloc(buffer_size);
if (!notify->buffer) {
- PyErr_Format(PyExc_MemoryError, "failed to allocate %d bytes", buffer_size);
+ PyErr_Format(PyExc_MemoryError, "failed to allocate %" G_GSIZE_FORMAT " bytes", buffer_size);
return FALSE;
}
@@ -330,7 +330,12 @@ _wrap_g_content_type_guess(PyGObject *self, PyObject *args, PyObject *kwargs)
{
char *kwlist[] = {"filename", "data", "want_uncertain", NULL};
char *filename = NULL, *data = NULL, *type;
+#ifdef PY_SSIZE_T_CLEAN
+ Py_ssize_t data_size = 0;
+#else
int data_size = 0;
+#endif
+
gboolean result_uncertain, want_uncertain = FALSE;
PyObject *ret;
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 409aeef..a9ddd38 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -25,6 +25,7 @@
#include <Python.h>
#include <pyglib.h>
#include <pygobject.h>
+#include <pyglib-python-compat.h>
#include <gio/gio.h>
@@ -39,167 +40,169 @@ void pygio_add_constants(PyObject *module, const gchar *strip_prefix);
extern PyMethodDef pygio_functions[];
-DL_EXPORT(void)
-init_gio(void)
+PYGLIB_INIT_FUNCTION(_gio, "gio._gio", pygio_functions)
{
- PyObject *m, *d;
+ PyObject *d;
PyObject *tuple;
PyObject *e;
+
/* perform any initialisation required by the library here */
- m = Py_InitModule("gio._gio", pygio_functions);
- d = PyModule_GetDict(m);
+ d = PyModule_GetDict(module);
g_type_init();
pyglib_init();
- init_pygobject_check(2, 15, 2);
+ if (pygobject_init(2, 15, 2) == NULL)
+ return -1;
pygio_register_classes(d);
- pygio_add_constants(m, "G_IO_");
+ pygio_add_constants(module, "G_IO_");
- PyModule_AddStringConstant(m, "ERROR", g_quark_to_string(G_IO_ERROR));
+ PyModule_AddStringConstant(module, "ERROR", g_quark_to_string(G_IO_ERROR));
e = pyglib_register_exception_for_domain("gio.Error", G_IO_ERROR);
PyDict_SetItemString(d, "Error", e);
Py_DECREF(e);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_TYPE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_TYPE",
G_FILE_ATTRIBUTE_STANDARD_TYPE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_HIDDEN",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_HIDDEN",
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_BACKUP",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_BACKUP",
G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_SYMLINK",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_SYMLINK",
G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL",
G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_NAME",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_NAME",
G_FILE_ATTRIBUTE_STANDARD_NAME);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME",
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_EDIT_NAME",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_EDIT_NAME",
G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_COPY_NAME",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_COPY_NAME",
G_FILE_ATTRIBUTE_STANDARD_COPY_NAME);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_DESCRIPTION",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_DESCRIPTION",
G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_ICON",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_ICON",
G_FILE_ATTRIBUTE_STANDARD_ICON);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE",
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE",
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_SIZE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_SIZE",
G_FILE_ATTRIBUTE_STANDARD_SIZE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET",
G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_TARGET_URI",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_TARGET_URI",
G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_SORT_ORDER",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_SORT_ORDER",
G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ETAG_VALUE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ETAG_VALUE",
G_FILE_ATTRIBUTE_ETAG_VALUE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ID_FILE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ID_FILE",
G_FILE_ATTRIBUTE_ID_FILE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ID_FILESYSTEM",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ID_FILESYSTEM",
G_FILE_ATTRIBUTE_ID_FILESYSTEM);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_READ",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_READ",
G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_WRITE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_WRITE",
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE",
G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_DELETE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_DELETE",
G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_TRASH",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_TRASH",
G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_RENAME",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_RENAME",
G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT",
G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT",
G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT",
G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE",
G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI",
G_FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_MODIFIED",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_MODIFIED",
G_FILE_ATTRIBUTE_TIME_MODIFIED);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_MODIFIED_USEC",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_MODIFIED_USEC",
G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_ACCESS",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_ACCESS",
G_FILE_ATTRIBUTE_TIME_ACCESS);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_ACCESS_USEC",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_ACCESS_USEC",
G_FILE_ATTRIBUTE_TIME_ACCESS_USEC);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CHANGED",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CHANGED",
G_FILE_ATTRIBUTE_TIME_CHANGED);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CHANGED_USEC",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CHANGED_USEC",
G_FILE_ATTRIBUTE_TIME_CHANGED_USEC);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CREATED",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CREATED",
G_FILE_ATTRIBUTE_TIME_CREATED);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CREATED_USEC",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CREATED_USEC",
G_FILE_ATTRIBUTE_TIME_CREATED_USEC);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_DEVICE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_DEVICE",
G_FILE_ATTRIBUTE_UNIX_DEVICE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_INODE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_INODE",
G_FILE_ATTRIBUTE_UNIX_INODE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_MODE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_MODE",
G_FILE_ATTRIBUTE_UNIX_MODE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_NLINK",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_NLINK",
G_FILE_ATTRIBUTE_UNIX_NLINK);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_UID",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_UID",
G_FILE_ATTRIBUTE_UNIX_UID);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_GID",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_GID",
G_FILE_ATTRIBUTE_UNIX_GID);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_RDEV",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_RDEV",
G_FILE_ATTRIBUTE_UNIX_RDEV);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_BLOCK_SIZE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_BLOCK_SIZE",
G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_BLOCKS",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_BLOCKS",
G_FILE_ATTRIBUTE_UNIX_BLOCKS);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT",
G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_DOS_IS_ARCHIVE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_DOS_IS_ARCHIVE",
G_FILE_ATTRIBUTE_DOS_IS_ARCHIVE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_DOS_IS_SYSTEM",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_DOS_IS_SYSTEM",
G_FILE_ATTRIBUTE_DOS_IS_SYSTEM);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_OWNER_USER",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_OWNER_USER",
G_FILE_ATTRIBUTE_OWNER_USER);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_OWNER_USER_REAL",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_OWNER_USER_REAL",
G_FILE_ATTRIBUTE_OWNER_USER_REAL);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_OWNER_GROUP",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_OWNER_GROUP",
G_FILE_ATTRIBUTE_OWNER_GROUP);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_THUMBNAIL_PATH",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_THUMBNAIL_PATH",
G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_THUMBNAILING_FAILED",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_THUMBNAILING_FAILED",
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_SIZE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_SIZE",
G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_FREE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_FREE",
G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_TYPE",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_TYPE",
G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_READONLY",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_READONLY",
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW",
G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_GVFS_BACKEND",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_GVFS_BACKEND",
G_FILE_ATTRIBUTE_GVFS_BACKEND);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_SELINUX_CONTEXT",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_SELINUX_CONTEXT",
G_FILE_ATTRIBUTE_SELINUX_CONTEXT);
- PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TRASH_ITEM_COUNT",
+ PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TRASH_ITEM_COUNT",
G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT);
-
- PyModule_AddStringConstant(m, "ERROR", g_quark_to_string(G_IO_ERROR));
+
+ PyModule_AddStringConstant(module, "ERROR", g_quark_to_string(G_IO_ERROR));
/* pygio version */
tuple = Py_BuildValue ("(iii)",
PYGIO_MAJOR_VERSION,
PYGIO_MINOR_VERSION,
PYGIO_MICRO_VERSION);
- PyDict_SetItemString(d, "pygio_version", tuple);
+ PyDict_SetItemString(d, "pygio_version", tuple);
Py_DECREF(tuple);
+
+ return 0;
}
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);
}