GNOME Bugzilla – Bug 547067
add File.replace_contents, replace_contents_async, replace_contents_finish
Last modified: 2008-08-10 03:28:52 UTC
I think I'm going to use these methods, so I've written up the necessary override code for them.
Created attachment 116230 [details] [review] add File.replace_contents methods
Comment on attachment 116230 [details] [review] add File.replace_contents methods >Index: gio/gio.defs >+ (docstring >+ "F.replace_contents(contents, [etag, [make_backup, [flags, [cancellable]]]]) -> etag_out\n\n" >+ "Replaces the content of the file, returning the new etag value for the file.\n" >+ "If an etag is specified, any existing file must have that etag, or the\n" >+ "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 file.\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" Make sure this is wrapped at 76 columns, you can easily test by doing pydoc gio.File.replace_contents in a terminal. It needs to be readable. I didn't test it might already look good, in that case just ignore this comment. >Index: gio/gfile.override >+_wrap_g_file_replace_contents_finish(PyGObject *self, PyObject *args, PyObject *kwargs) >+ static char *kwlist[] = { "res", NULL }; shouldn't that be result instead of res? >+ if (ret) { >+ PyObject *py_ret = PyString_FromString(etag_out); >+ g_free(etag_out); >+ return py_ret; >+ } else { >+ Py_INCREF(Py_None); >+ return Py_None; >+ } Shouldn't etag_out always be freed? Or is it only set if ret is true? The rest looks good, if the above comments are addressed or deemed invalid, please commit.
etag can be NULL in both replace_contents and replace_contents_async, so you should use z instead of s
I've fixed up the docstring line length, made the freeing of etag_out unconditional, renamed 'res' to 'result', used 'z' rather than 's' for etags, added a couple more tests, and committed. Thanks for the prompt review. I noticed that File.load_contents_async also calls the result parameter 'res'. Should I fix that one too? There are a number of other docstrings in gio.defs that wrap across lines in a 80 column terminal. I can provide a patch for these.