diff options
author | Gian Mario Tagliaretti <gianmt@src.gnome.org> | 2008-08-02 08:25:25 +0000 |
---|---|---|
committer | Gian Mario Tagliaretti <gianmt@src.gnome.org> | 2008-08-02 08:25:25 +0000 |
commit | c5dc87ea088613158d527f5b1b1cd947db8d12b8 (patch) | |
tree | 51447b5998f92dc89651cf0a71e7272b87b46b5f | |
parent | e72525344fdab47604282581fec6d7ad449c1f76 (diff) | |
download | pygobject-c5dc87ea088613158d527f5b1b1cd947db8d12b8.tar.gz pygobject-c5dc87ea088613158d527f5b1b1cd947db8d12b8.tar.xz pygobject-c5dc87ea088613158d527f5b1b1cd947db8d12b8.zip |
Wrap GFile.append_to_async with docs and test
svn path=/trunk/; revision=912
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | gio/gfile.override | 45 | ||||
-rw-r--r-- | gio/gio.defs | 9 | ||||
-rw-r--r-- | tests/test_gio.py | 39 |
4 files changed, 101 insertions, 1 deletions
@@ -1,3 +1,12 @@ +2008-08-02 Gian Mario Tagliaretti <gianmt@gnome.org> + + Bug 545959 – Wrap GFile.append_to_async + + * tests/test_gio.py: + * gio/gfile.override: + * gio/gio.defs: + Wrap GFile.append_to_async with docs and test + 2008-08-02 Johan Dahlin <johan@gnome.org> * gio/gfileinfo.override: diff --git a/gio/gfile.override b/gio/gfile.override index d9c6d54..56dbfad 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -783,7 +783,50 @@ _wrap_g_file_query_writable_namespaces(PyGObject *self, return Py_None; } } -/* GFile.append_to_async */ +%% +override g_file_append_to_async kwargs +static PyObject * +_wrap_g_file_append_to_async(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "callback", "flags", "io_priority", + "cancellable", "user_data", NULL }; + GCancellable *cancellable; + PyGObject *pycancellable = NULL; + GFileCreateFlags flags = G_FILE_CREATE_NONE; + PyObject *py_flags = NULL; + int io_priority = G_PRIORITY_DEFAULT; + PyGIONotify *notify; + + notify = g_slice_new0(PyGIONotify); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O|OiOO:File.append_to_async", + kwlist, + ¬ify->callback, + &flags, &io_priority, + &pycancellable, + ¬ify->data)) + + { + g_slice_free(PyGIONotify, notify); + return NULL; + } + + if (py_flags && pyg_flags_get_value(G_TYPE_FILE_CREATE_FLAGS, + py_flags, (gpointer)&flags)) + return NULL; + + if (!pygio_check_cancellable(pycancellable, &cancellable)) + return NULL; + + g_file_append_to_async(G_FILE(self->obj), flags, io_priority, cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; +} + /* GFile.create_async */ /* GFile.eject_mountable */ /* GFile.find_enclosing_mount_async */ diff --git a/gio/gio.defs b/gio/gio.defs index 3ad3518..e39eda3 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -1389,6 +1389,15 @@ ) (define-method append_to_async + (docstring + "F.append_to_async(callback [flags, [,io_priority [,cancellable [,user_data]]]]) -> open for append\n" + "\n" + "Asynchronously opens file for appending." + "For more details, see gio.File.append_to() which is the synchronous\n" + "version of this call. When the operation is finished, callback will\n" + "be called. You can then call F.append_to_finish() to get the result\n" + "of the operation." + ) (of-object "GFile") (c-name "g_file_append_to_async") (return-type "none") diff --git a/tests/test_gio.py b/tests/test_gio.py index 3761b31..17642ba 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -33,6 +33,45 @@ class TestFile(unittest.TestCase): loop = glib.MainLoop() loop.run() + def testAppendToAsync(self): + self._f.write("append_to ") + self._f.close() + + def callback(file, result): + try: + stream = file.append_to_finish(result) + self.failUnless(isinstance(stream, gio.OutputStream)) + w = stream.write("testing") + cont, leng, etag = self.file.load_contents() + self.assertEqual(cont, "append_to testing") + finally: + loop.quit() + + self.file.append_to_async(callback, gio.FILE_CREATE_NONE, + glib.PRIORITY_HIGH) + + loop = glib.MainLoop() + loop.run() + + def testAppendToAsyncNoargs(self): + self._f.write("append_to ") + self._f.close() + + def callback(file, result): + try: + stream = file.append_to_finish(result) + self.failUnless(isinstance(stream, gio.OutputStream)) + w = stream.write("testing") + cont, leng, etag = self.file.load_contents() + self.assertEqual(cont, "append_to testing") + finally: + loop.quit() + + self.file.append_to_async(callback) + + loop = glib.MainLoop() + loop.run() + def testReadAsyncError(self): self.assertRaises(TypeError, self.file.read_async) self.assertRaises(TypeError, self.file.read_async, "foo", "bar") |