diff options
| author | Jonathan Matthew <jonathan@d14n.org> | 2008-08-10 03:28:03 +0000 |
|---|---|---|
| committer | Jonathan Matthew <jmatthew@src.gnome.org> | 2008-08-10 03:28:03 +0000 |
| commit | fa274210cccf8db816a24f1d55195fa79c9a2ad4 (patch) | |
| tree | 08ce01d42e8e9808229db768dd6e69357144cda7 /gio | |
| parent | 6ec9a71b8ae621203fa546b60867f1198bf723bc (diff) | |
| download | pygobject-fa274210cccf8db816a24f1d55195fa79c9a2ad4.tar.gz pygobject-fa274210cccf8db816a24f1d55195fa79c9a2ad4.tar.xz pygobject-fa274210cccf8db816a24f1d55195fa79c9a2ad4.zip | |
Bug 547067 – add File.replace_contents, replace_contents_async,
2008-08-10 Jonathan Matthew <jonathan@d14n.org>
Bug 547067 – add File.replace_contents, replace_contents_async,
replace_contents_finish.
* gio/gfile.override:
* gio/gio.defs:
* tests/test_gio.py:
Add overrides, docs, and tests for File.replace_contents,
replace_contents_async, and replace_contents_finish.
svn path=/trunk/; revision=935
Diffstat (limited to 'gio')
| -rw-r--r-- | gio/gfile.override | 155 | ||||
| -rw-r--r-- | gio/gio.defs | 31 |
2 files changed, 183 insertions, 3 deletions
diff --git a/gio/gfile.override b/gio/gfile.override index d7a40ee..3d524a6 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -972,14 +972,163 @@ _wrap_g_file_query_info_async(PyGObject *self, PyObject *args, PyObject *kwargs) Py_INCREF(Py_None); return Py_None; } +%% +override g_file_replace_contents kwargs +static PyObject * +_wrap_g_file_replace_contents(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "contents", "etag", "make_backup", + "flags", "cancellable", NULL }; + GCancellable *cancellable; + PyGObject *pycancellable = NULL; + GFileCreateFlags flags = G_FILE_CREATE_NONE; + PyObject *py_flags = NULL; + gsize length; + gboolean make_backup = FALSE; + char *contents; + char *etag = NULL; + char *new_etag = NULL; + GError *error = NULL; + gboolean ret; + PyObject *py_ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "s#|zbOO:File.replace_contents", + kwlist, + &contents, + &length, + &etag, + &make_backup, + &flags, + &cancellable)) + { + 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; + + ret = g_file_replace_contents(G_FILE(self->obj), contents, length, etag, + make_backup, flags, &new_etag, cancellable, + &error); + + if (pyg_error_check(&error)) + return NULL; + + if (ret) { + py_ret = PyString_FromString(new_etag); + } else { + py_ret = Py_None; + Py_INCREF(py_ret); + } + + g_free(new_etag); + return py_ret; +} +%% +override g_file_replace_contents_finish kwargs +static PyObject * +_wrap_g_file_replace_contents_finish(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "result", NULL }; + PyGObject *res; + gchar *etag_out = NULL; + GError *error = NULL; + gboolean ret; + PyObject *py_ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O!:File.replace_contents_finish", + kwlist, + &PyGAsyncResult_Type, + &res)) + return NULL; + + ret = g_file_replace_contents_finish(G_FILE(self->obj), + G_ASYNC_RESULT(res->obj), &etag_out, + &error); + + if (pyg_error_check(&error)) + return NULL; + + if (ret) { + py_ret = PyString_FromString(etag_out); + return py_ret; + } else { + py_ret = Py_None; + Py_INCREF(py_ret); + } + + g_free(etag_out); + return py_ret; +} +%% +override g_file_replace_contents_async kwargs +static PyObject * +_wrap_g_file_replace_contents_async(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "contents", "callback", "etag", "make_backup", + "flags", "cancellable", "user_data", NULL }; + GCancellable *cancellable; + PyGObject *pycancellable = NULL; + PyGIONotify *notify; + GFileCreateFlags flags = G_FILE_CREATE_NONE; + PyObject *py_flags = NULL; + gsize length; + gboolean make_backup = FALSE; + char *contents; + char *etag = NULL; + + notify = g_slice_new0(PyGIONotify); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "s#O|zbOOO:File.replace_contents_async", + kwlist, + &contents, + &length, + ¬ify->callback, + &etag, + &make_backup, + &py_flags, + &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; + + Py_INCREF(notify->callback); + Py_XINCREF(notify->data); + g_file_replace_contents_async(G_FILE(self->obj), + contents, + length, + etag, + make_backup, + flags, + cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; +} + /* GFile.eject_mountable */ /* GFile.find_enclosing_mount_async */ -/* GFile.replace_contents_async */ /* GFile.set_attributes_async */ /* GFile.set_display_name_async */ /* GFile.load_partial_contents_async: No ArgType for GFileReadMoreCallback */ /* GFile.move: No ArgType for GFileProgressCallback */ /* GFile.set_attributes_finish: No ArgType for GFileInfo** */ /* GFile.load_partial_contents_finish: No ArgType for char** */ -/* GFile.replace_contents: No ArgType for char** */ -/* GFile.replace_contents_finish: No ArgType for char** */ diff --git a/gio/gio.defs b/gio/gio.defs index c083ff3..56da6fb 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -2263,6 +2263,18 @@ ) (define-method replace_contents + (docstring + "F.replace_contents(contents, [etag, [make_backup, [flags, [cancellable]]]])\n" + "-> etag_out\n" + "\n" + "Replaces the content of the file, returning the new etag value for the\n" + "file. If an etag is specified, any existing file must have that etag, or\n" + "the error gio.IO_ERROR_WRONG_ETAG will be returned.\n" + "If make_backup is True, this method will attempt to make a backup of the\n" + "file. If cancellable is not None, then the operation can be cancelled by\n" + "triggering the cancellable object from another thread. If the operation\n" + "was cancelled, the error gio.IO_ERROR_CANCELLED will be returned.\n" + ) (of-object "GFile") (c-name "g_file_replace_contents") (return-type "gboolean") @@ -2279,6 +2291,20 @@ ) (define-method replace_contents_async + (docstring + "F.replace_contents_async(contents, callback, [etag, [make_backup, [flags,\n" + " [cancellable]]]]) -> etag_out\n" + "\n" + "Starts an asynchronous replacement of the file with the given contents.\n" + "For more details, see F.replace_contents() which is the synchronous\n" + "version of this call.\n\n" + "When the load operation has completed, callback will be called with\n" + "user data. To finish the operation, call F.replace_contents_finish() with\n" + "the parameter 'res' returned by the callback.\n\n" + "If cancellable is not None, then the operation can be cancelled by\n" + "triggering the cancellable object from another thread. If the operation\n" + "was cancelled, the error gio.IO_ERROR_CANCELLED will be returned.\n" + ) (of-object "GFile") (c-name "g_file_replace_contents_async") (return-type "none") @@ -2295,6 +2321,11 @@ ) (define-method replace_contents_finish + (docstring + "F.replace_contents_finish(res) -> etag_out\n\n" + "Finishes an asynchronous replacement of the file's contents.\n" + "The new entity tag for the file is returned.\n" + ) (of-object "GFile") (c-name "g_file_replace_contents_finish") (return-type "gboolean") |
