[Commits] python-hooks.c 1.1.2.2 1.1.2.3

holger at claws-mail.org holger at claws-mail.org
Wed Nov 21 22:15:52 CET 2012


Update of /home/claws-mail/plugins/python/src
In directory srv:/tmp/cvs-serv4419/src

Modified Files:
      Tag: gtk2
	python-hooks.c 
Log Message:
2012-11-21 [holger]	0.11cvs2

	* src/python-hooks.c
		Simulate EOF on stdin in the interactive
		Python console. Solves the hang reported
		in bug #2734 

Index: python-hooks.c
===================================================================
RCS file: /home/claws-mail/plugins/python/src/Attic/python-hooks.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- python-hooks.c	13 Jan 2010 14:16:09 -0000	1.1.2.2
+++ python-hooks.c	21 Nov 2012 21:15:50 -0000	1.1.2.3
@@ -71,6 +71,14 @@
 }
 
 static PyObject *
+capture_stdin(PyObject *self, PyObject *args)
+{
+    /* Return an empty string.
+     * This is what read() returns when hitting EOF. */
+    return PyString_FromString("");
+}
+
+static PyObject *
 wrap_gobj(PyObject *self, PyObject *args)
 {
     void *addr;
@@ -93,6 +101,7 @@
 static PyMethodDef parasite_python_methods[] = {
     {"capture_stdout", capture_stdout, METH_VARARGS, "Captures stdout"},
     {"capture_stderr", capture_stderr, METH_VARARGS, "Captures stderr"},
+    {"capture_stdin", capture_stdin, METH_VARARGS, "Captures stdin"},
     {"gobj", wrap_gobj, METH_VARARGS, "Wraps a C GObject"},
     {NULL, NULL, 0, NULL}
 };
@@ -153,6 +162,14 @@
         "    def flush(self):\n"
         "        pass\n"
         "\n"
+        "class StdinCatcher:\n"
+        "    def readline(self, size=-1):\n"
+        "        return parasite.capture_stdin(size)\n"
+        "    def read(self, size=-1):\n"
+        "        return parasite.capture_stdin(size)\n"
+        "    def flush(self):\n"
+        "        pass\n"
+        "\n"
     );
 
     if (!pygobject_init(-1, -1, -1))
@@ -220,14 +237,17 @@
 
     PyRun_SimpleString("old_stdout = sys.stdout\n"
                        "old_stderr = sys.stderr\n"
+                       "old_stdin  = sys.stdin\n"
                        "sys.stdout = StdoutCatcher()\n"
-                       "sys.stderr = StderrCatcher()\n");
+                       "sys.stderr = StderrCatcher()\n"
+                       "sys.stdin  = StdinCatcher()\n");
 
     obj = PyRun_String(command, Py_single_input, dict, dict);
     if(PyErr_Occurred())
       PyErr_Print();
     PyRun_SimpleString("sys.stdout = old_stdout\n"
-                       "sys.stderr = old_stderr\n");
+                       "sys.stderr = old_stderr\n"
+                       "sys.stdin = old_stdin\n");
 
     if (stdout_logger != NULL)
         stdout_logger(captured_stdout->str, user_data);



More information about the Commits mailing list