pygobject r946 - in trunk: . gio tests



Author: paulp
Date: Tue Aug 12 20:00:48 2008
New Revision: 946
URL: http://svn.gnome.org/viewvc/pygobject?rev=946&view=rev

Log:
2008-08-12  Paul Pogonyshev  <pogonyshev gmx net>

	Bug 547484 â wrap gio.DataInputStream.read_line and ...read_until

	* tests/test_gio.py (TestDataInputStream): New test case.

	* gio/ginputstream.override (_wrap_g_data_input_stream_read_line)
	(_wrap_g_data_input_stream_read_until): New functions.


Modified:
   trunk/ChangeLog
   trunk/gio/ginputstream.override
   trunk/tests/test_gio.py

Modified: trunk/gio/ginputstream.override
==============================================================================
--- trunk/gio/ginputstream.override	(original)
+++ trunk/gio/ginputstream.override	Tue Aug 12 20:00:48 2008
@@ -286,6 +286,71 @@
     return Py_None;
 }
 %%
+override g_data_input_stream_read_line kwargs
+static PyObject *
+_wrap_g_data_input_stream_read_line(PyGObject *self,
+				    PyObject *args,
+				    PyObject *kwargs)
+{
+    static char *kwlist[] = { "cancellable", NULL };
+    PyGObject *pycancellable = NULL;
+    GCancellable *cancellable;
+    char *line;
+    gsize length;
+    PyObject *py_line;
+    GError *error = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+				     "|O:gio.DataInputStream.read_line",
+                                     kwlist, &pycancellable))
+        return NULL;
+
+    if (!pygio_check_cancellable(pycancellable, &cancellable))
+	return NULL;
+
+    line = g_data_input_stream_read_line(G_DATA_INPUT_STREAM(self->obj),
+					 &length, cancellable, &error);
+    if (pyg_error_check(&error))
+        return NULL;
+
+    py_line = PyString_FromStringAndSize(line, length);
+    g_free(line);
+    return py_line;
+}
+%%
+override g_data_input_stream_read_until kwargs
+static PyObject *
+_wrap_g_data_input_stream_read_until(PyGObject *self,
+				     PyObject *args,
+				     PyObject *kwargs)
+{
+    static char *kwlist[] = { "stop_chars", "cancellable", NULL };
+    const char *stop_chars;
+    PyGObject *pycancellable = NULL;
+    GCancellable *cancellable;
+    char *line;
+    gsize length;
+    PyObject *py_line;
+    GError *error = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+				     "s|O:gio.DataInputStream.read_line",
+                                     kwlist, &stop_chars, &pycancellable))
+        return NULL;
+
+    if (!pygio_check_cancellable(pycancellable, &cancellable))
+	return NULL;
+
+    line = g_data_input_stream_read_until(G_DATA_INPUT_STREAM(self->obj),
+					  stop_chars, &length, cancellable, &error);
+    if (pyg_error_check(&error))
+        return NULL;
+
+    py_line = PyString_FromStringAndSize(line, length);
+    g_free(line);
+    return py_line;
+}
+%%
 override g_memory_input_stream_add_data kwargs
 static PyObject *
 _wrap_g_memory_input_stream_add_data(PyGObject *self,

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Tue Aug 12 20:00:48 2008
@@ -545,6 +545,27 @@
         loop.run()
 
 
+class TestDataInputStream(unittest.TestCase):
+    def setUp(self):
+        self.base_stream = gio.MemoryInputStream()
+        self.data_stream = gio.DataInputStream(self.base_stream)
+
+    def test_read_line(self):
+        # Currently fails because GIO itself is buggy.  See bug 547481.
+        return
+        self.base_stream.add_data('foo\nbar\n\nbaz')
+        self.assertEquals('foo\n', self.data_stream.read_line())
+        self.assertEquals('bar\n', self.data_stream.read_line())
+        self.assertEquals('\n', self.data_stream.read_line())
+        self.assertEquals('baz', self.data_stream.read_line())
+
+    def test_read_until(self):
+        self.base_stream.add_data('sentence.end of line\nthe rest')
+        self.assertEquals('sentence', self.data_stream.read_until('.!?'))
+        self.assertEquals('end of line', self.data_stream.read_until('\n\r'))
+        self.assertEquals('the rest', self.data_stream.read_until('#$%^&'))
+
+
 class TestMemoryInputStream(unittest.TestCase):
     def setUp(self):
         self.stream = gio.MemoryInputStream()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]