summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--gio/gfile.override86
-rw-r--r--gio/gio.defs10
-rw-r--r--tests/test_gio.py39
4 files changed, 143 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 29895fb..e66914f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-08-02 Gian Mario Tagliaretti <gianmt@gnome.org>
+
+ Bug 546020 – Wrap GFile.create_async
+
+ * tests/test_gio.py:
+ * gio/gfile.override:
+ * gio/gio.defs:
+ Wrap GFile.create_async with docs and test
+
2008-08-02 Johan Dahlin <johan@gnome.org>
* codegen/docgen.py:
diff --git a/gio/gfile.override b/gio/gfile.override
index 56dbfad..fb78e6e 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -826,8 +826,92 @@ _wrap_g_file_append_to_async(PyGObject *self, PyObject *args, PyObject *kwargs)
Py_INCREF(Py_None);
return Py_None;
}
+%%
+override g_file_create_async kwargs
+static PyObject *
+_wrap_g_file_create_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);
-/* GFile.create_async */
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O|OiOO:File.create_async",
+ kwlist,
+ &notify->callback,
+ &flags, &io_priority,
+ &pycancellable,
+ &notify->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_create_async(G_FILE(self->obj), flags, io_priority, cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+%%
+override g_file_create_async kwargs
+static PyObject *
+_wrap_g_file_create_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.create_async",
+ kwlist,
+ &notify->callback,
+ &flags, &io_priority,
+ &pycancellable,
+ &notify->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_create_async(G_FILE(self->obj), flags, io_priority, cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
/* GFile.eject_mountable */
/* GFile.find_enclosing_mount_async */
/* GFile.query_info_async */
diff --git a/gio/gio.defs b/gio/gio.defs
index 0b1ff5e..d0e6f2a 100644
--- a/gio/gio.defs
+++ b/gio/gio.defs
@@ -1420,6 +1420,16 @@
)
(define-method create_async
+ (docstring
+ "F.create_async(callback [flags, [,io_priority [,cancellable [,user_data]]]]) -> file created\n"
+ "\n"
+ "Asynchronously creates a new file and returns an output stream for\n"
+ "writing to it. The file must not already exist.\n"
+ "For more details, see F.create() which is the synchronous\n"
+ "version of this call.\n"
+ "When the operation is finished, callback will be called. You can\n"
+ "then call F.create_finish() to get the result of the operation."
+ )
(of-object "GFile")
(c-name "g_file_create_async")
(return-type "none")
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 17642ba..d96d9aa 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -72,6 +72,45 @@ class TestFile(unittest.TestCase):
loop = glib.MainLoop()
loop.run()
+ def testCreateAsync(self):
+ def callback(file, result):
+ try:
+ stream = file.create_finish(result)
+ self.failUnless(isinstance(stream, gio.OutputStream))
+ w = stream.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_async(callback, gio.FILE_CREATE_NONE,
+ glib.PRIORITY_HIGH)
+
+ loop = glib.MainLoop()
+ loop.run()
+
+ def testCreateAsyncNoargs(self):
+ def callback(file, result):
+ try:
+ stream = file.create_finish(result)
+ self.failUnless(isinstance(stream, gio.OutputStream))
+ w = stream.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_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")