From 180c157f2a20b7d2dd9af05bfb5f515fd23870a0 Mon Sep 17 00:00:00 2001 From: Gian Mario Tagliaretti Date: Tue, 2 Jun 2009 10:41:26 +0200 Subject: Wrap gio.FileOutputStream.query_info_async Add the wrapper for gio.FileOutputStream.query_info_async including docs and a test. --- docs/Makefile.am | 2 + docs/reference/pygio-classes.xml | 1 + docs/reference/pygio-fileoutputstream.xml | 257 ++++++++++++++++++++++++++++++ gio/Makefile.am | 3 +- gio/gfileoutputstream.override | 68 ++++++++ gio/gio.override | 1 + tests/test_gio.py | 27 ++++ 7 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 docs/reference/pygio-fileoutputstream.xml create mode 100644 gio/gfileoutputstream.override diff --git a/docs/Makefile.am b/docs/Makefile.am index 72b4270..5d7b083 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -30,6 +30,7 @@ HTML_FILES = \ html/class-giofileinfo.html \ html/class-giofileinputstream.html \ html/class-giofilemonitor.html \ + html/class-giofileoutputstream.html \ html/class-gioicon.html \ html/class-gioinputstream.html \ html/class-gioloadableicon.html \ @@ -82,6 +83,7 @@ XML_FILES = \ reference/pygio-fileinfo.xml \ reference/pygio-fileinputstream.xml \ reference/pygio-filemonitor.xml \ + reference/pygio-fileoutputstream.xml \ reference/pygio-icon.xml \ reference/pygio-inputstream.xml \ reference/pygio-loadableicon.xml \ diff --git a/docs/reference/pygio-classes.xml b/docs/reference/pygio-classes.xml index 4f2cfb2..5c7f9df 100644 --- a/docs/reference/pygio-classes.xml +++ b/docs/reference/pygio-classes.xml @@ -21,6 +21,7 @@ + diff --git a/docs/reference/pygio-fileoutputstream.xml b/docs/reference/pygio-fileoutputstream.xml new file mode 100644 index 0000000..f4367d7 --- /dev/null +++ b/docs/reference/pygio-fileoutputstream.xml @@ -0,0 +1,257 @@ + + + + + + gio.FileOutputStream + Base class for implementing streaming input + + + + Synopsis + + + gio.FileOutputStream + gio.OutputStream + + + get_etag + + + + query_info + attributes + cancellableNone + + + query_info_async + attributes + callback + io_priorityglib.PRIORITY_DEFAULT + cancellableNone + user_dataNone + + + query_info_finish + result + + + + + + + + Ancestry + ++-- gobject.GObject + +-- gio.OutputStream + +-- gio.FileOutputStream + + + + + + Implemented Interfaces + + gio.FileOutputStream + implements + gio.Seekable + + + + + Description + + + gio.FileOutputStream + provides output streams that write their content to a file. + + + gio.FileOutputStream + implements gio.Seekable, + which allows the output stream to jump to arbitrary positions in the file and to truncate + the file, provided the filesystem of the file supports these operations. In addition to the + generic gio.Seekable. API, + gio.FileOutputStream + has its own API for seeking and positioning. To find the position of a file output stream, use + gio.Seekable.tell(). + To find out if a file output stream supports seeking, use + gio.Seekable.can_seek(). + To position a file output stream, use + gio.Seekable.seek(). + To find out if a file output stream supports truncating, use + gio.FileOutputStream.can_truncate(). + To truncate a file output stream, use + gio.Seekable.truncate(). + + + + + Methods + + + gio.FileOutputStream.get_etag + + + get_etag + + + + + + Returns : + the entity tag for the stream. + + + + + + The get_etag() method gets the entity tag + for the file when it has been written. This must be called after the + stream has been written and closed, as the etag can change while writing. + + + + + gio.FileOutputStream.query_info + + + query_info + attributes + cancellableNone + + + + + attributes : + a file attribute query string. + + + + cancellable : + optional + gio.Cancellable + object, None to ignore. + + + + Returns : + a gio.FileInfo, + or None on error. + + + + + + The query_info() method queries a file input stream + the given attributes. This function blocks while querying the stream. + For the asynchronous (non-blocking) version of this function, see + gio.FileOutputStream.query_info_async(). + While the stream is blocked, the stream will set the pending flag internally, + and any other operations on the stream will fail with gio.ERROR_PENDING. + + + Can fail if the stream was already closed (with error being set to gio.ERROR_CLOSED), + the stream has pending operations (with error being set to gio.ERROR_PENDING), or + if querying info is not supported for the stream's interface (with error being set to + gio.ERROR_NOT_SUPPORTED). In all cases of failure, NULL will be returned. + + + If cancellable is not None, then the operation can be cancelled by + triggering the cancellable object from another thread. If the operation was cancelled, + the error gio.ERROR_CANCELLED will be set, and None will be returned. + + + + + gio.FileOutputStream.query_info_async + + + query_info_async + attributes + callback + io_priorityglib.PRIORITY_DEFAULT + cancellableNone + user_dataNone + + + + + attributes : + a file attribute query string. + + + + callback : + a GAsyncReadyCallback to call when the request is satisfied. + + + + io_priority : + the + + of the request. + + + + cancellable : + optional + gio.Cancellable + object, None to ignore. + + + user_data : + the data to pass to callback function. + + + + + + The query_info_async() method queries the stream + information asynchronously. When the operation is finished callback will be + called. You can then call + gio.FileOutputStream.query_info_finish() + to get the result of the operation. + + + For the synchronous version of this function, see + gio.FileOutputStream.query_info(). + + + If cancellable is not None, then the operation can be cancelled + by triggering the cancellable object from another thread. If the operation was + cancelled, the error gio.ERROR_CANCELLED will be set + + + + + gio.FileOutputStream.query_info_finish + + + query_info_finish + result + + + + + result : + a gio.AsyncResult. + + + + Returns : + a gio.FileInfo, + or None on error. + + + + + + The query_info_finish() method finishes an asynchronous + file append operation started with + gio.FileOutputStream.query_info_async(). + + + + diff --git a/gio/Makefile.am b/gio/Makefile.am index 1a86406..1fd193a 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -39,12 +39,13 @@ GIO_OVERRIDES = \ gappinfo.override \ gapplaunchcontext.override \ gdatainputstream.override \ - gdrive.override \ + gdrive.override \ gfile.override \ gfileattribute.override \ gfileenumerator.override \ gfileinfo.override \ gfileinputstream.override \ + gfileoutputstream.override \ gicon.override \ ginputstream.override \ gmount.override \ diff --git a/gio/gfileoutputstream.override b/gio/gfileoutputstream.override new file mode 100644 index 0000000..c5c184d --- /dev/null +++ b/gio/gfileoutputstream.override @@ -0,0 +1,68 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygobject - Python bindings for GObject + * Copyright (C) 2009 Gian Mario Tagliaretti + * + * gfileoutputstream.override: module overrides for GFileOuputStream + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +%% +override g_file_output_stream_query_info_async kwargs +static PyObject * +_wrap_g_file_output_stream_query_info_async(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "attributes", "callback", + "io_priority", "cancellable", "user_data", NULL }; + GCancellable *cancellable; + PyGObject *pycancellable = NULL; + int io_priority = G_PRIORITY_DEFAULT; + char *attributes; + PyGIONotify *notify; + + notify = pygio_notify_new(); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "sO|iOO:gio.FileOutputStream.query_info_async", + kwlist, + &attributes, + ¬ify->callback, + &io_priority, + &pycancellable, + ¬ify->data)) + + if (!pygio_notify_callback_is_valid(notify)) + goto error; + + if (!pygio_check_cancellable(pycancellable, &cancellable)) + goto error; + + pygio_notify_reference_callback(notify); + + g_file_output_stream_query_info_async(G_FILE_OUTPUT_STREAM(self->obj), + attributes, io_priority, cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; + + error: + pygio_notify_free(notify); + return NULL; +} diff --git a/gio/gio.override b/gio/gio.override index 39d85b7..a175760 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -237,6 +237,7 @@ include gfileenumerator.override gfileinfo.override gfileinputstream.override + gfileoutputstream.override gicon.override gmount.override ginputstream.override diff --git a/tests/test_gio.py b/tests/test_gio.py index 203f933..fb7360e 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -1011,3 +1011,30 @@ class TestFileInputStream(unittest.TestCase): loop = glib.MainLoop() loop.run() + +class TestFileOutputStream(unittest.TestCase): + def setUp(self): + self._f = open("file.txt", "w+") + self._f.write("testing") + self._f.seek(0) + self.file = gio.File("file.txt") + + def tearDown(self): + self._f.close() + if os.path.exists('file.txt'): + os.unlink("file.txt") + + def testQueryInfoAsync(self): + def callback(stream, result): + try: + info = stream.query_info_finish(result) + self.failUnless(isinstance(info, gio.FileInfo)) + self.failUnless(info.get_attribute_uint64("standard::size"), 7) + finally: + loop.quit() + + outputstream = self.file.append_to() + outputstream.query_info_async("standard", callback) + + loop = glib.MainLoop() + loop.run() -- cgit