diff options
| author | Paul Pogonyshev <pogonyshev@gmx.net> | 2008-08-12 20:00:48 +0000 |
|---|---|---|
| committer | Paul Pogonyshev <paulp@src.gnome.org> | 2008-08-12 20:00:48 +0000 |
| commit | 9ecb2ef1203b8667f4c05798f5bf9306f599bbab (patch) | |
| tree | 0d5b2df37621c7e650ecd32b9da7e7af1133dfa2 | |
| parent | ad7a6f15aafaf6d962ebbd2a8431fd17e6abfc30 (diff) | |
| download | pygobject-9ecb2ef1203b8667f4c05798f5bf9306f599bbab.tar.gz pygobject-9ecb2ef1203b8667f4c05798f5bf9306f599bbab.tar.xz pygobject-9ecb2ef1203b8667f4c05798f5bf9306f599bbab.zip | |
Bug 547484 – wrap gio.DataInputStream.read_line and ...read_until
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.
svn path=/trunk/; revision=946
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | gio/ginputstream.override | 65 | ||||
| -rw-r--r-- | tests/test_gio.py | 21 |
3 files changed, 95 insertions, 0 deletions
@@ -1,5 +1,14 @@ 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. + +2008-08-12 Paul Pogonyshev <pogonyshev@gmx.net> + Bug 547354 – wrap a few memory stream methods * gio/ginputstream.override (_wrap_g_memory_input_stream_add_data): diff --git a/gio/ginputstream.override b/gio/ginputstream.override index d345d27..44378cd 100644 --- a/gio/ginputstream.override +++ b/gio/ginputstream.override @@ -286,6 +286,71 @@ _wrap_g_input_stream_close_async(PyGObject *self, 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, diff --git a/tests/test_gio.py b/tests/test_gio.py index 2fb5c3a..03d09be 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -545,6 +545,27 @@ class TestInputStream(unittest.TestCase): 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() |
