[pygobject] Wrap gio.File.create_readwrite_async() and add a test
- From: Gian Mario Tagliaretti <gianmt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject] Wrap gio.File.create_readwrite_async() and add a test
- Date: Fri, 1 Jan 2010 13:30:50 +0000 (UTC)
commit ca436fe7785fd24b0f0e65f2f8c9fa6478277682
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date: Fri Jan 1 13:30:24 2010 +0100
Wrap gio.File.create_readwrite_async() and add a test
gio/gfile.override | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test_gio.py | 24 ++++++++++++++++++++++++
2 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/gio/gfile.override b/gio/gfile.override
index 6469d22..998b309 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -956,6 +956,57 @@ _wrap_g_file_create_async(PyGObject *self, PyObject *args, PyObject *kwargs)
return NULL;
}
%%
+override g_file_create_readwrite_async kwargs
+static PyObject *
+_wrap_g_file_create_readwrite_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 = pygio_notify_new();
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O|OiOO:File.create_readwrite_async",
+ kwlist,
+ ¬ify->callback,
+ &flags, &io_priority,
+ &pycancellable,
+ ¬ify->data))
+ goto error;
+
+ if (!pygio_notify_callback_is_valid(notify))
+ goto error;
+
+ if (py_flags && pyg_flags_get_value(G_TYPE_FILE_CREATE_FLAGS,
+ py_flags, (gpointer)&flags))
+ goto error;
+
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
+ goto error;
+
+ pygio_notify_reference_callback(notify);
+
+ g_file_create_readwrite_async(G_FILE(self->obj), flags, io_priority,
+ cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+
+ error:
+ pygio_notify_free(notify);
+ return NULL;
+}
+%%
override g_file_replace_async kwargs
static PyObject *
_wrap_g_file_replace_async(PyGObject *self, PyObject *args, PyObject *kwargs)
diff --git a/tests/test_gio.py b/tests/test_gio.py
index a9ef159..feafc70 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -92,6 +92,30 @@ class TestFile(unittest.TestCase):
loop = glib.MainLoop()
loop.run()
+ def testCreateReadWriteAsync(self):
+ def callback(file, result):
+ try:
+ iostream = file.create_readwrite_finish(result)
+ self.failUnless(isinstance(iostream, gio.FileIOStream))
+
+ ostream = iostream.get_output_stream()
+ self.failUnless(isinstance(ostream, gio.OutputStream))
+
+ w = ostream.write("testing")
+ cont, leng, etag = file.load_contents()
+ self.assertEqual(cont, "testing")
+ finally:
+ if os.path.exists('temp.txt'):
+ os.unlink("temp.txt")
+ loop.quit()
+
+ gfile = gio.File("temp.txt")
+ gfile.create_readwrite_async(callback, gio.FILE_CREATE_NONE,
+ glib.PRIORITY_HIGH)
+
+ loop = glib.MainLoop()
+ loop.run()
+
def testCreateAsyncNoargs(self):
def callback(file, result):
try:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]