[Commits] [SCM] claws branch, gtk3, updated. 3.16.0-916-gb0542c38f
paul at claws-mail.org
paul at claws-mail.org
Thu Feb 6 13:18:43 CET 2020
The branch, gtk3 has been updated
via b0542c38f325eb1f5f3a2cf48daf892fa11ed2f1 (commit)
from aaff9087b693096732bd0f3ba482902114081ee3 (commit)
Summary of changes:
AUTHORS | 2 +-
configure.ac | 23 +++++------
src/gtk/authors.h | 1 +
src/plugins/python/Makefile.am | 4 +-
src/plugins/python/accounttype.c | 13 +++----
src/plugins/python/clawsmailmodule.c | 39 ++++++++++++-------
src/plugins/python/composewindowtype.c | 19 +++++-----
src/plugins/python/folderpropertiestype.c | 5 +--
src/plugins/python/foldertype.c | 35 +++++++++--------
src/plugins/python/mailboxtype.c | 9 ++---
src/plugins/python/messageinfotype.c | 19 +++++-----
src/plugins/python/python-hooks.c | 63 +++++++++++++------------------
src/plugins/python/python-hooks.h | 2 +
src/plugins/python/python_plugin.c | 17 ++++-----
14 files changed, 123 insertions(+), 128 deletions(-)
- Log -----------------------------------------------------------------
commit b0542c38f325eb1f5f3a2cf48daf892fa11ed2f1
Author: paul <paul at claws-mail.org>
Date: Thu Feb 6 12:18:38 2020 +0000
port python plugin to python3. based on patch by Raphael Michel
diff --git a/AUTHORS b/AUTHORS
index b01493eb6..721dc12ad 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -330,4 +330,4 @@ contributors (in addition to the above; based on Changelog)
Alexander Lyons Harkness
Jakub KiciĆski
Jean Delvare
-
+ Raphael Michel
diff --git a/configure.ac b/configure.ac
index 8b46bad0f..8bbc005e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1324,7 +1324,7 @@ fi
dnl Python *********************************************************************
missing_python=""
-AM_PATH_PYTHON([2.5], [
+AM_PATH_PYTHON([3.5], [
AC_PATH_PROG(PYTHON_CONFIG, python$PYTHON_VERSION-config)
if test x"$PYTHON_CONFIG" = x"" ; then
AC_PATH_PROG(PYTHON_CONFIG, python-config)
@@ -1340,11 +1340,15 @@ AM_PATH_PYTHON([2.5], [
missing_python="python-config"
fi
+ PKG_CHECK_MODULES(PYGOBJECT, pygobject-3.0, HAVE_PYGOBJ=yes, HAVE_PYGOBJ=no)
+ AC_SUBST(PYGOBJECT_LIBS)
+ AC_SUBST(PYGOBJECT_CFLAGS)
+
if test x"$HAVE_PYTHON" = xyes; then
_save_libs="$LIBS"
if test x"$platform_win32" = xno; then
# libpython.so
- PYTHON_SHARED_LIB="libpython${PYTHON_VERSION}.so"
+ PYTHON_SHARED_LIB="libpython${PYTHON_VERSION}m.so"
AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl"])
AC_MSG_CHECKING([whether to dlopen $PYTHON_SHARED_LIB works])
AC_RUN_IFELSE(
@@ -1352,7 +1356,7 @@ AM_PATH_PYTHON([2.5], [
[#include <dlfcn.h>
#define PYTHON_SO_FILE "${PYTHON_SHARED_LIB}"
],
- [if (!dlopen(PYTHON_SO_FILE, RTLD_NOW | RTLD_GLOBAL)) return 1; return 0;])
+ [if (!dlopen(PYTHON_SO_FILE, RTLD_NOW | RTLD_GLOBAL)) { return 1; } else { return 0; }])
],
[found_libpython_so="yes"],
[found_libpython_so="no"],
@@ -1368,12 +1372,6 @@ AM_PATH_PYTHON([2.5], [
fi
LIBS="$_save_libs";
fi
- if test x"$HAVE_PYTHON" = xyes; then
- PKG_CHECK_MODULES(PYGTK, pygtk-2.0 >= 2.10.3, [AC_DEFINE(ENABLE_PYTHON, [1], [Enable Python support])], HAVE_PYTHON=no)
- if test x"$HAVE_PYTHON" = xno; then
- missing_python="pygtk-2.0 >= 2.10.3"
- fi
- fi
], [
HAVE_PYTHON=no
missing_python="python interpreter"
@@ -1381,8 +1379,8 @@ AM_PATH_PYTHON([2.5], [
AC_SUBST(PYTHON_SHARED_LIB)
AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_LIBS)
-AC_SUBST(PYGTK_CFLAGS)
-AC_SUBST(PYGTK_LIBS)
+AC_SUBST(PYGOBJECT_CFLAGS)
+AC_SUBST(PYGOBJECT_LIBS)
dnl libnotify ******************************************************************
PKG_CHECK_MODULES(libnotify, libnotify >= 0.4.3, HAVE_LIBNOTIFY=yes, HAVE_LIBNOTIFY=no)
@@ -1824,6 +1822,9 @@ if test x"$enable_python_plugin" != xno; then
if test x"$HAVE_PYTHON" = xno; then
dependencies_missing="$missing_python $dependencies_missing"
fi
+ if test x"$HAVE_PYGOBJ" = xno; then
+ dependencies_missing="pygobject-3.0 $dependencies_missing"
+ fi
if test x"$dependencies_missing" = x; then
PLUGINS="$PLUGINS python"
diff --git a/src/gtk/authors.h b/src/gtk/authors.h
index 6034aeccf..48c78db19 100644
--- a/src/gtk/authors.h
+++ b/src/gtk/authors.h
@@ -224,6 +224,7 @@ static char *CONTRIBS_LIST[] = {
"Bram Metsch",
"Hanno Meyer-Thurow",
"George Michaelson",
+"Raphael Michel",
"Florian Mickler",
"Neill Miller",
"Suzuki Mio",
diff --git a/src/plugins/python/Makefile.am b/src/plugins/python/Makefile.am
index 6c2e988f1..82c502156 100644
--- a/src/plugins/python/Makefile.am
+++ b/src/plugins/python/Makefile.am
@@ -40,7 +40,7 @@ python_la_LDFLAGS = \
-avoid-version -module \
$(GLIB_LIBS) \
$(GTK_LIBS) \
- $(PYGTK_LIBS) \
+ $(PYGOBJECT_LIBS) \
$(PYTHON_LIBS)
@@ -52,8 +52,8 @@ python_la_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(ENCHANT_CFLAGS) \
+ $(PYGOBJECT_CFLAGS) \
$(PYTHON_CFLAGS) \
- $(PYGTK_CFLAGS) \
-DPYTHON_SHARED_LIB="\"$(PYTHON_SHARED_LIB)\"" \
-DENABLE_PYTHON \
-fno-strict-aliasing
diff --git a/src/plugins/python/accounttype.c b/src/plugins/python/accounttype.c
index c86a6c3c8..0fb30f23f 100644
--- a/src/plugins/python/accounttype.c
+++ b/src/plugins/python/accounttype.c
@@ -38,7 +38,7 @@ static int Account_init(clawsmail_AccountObject *self, PyObject *args, PyObject
static void Account_dealloc(clawsmail_AccountObject* self)
{
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static int Account_compare(clawsmail_AccountObject *obj1, clawsmail_AccountObject *obj2)
@@ -54,21 +54,21 @@ static int Account_compare(clawsmail_AccountObject *obj1, clawsmail_AccountObjec
static PyObject* Account_str(clawsmail_AccountObject *self)
{
if(self->account && self->account->account_name)
- return PyString_FromFormat("Account: %s", self->account->account_name);
+ return PyUnicode_FromFormat("Account: %s", self->account->account_name);
Py_RETURN_NONE;
}
static PyObject* get_account_name(clawsmail_AccountObject *self, void *closure)
{
if(self->account && self->account->account_name)
- return PyString_FromString(self->account->account_name);
+ return PyUnicode_FromString(self->account->account_name);
Py_RETURN_NONE;
}
static PyObject* get_address(clawsmail_AccountObject *self, void *closure)
{
if(self->account && self->account->address)
- return PyString_FromString(self->account->address);
+ return PyUnicode_FromString(self->account->address);
Py_RETURN_NONE;
}
@@ -93,8 +93,7 @@ static PyGetSetDef Account_getset[] = {
};
static PyTypeObject clawsmail_AccountType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"clawsmail.Account", /* tp_name*/
sizeof(clawsmail_AccountObject), /* tp_basicsize*/
0, /* tp_itemsize*/
@@ -102,7 +101,7 @@ static PyTypeObject clawsmail_AccountType = {
0, /* tp_print*/
0, /* tp_getattr*/
0, /* tp_setattr*/
- (cmpfunc)Account_compare, /* tp_compare*/
+ 0, /* tp_compare*/
0, /* tp_repr*/
0, /* tp_as_number*/
0, /* tp_as_sequence*/
diff --git a/src/plugins/python/clawsmailmodule.c b/src/plugins/python/clawsmailmodule.c
index e6eddebdd..581b73a3b 100644
--- a/src/plugins/python/clawsmailmodule.c
+++ b/src/plugins/python/clawsmailmodule.c
@@ -35,8 +35,6 @@
#define NO_IMPORT_PYGOBJECT
#include <pygobject.h>
-#define NO_IMPORT_PYGTK
-#include <pygtk/pygtk.h>
#include "main.h"
#include "mainwindow.h"
@@ -325,9 +323,9 @@ static PyObject* get_folder_tree(PyObject *self, PyObject *args)
if(PyTuple_Size(args) == 0) {
result = get_folder_tree_from_account_name(NULL);
}
- else if(PyString_Check(arg)){
+ else if(PyBytes_Check(arg)){
const char *str;
- str = PyString_AsString(arg);
+ str = PyBytes_AsString(arg);
if(!str)
return NULL;
@@ -904,21 +902,33 @@ static gboolean add_miscstuff(PyObject *module)
}
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "clawsmail",
+ "This module can be used to access some of Claws Mail's data structures\n"
+ "in order to extend or modify the user interface or automate repetitive tasks.\n"
+ "\n"
+ "Whenever possible, the interface works with standard GTK+ widgets\n"
+ "via the PyGTK bindings, so you can refer to the GTK+ / PyGTK documentation\n"
+ "to find out about all possible options.\n"
+ "\n"
+ "The interface to Claws Mail in this module is extended on a 'as-needed' basis.\n"
+ "If you're missing something specific, try contacting the author.",
+ 0,
+ ClawsMailMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC initclawsmail(void)
{
gboolean ok = TRUE;
/* create module */
- cm_module = Py_InitModule3("clawsmail", ClawsMailMethods,
- "This module can be used to access some of Claws Mail's data structures\n"
- "in order to extend or modify the user interface or automate repetitive tasks.\n"
- "\n"
- "Whenever possible, the interface works with standard GTK+ widgets\n"
- "via the PyGTK bindings, so you can refer to the GTK+ / PyGTK documentation\n"
- "to find out about all possible options.\n"
- "\n"
- "The interface to Claws Mail in this module is extended on a 'as-needed' basis.\n"
- "If you're missing something specific, try contacting the author.");
+
+ cm_module = PyModule_Create(&moduledef);
/* add module member "compose_window" set to None */
Py_INCREF(Py_None);
@@ -937,6 +947,7 @@ PyMODINIT_FUNC initclawsmail(void)
/* initialize misc things */
if(ok)
add_miscstuff(cm_module);
+ return cm_module;
}
diff --git a/src/plugins/python/composewindowtype.c b/src/plugins/python/composewindowtype.c
index b7c331167..c6edfb2b5 100644
--- a/src/plugins/python/composewindowtype.c
+++ b/src/plugins/python/composewindowtype.c
@@ -54,7 +54,7 @@ static void ComposeWindow_dealloc(clawsmail_ComposeWindowObject* self)
Py_XDECREF(self->text);
Py_XDECREF(self->replyinfo);
Py_XDECREF(self->fwdinfo);
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static void flush_gtk_queue(void)
@@ -337,7 +337,7 @@ static PyObject* ComposeWindow_set_header_list(clawsmail_ComposeWindowObject *se
/* check that we got a list of tuples with two elements */
element = PyList_GET_ITEM(headerlist, iEl);
if(!element || !PyObject_TypeCheck(element, &PyTuple_Type) || (PyTuple_Size(element) != 2)) {
- PyErr_SetString(PyExc_LookupError, "Argument to set_header_list() must be a list of tuples with two strings");
+ PyErr_SetString(PyExc_LookupError, "Argument to set_header_list() must be a list of tuples with two bytestrings");
return NULL;
}
@@ -345,8 +345,8 @@ static PyObject* ComposeWindow_set_header_list(clawsmail_ComposeWindowObject *se
headerfield = PyTuple_GetItem(element, 0);
headercontent = PyTuple_GetItem(element, 1);
if(!headerfield || !headercontent
- || !PyObject_TypeCheck(headerfield, &PyString_Type) || !PyObject_TypeCheck(headercontent, &PyString_Type)) {
- PyErr_SetString(PyExc_LookupError, "Argument to set_header_list() must be a list of tuples with two strings");
+ || !PyObject_TypeCheck(headerfield, &PyBytes_Type) || !PyObject_TypeCheck(headercontent, &PyBytes_Type)) {
+ PyErr_SetString(PyExc_LookupError, "Argument to set_header_list() must be a list of tuples with two bytestrings");
return NULL;
}
}
@@ -381,10 +381,10 @@ static PyObject* ComposeWindow_set_header_list(clawsmail_ComposeWindowObject *se
/* set header field */
editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(headerentry->combo)));
gtk_editable_delete_text(editable, 0, -1);
- gtk_editable_insert_text(editable, PyString_AsString(headerfield), -1, &pos);
+ gtk_editable_insert_text(editable, PyBytes_AsString(headerfield), -1, &pos);
/* set header content */
- gtk_entry_set_text(GTK_ENTRY(headerentry->entry), PyString_AsString(headercontent));
+ gtk_entry_set_text(GTK_ENTRY(headerentry->entry), PyBytes_AsString(headercontent));
}
Py_INCREF(Py_None);
@@ -438,7 +438,7 @@ static PyObject* ComposeWindow_save_message_to(clawsmail_ComposeWindowObject *se
if(!PyArg_ParseTuple(args, "O", &arg))
return NULL;
- if(PyString_Check(arg)) {
+ if(PyBytes_Check(arg)) {
GtkEditable *editable;
gint pos;
@@ -446,7 +446,7 @@ static PyObject* ComposeWindow_save_message_to(clawsmail_ComposeWindowObject *se
editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(self->compose->savemsg_combo)));
gtk_editable_delete_text(editable, 0, -1);
- gtk_editable_insert_text(editable, PyString_AsString(arg), -1, &pos);
+ gtk_editable_insert_text(editable, PyBytes_AsString(arg), -1, &pos);
}
else if(clawsmail_folder_check(arg)) {
GtkEditable *editable;
@@ -672,8 +672,7 @@ static PyGetSetDef ComposeWindow_getset[] = {
};
static PyTypeObject clawsmail_ComposeWindowType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"clawsmail.ComposeWindow", /*tp_name*/
sizeof(clawsmail_ComposeWindowObject), /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/src/plugins/python/folderpropertiestype.c b/src/plugins/python/folderpropertiestype.c
index 0c43e9a49..d1e3c1493 100644
--- a/src/plugins/python/folderpropertiestype.c
+++ b/src/plugins/python/folderpropertiestype.c
@@ -38,7 +38,7 @@ static int FolderProperties_init(clawsmail_FolderPropertiesObject *self, PyObjec
static void FolderProperties_dealloc(clawsmail_FolderPropertiesObject* self)
{
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject* get_default_account(clawsmail_FolderPropertiesObject *self, void *closure)
@@ -61,8 +61,7 @@ static PyGetSetDef FolderProperties_getset[] = {
};
static PyTypeObject clawsmail_FolderPropertiesType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"clawsmail.FolderProperties", /* tp_name*/
sizeof(clawsmail_FolderPropertiesObject), /* tp_basicsize*/
0, /* tp_itemsize*/
diff --git a/src/plugins/python/foldertype.c b/src/plugins/python/foldertype.c
index 6bb0b9eb3..44479ed26 100644
--- a/src/plugins/python/foldertype.c
+++ b/src/plugins/python/foldertype.c
@@ -40,7 +40,7 @@ typedef struct {
static void Folder_dealloc(clawsmail_FolderObject* self)
{
Py_XDECREF(self->properties);
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static int Folder_init(clawsmail_FolderObject *self, PyObject *args, PyObject *kwds)
@@ -83,7 +83,7 @@ static int Folder_init(clawsmail_FolderObject *self, PyObject *args, PyObject *k
static PyObject* Folder_str(clawsmail_FolderObject *self)
{
- return PyString_FromFormat("Folder: %s", self->folderitem->name);
+ return PyUnicode_FromFormat("Folder: %s", self->folderitem->name);
}
static PyObject* Folder_get_identifier(clawsmail_FolderObject *self, PyObject *args)
@@ -128,14 +128,14 @@ static PyObject* Folder_get_messages(clawsmail_FolderObject *self, PyObject *arg
static PyObject* get_name(clawsmail_FolderObject *self, void *closure)
{
if(self->folderitem && self->folderitem->name)
- return PyString_FromString(self->folderitem->name);
+ return PyUnicode_FromString(self->folderitem->name);
Py_RETURN_NONE;
}
static PyObject* get_mailbox_name(clawsmail_FolderObject *self, void *closure)
{
if(self->folderitem && self->folderitem->folder && self->folderitem->folder->name)
- return PyString_FromString(self->folderitem->folder->name);
+ return PyUnicode_FromString(self->folderitem->folder->name);
Py_RETURN_NONE;
}
@@ -154,7 +154,7 @@ static PyObject* get_identifier(clawsmail_FolderObject *self, void *closure)
id = folder_item_get_identifier(self->folderitem);
if(id) {
PyObject *retval;
- retval = PyString_FromString(id);
+ retval = PyUnicode_FromString(id);
g_free(id);
return retval;
}
@@ -169,7 +169,7 @@ static PyObject* get_path(clawsmail_FolderObject *self, void *closure)
path = folder_item_get_path(self->folderitem);
if(path) {
PyObject *retval;
- retval = PyString_FromString(path);
+ retval = PyUnicode_FromString(path);
g_free(path);
return retval;
}
@@ -187,70 +187,70 @@ static PyObject* get_properties(clawsmail_FolderObject *self, void *closure)
static PyObject* get_num_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->total_msgs);
+ return PyLong_FromLong(self->folderitem->total_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_new_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->new_msgs);
+ return PyLong_FromLong(self->folderitem->new_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_unread_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->unread_msgs);
+ return PyLong_FromLong(self->folderitem->unread_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_marked_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->marked_msgs);
+ return PyLong_FromLong(self->folderitem->marked_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_locked_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->locked_msgs);
+ return PyLong_FromLong(self->folderitem->locked_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_unread_marked_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->unreadmarked_msgs);
+ return PyLong_FromLong(self->folderitem->unreadmarked_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_ignored_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->ignored_msgs);
+ return PyLong_FromLong(self->folderitem->ignored_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_watched_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->watched_msgs);
+ return PyLong_FromLong(self->folderitem->watched_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_replied_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->replied_msgs);
+ return PyLong_FromLong(self->folderitem->replied_msgs);
Py_RETURN_NONE;
}
static PyObject* get_num_forwarded_messages(clawsmail_FolderObject *self, void *closure)
{
if(self && self->folderitem)
- return PyInt_FromLong(self->folderitem->forwarded_msgs);
+ return PyLong_FromLong(self->folderitem->forwarded_msgs);
Py_RETURN_NONE;
}
@@ -324,8 +324,7 @@ static PyGetSetDef Folder_getset[] = {
static PyTypeObject clawsmail_FolderType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"clawsmail.Folder", /* tp_name*/
sizeof(clawsmail_FolderObject), /* tp_basicsize*/
0, /* tp_itemsize*/
diff --git a/src/plugins/python/mailboxtype.c b/src/plugins/python/mailboxtype.c
index becfe6464..08408539a 100644
--- a/src/plugins/python/mailboxtype.c
+++ b/src/plugins/python/mailboxtype.c
@@ -41,20 +41,20 @@ static int Mailbox_init(clawsmail_MailboxObject *self, PyObject *args, PyObject
static void Mailbox_dealloc(clawsmail_MailboxObject* self)
{
self->folder = NULL;
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject* Mailbox_str(clawsmail_MailboxObject *self)
{
if(self->folder && self->folder->name)
- return PyString_FromFormat("Mailbox: %s", self->folder->name);
+ return PyUnicode_FromFormat("Mailbox: %s", self->folder->name);
Py_RETURN_NONE;
}
static PyObject* get_name(clawsmail_MailboxObject *self, void *closure)
{
if(self->folder && self->folder->name)
- return PyString_FromString(self->folder->name);
+ return PyUnicode_FromString(self->folder->name);
Py_RETURN_NONE;
}
@@ -66,8 +66,7 @@ static PyGetSetDef Mailbox_getset[] = {
};
static PyTypeObject clawsmail_MailboxType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"clawsmail.Mailbox", /* tp_name*/
sizeof(clawsmail_MailboxObject), /* tp_basicsize*/
0, /* tp_itemsize*/
diff --git a/src/plugins/python/messageinfotype.c b/src/plugins/python/messageinfotype.c
index da5893429..c094f8e1d 100644
--- a/src/plugins/python/messageinfotype.c
+++ b/src/plugins/python/messageinfotype.c
@@ -43,7 +43,7 @@ typedef struct {
static void MessageInfo_dealloc(clawsmail_MessageInfoObject* self)
{
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static int MessageInfo_init(clawsmail_MessageInfoObject *self, PyObject *args, PyObject *kwds)
@@ -58,7 +58,7 @@ static PyObject* MessageInfo_str(clawsmail_MessageInfoObject *self)
gchar *Subject;
From = self->msginfo->from ? self->msginfo->from : "";
Subject = self->msginfo->subject ? self->msginfo->subject : "";
- return PyString_FromFormat("MessageInfo: %s / %s", From, Subject);
+ return PyUnicode_FromFormat("MessageInfo: %s / %s", From, Subject);
}
Py_RETURN_NONE;
}
@@ -229,35 +229,35 @@ static PyObject* get_header(PyObject *self, PyObject *args)
static PyObject* get_From(clawsmail_MessageInfoObject *self, void *closure)
{
if(self->msginfo && self->msginfo->from)
- return PyString_FromString(self->msginfo->from);
+ return PyUnicode_FromString(self->msginfo->from);
Py_RETURN_NONE;
}
static PyObject* get_To(clawsmail_MessageInfoObject *self, void *closure)
{
if(self->msginfo && self->msginfo->to)
- return PyString_FromString(self->msginfo->to);
+ return PyUnicode_FromString(self->msginfo->to);
Py_RETURN_NONE;
}
static PyObject* get_Cc(clawsmail_MessageInfoObject *self, void *closure)
{
if(self->msginfo && self->msginfo->cc)
- return PyString_FromString(self->msginfo->cc);
+ return PyUnicode_FromString(self->msginfo->cc);
Py_RETURN_NONE;
}
static PyObject* get_Subject(clawsmail_MessageInfoObject *self, void *closure)
{
if(self->msginfo && self->msginfo->subject)
- return PyString_FromString(self->msginfo->subject);
+ return PyUnicode_FromString(self->msginfo->subject);
Py_RETURN_NONE;
}
static PyObject* get_MessageID(clawsmail_MessageInfoObject *self, void *closure)
{
if(self->msginfo && self->msginfo->msgid)
- return PyString_FromString(self->msginfo->msgid);
+ return PyUnicode_FromString(self->msginfo->msgid);
Py_RETURN_NONE;
}
@@ -268,7 +268,7 @@ static PyObject* get_FilePath(clawsmail_MessageInfoObject *self, void *closure)
filepath = procmsg_get_message_file_path(self->msginfo);
if(filepath) {
PyObject *retval;
- retval = PyString_FromString(filepath);
+ retval = PyUnicode_FromString(filepath);
g_free(filepath);
return retval;
}
@@ -426,8 +426,7 @@ static PyGetSetDef MessageInfo_getset[] = {
static PyTypeObject clawsmail_MessageInfoType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"clawsmail.MessageInfo", /* tp_name*/
sizeof(clawsmail_MessageInfoObject), /* tp_basicsize*/
0, /* tp_itemsize*/
diff --git a/src/plugins/python/python-hooks.c b/src/plugins/python/python-hooks.c
index e0d2873b6..9d482f6e3 100644
--- a/src/plugins/python/python-hooks.c
+++ b/src/plugins/python/python-hooks.c
@@ -28,7 +28,6 @@
#ifdef ENABLE_PYTHON
#include <Python.h>
#include <pygobject.h>
-#include <pygtk/pygtk.h>
#endif // ENABLE_PYTHON
#include <glib.h>
@@ -82,7 +81,7 @@ capture_stdin(PyObject *self, PyObject *args)
{
/* Return an empty string.
* This is what read() returns when hitting EOF. */
- return PyString_FromString("");
+ return PyUnicode_FromString("");
}
static PyObject *
@@ -123,6 +122,27 @@ is_blacklisted(void)
}
#endif // ENABLE_PYTHON
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "parasite",
+ NULL,
+ -1,
+ parasite_python_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC
+parasite_python_module_init(void)
+{
+#ifdef ENABLE_PYTHON
+ return PyModule_Create(&moduledef);
+#endif // ENABLE_PYTHON
+ return NULL;
+}
+
int
parasite_python_init(char **error)
{
@@ -154,7 +174,6 @@ parasite_python_init(char **error)
sigaction(SIGINT, &old_sigint, NULL);
- Py_InitModule("parasite", parasite_python_methods);
if(PyRun_SimpleString(
"import parasite\n"
"import sys\n"
@@ -185,41 +204,11 @@ parasite_python_init(char **error)
return 0;
}
- if (!pygobject_init(-1, -1, -1)) {
- dlclose(python_dlhandle);
- python_dlhandle = NULL;
- return 0;
- }
+ pygtk = PyImport_ImportModule("gi");
- pygtk = PyImport_ImportModule("gtk");
-
- if (pygtk != NULL)
+ if (pygtk == NULL)
{
- PyObject *module_dict = PyModule_GetDict(pygtk);
- PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API");
-
- /*
- * This seems to be NULL when we're running a PyGTK program.
- * We really need to find out why.
- */
- if (cobject != NULL)
- {
- if (PyCObject_Check(cobject)) {
- _PyGtk_API = (struct _PyGtk_FunctionStruct*)
- PyCObject_AsVoidPtr(cobject);
- }
-#if PY_VERSION_HEX >= 0x02070000
- else if (PyCapsule_IsValid(cobject, "gtk._gtk._PyGtk_API")) {
- _PyGtk_API = (struct _PyGtk_FunctionStruct*)PyCapsule_GetPointer(cobject, "gtk._gtk._PyGtk_API");
- }
-#endif
- else {
- *error = g_strdup("Parasite: Could not find _PyGtk_API object");
- return 0;
- }
- }
- } else {
- *error = g_strdup("Parasite: Could not import gtk");
+ *error = g_strdup("Parasite: Could not import gi");
dlclose(python_dlhandle);
python_dlhandle = NULL;
return 0;
@@ -294,7 +283,7 @@ parasite_python_run(const char *command,
if (obj != NULL && obj != Py_None) {
PyObject *repr = PyObject_Repr(obj);
if (repr != NULL) {
- char *string = PyString_AsString(repr);
+ char *string = PyBytes_AsString(repr);
if (stdout_logger != NULL) {
stdout_logger(string, user_data);
diff --git a/src/plugins/python/python-hooks.h b/src/plugins/python/python-hooks.h
index dbde331a7..d92879bd2 100644
--- a/src/plugins/python/python-hooks.h
+++ b/src/plugins/python/python-hooks.h
@@ -24,10 +24,12 @@
#define _GTKPARASITE_PYTHON_MODULE_H_
#include <glib.h>
+#include <Python.h>
typedef void (*ParasitePythonLogger)(const char *text, gpointer user_data);
+PyMODINIT_FUNC parasite_python_module_init(void);
int parasite_python_init(char **error);
void parasite_python_done(void);
void parasite_python_run(const char *command,
diff --git a/src/plugins/python/python_plugin.c b/src/plugins/python/python_plugin.c
index 68e3a59a0..dab88ada9 100644
--- a/src/plugins/python/python_plugin.c
+++ b/src/plugins/python/python_plugin.c
@@ -595,9 +595,9 @@ static PyObject *get_StringIO_instance(void)
PyObject *class_StringIO = NULL;
PyObject *inst_StringIO = NULL;
- module_StringIO = PyImport_ImportModule("cStringIO");
+ module_StringIO = PyImport_ImportModule("io");
if(!module_StringIO) {
- debug_print("Error getting traceback: Could not import module cStringIO\n");
+ debug_print("Error getting traceback: Could not import module io\n");
goto done;
}
@@ -648,7 +648,7 @@ static char* get_exception_information(PyObject *inst_StringIO)
goto done;
}
- retval = g_strdup(PyString_AsString(result_getvalue));
+ retval = g_strdup(PyBytes_AsString(result_getvalue));
done:
@@ -686,6 +686,10 @@ gint plugin_init(gchar **error)
if(!make_sure_directories_exist(error))
goto err;
+ /* register moduke */
+ PyImport_AppendInittab("clawsmail", initclawsmail);
+ PyImport_AppendInittab("parasite", parasite_python_module_init);
+
/* initialize python interpreter */
Py_Initialize();
@@ -694,13 +698,6 @@ gint plugin_init(gchar **error)
* an error occurred. */
inst_StringIO = get_StringIO_instance();
- /* initialize Claws Mail Python module */
- initclawsmail();
- if(PyErr_Occurred()) {
- *error = get_exception_information(inst_StringIO);
- goto err;
- }
-
if(PyRun_SimpleString("import clawsmail") == -1) {
*error = g_strdup("Error importing the clawsmail module");
goto err;
-----------------------------------------------------------------------
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list