[pygobject] Wrap gio.FileInputStream.query_async



commit f605811afe8c91f121e89b6f9ec28c70b62f4110
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Mon Jun 1 22:40:56 2009 +0200

    Wrap gio.FileInputStream.query_async
    
    Add the wrapper for gio.FileInputStream.query_async including docs and
    a test.
---
 docs/Makefile.am                         |    2 +
 docs/reference/pygio-classes.xml         |    1 +
 docs/reference/pygio-fileinputstream.xml |  221 ++++++++++++++++++++++++++++++
 gio/Makefile.am                          |    1 +
 gio/gfileinputstream.override            |   68 +++++++++
 gio/gio.override                         |    1 +
 tests/test_gio.py                        |   27 ++++
 7 files changed, 321 insertions(+), 0 deletions(-)

diff --git a/docs/Makefile.am b/docs/Makefile.am
index 0e31a9a..72b4270 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -28,6 +28,7 @@ HTML_FILES =					\
 	html/class-giofileenumerator.html	\
 	html/class-giofileicon.html		\
 	html/class-giofileinfo.html		\
+	html/class-giofileinputstream.html	\
 	html/class-giofilemonitor.html		\
 	html/class-gioicon.html			\
 	html/class-gioinputstream.html		\
@@ -79,6 +80,7 @@ XML_FILES = 					\
 	reference/pygio-fileenumerator.xml	\
 	reference/pygio-fileicon.xml 		\
 	reference/pygio-fileinfo.xml 		\
+	reference/pygio-fileinputstream.xml 	\
 	reference/pygio-filemonitor.xml		\
 	reference/pygio-icon.xml		\
 	reference/pygio-inputstream.xml		\
diff --git a/docs/reference/pygio-classes.xml b/docs/reference/pygio-classes.xml
index c4869ca..4f2cfb2 100644
--- a/docs/reference/pygio-classes.xml
+++ b/docs/reference/pygio-classes.xml
@@ -19,6 +19,7 @@
 <xi:include href="pygio-fileenumerator.xml"/>
 <xi:include href="pygio-fileicon.xml"/>
 <xi:include href="pygio-fileinfo.xml"/>
+<xi:include href="pygio-fileinputstream.xml"/>
 <xi:include href="pygio-filemonitor.xml"/>
 <xi:include href="pygio-icon.xml"/>
 <xi:include href="pygio-inputstream.xml"/>
diff --git a/docs/reference/pygio-fileinputstream.xml b/docs/reference/pygio-fileinputstream.xml
new file mode 100644
index 0000000..f22b60a
--- /dev/null
+++ b/docs/reference/pygio-fileinputstream.xml
@@ -0,0 +1,221 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd";>
+
+<refentry id="class-giofileinputstream">
+    <refnamediv>
+        <refname>gio.FileInputStream</refname>
+        <refpurpose>Base class for implementing streaming input</refpurpose>
+    </refnamediv>
+
+    <refsect1>
+        <title>Synopsis</title>
+
+    <classsynopsis language="python">
+        <ooclass><classname>gio.FileInputStream</classname></ooclass>
+        <ooclass><classname><link linkend="class-gioinputstream">gio.InputStream</link></classname></ooclass>
+
+    <methodsynopsis language="python">
+        <methodname><link linkend="method-giofileinputstream--query-info">query_info</link></methodname>
+        <methodparam><parameter role="keyword">attributes</parameter></methodparam>
+        <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
+    </methodsynopsis>
+    <methodsynopsis language="python">
+        <methodname><link linkend="method-giofileinputstream--query-info-async">query_info_async</link></methodname>
+        <methodparam><parameter role="keyword">attributes</parameter></methodparam>
+        <methodparam><parameter role="keyword">callback</parameter></methodparam>
+        <methodparam><parameter role="keyword">io_priority</parameter><initializer>glib.PRIORITY_DEFAULT</initializer></methodparam>
+        <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
+        <methodparam><parameter role="keyword">user_data</parameter><initializer>None</initializer></methodparam>
+    </methodsynopsis>
+    <methodsynopsis language="python">
+        <methodname><link linkend="method-giofileinputstream--query-info-finish">query_info_finish</link></methodname>
+        <methodparam><parameter role="keyword">result</parameter></methodparam>
+    </methodsynopsis>
+
+    </classsynopsis>
+
+    </refsect1>
+
+    <refsect1>
+        <title>Ancestry</title>
+
+<synopsis>+-- <link linkend="class-gobject">gobject.GObject</link>
+  +-- <link linkend="class-gioinputstream">gio.InputStream</link>
+    +-- <link linkend="class-giofileinputstream">gio.FileInputStream</link>
+</synopsis>
+
+    </refsect1>
+
+    <refsect1>
+        <title>Description</title>
+
+        <para>
+            <link linkend="class-giofileinputstream"><classname>gio.FileInputStream</classname></link>
+            provides input streams that take their content from a file.
+        </para>
+        <para>
+            <link linkend="class-giofileinputstream"><classname>gio.FileInputStream</classname></link>
+            implements <link linkend="class-gioseekable"><classname>gio.Seekable</classname></link>,
+            which allows the input stream to jump to arbitrary positions in the file, provided the filesystem
+            of the file allows it. In addition to the generic g_seekable_ API,
+            <link linkend="class-giofileinputstream"><classname>gio.FileInputStream</classname></link>
+            has its own API for seeking and positioning. To find the position of a file input stream, use
+            <methodname><link linkend="method-gioseekable--tell">gio.Seekable.tell</link></methodname>().
+            To find out if a file input stream supports seeking, use
+            <methodname><link linkend="method-gioseekable--can_seek">gio.Seekable.can_seek</link></methodname>().
+            To position a file input stream, use
+            <methodname><link linkend="method-gioseekable--seek">gio.Seekable.seek</link></methodname>().
+        </para>
+    </refsect1>
+
+    <refsect1>
+        <title>Methods</title>
+
+        <refsect2 id="method-giofileinputstream--clear-pending">
+            <title>gio.FileInputStream.clear_pending</title>
+
+            <programlisting><methodsynopsis language="python">
+                <methodname>clear_pending</methodname>
+                <methodparam></methodparam>
+            </methodsynopsis></programlisting>
+            
+            <variablelist>
+            </variablelist>
+    
+            <para>
+                The <methodname>clear_pending</methodname>() method clears the pending flag on stream.
+            </para>
+        </refsect2>
+
+        <refsect2 id="method-giofileinputstream--query-info">
+            <title>gio.FileInputStream.query_info</title>
+
+            <programlisting><methodsynopsis language="python">
+                <methodname>query_info</methodname>
+                <methodparam><parameter role="keyword">attributes</parameter></methodparam>
+                <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
+            </methodsynopsis></programlisting>
+            
+            <variablelist>
+                <varlistentry>
+                  <term><parameter role="keyword">attributes</parameter>&nbsp;:</term>
+                  <listitem><simpara>a file attribute query string.
+                  </simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                  <term><parameter role="keyword">cancellable</parameter>&nbsp;:</term>
+                  <listitem><simpara>optional
+                    <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
+                    object, <literal>None</literal> to ignore.
+                  </simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term><emphasis>Returns</emphasis>&nbsp;:</term>
+                    <listitem><simpara>a <link linkend="class-giofileinfo"><classname>gio.FileInfo</classname></link>,
+                    or <literal>None</literal> on error.
+                    </simpara></listitem>
+                </varlistentry>
+            </variablelist>
+    
+            <para>
+                The <methodname>query_info</methodname>() 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
+                <methodname><link linkend="method-giofileinputstream--query-info-async">gio.FileInputStream.query_info_async</link></methodname>().
+                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.
+            </para>
+        </refsect2>
+
+        <refsect2 id="method-giofileinputstream--query-info-async">
+            <title>gio.FileInputStream.query_info_async</title>
+
+            <programlisting><methodsynopsis language="python">
+                <methodname>query_info_async</methodname>
+                <methodparam><parameter role="keyword">attributes</parameter></methodparam>
+                <methodparam><parameter role="keyword">callback</parameter></methodparam>
+                <methodparam><parameter role="keyword">io_priority</parameter><initializer>glib.PRIORITY_DEFAULT</initializer></methodparam>
+                <methodparam><parameter role="keyword">cancellable</parameter><initializer>None</initializer></methodparam>
+                <methodparam><parameter role="keyword">user_data</parameter><initializer>None</initializer></methodparam>
+            </methodsynopsis></programlisting>
+            
+            <variablelist>
+                <varlistentry>
+                  <term><parameter role="keyword">attributes</parameter>&nbsp;:</term>
+                  <listitem><simpara>a file attribute query string.
+                  </simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term><parameter>callback</parameter>&nbsp;:</term>
+                    <listitem><simpara>a GAsyncReadyCallback to call when the request is satisfied.
+                    </simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term><parameter>io_priority</parameter>&nbsp;:</term>
+                    <listitem><simpara>the
+                    <xref linkend="glib-priority-constants" endterm="glib-priority-constants-title"></xref>
+                    of the request. 
+                    </simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term><parameter>cancellable</parameter>&nbsp;:</term>
+                    <listitem><simpara>optional
+                    <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
+                    object, <literal>None</literal> to ignore.</simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term><parameter>user_data</parameter>&nbsp;:</term>
+                    <listitem><simpara>the data to pass to callback function.
+                    </simpara></listitem>
+                </varlistentry>
+            </variablelist>
+    
+            <para>
+                The <methodname>query_info_async</methodname>() method queries the stream
+                information asynchronously. When the operation is finished callback will be
+                called. You can then call
+                <methodname><link linkend="method-giofileinputstream--query-info-finish">gio.FileInputStream.query_info_finish</link></methodname>()
+                to get the result of the operation.
+            </para>
+            <para>
+                For the synchronous version of this function, see
+                <methodname><link linkend="method-giofileinputstream--query-info">gio.FileInputStream.query_info</link></methodname>().
+            </para>
+            <para>
+                If cancellable is not <literal>None</literal>, 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
+            </para>
+        </refsect2>
+
+        <refsect2 id="method-giofileinputstream--query-info-finish">
+            <title>gio.FileInputStream.query_info_finish</title>
+
+            <programlisting><methodsynopsis language="python">
+                <methodname>query_info_finish</methodname>
+                <methodparam><parameter role="keyword">result</parameter></methodparam>
+            </methodsynopsis></programlisting>
+            
+            <variablelist>
+                <varlistentry>
+                  <term><parameter role="keyword">result</parameter>&nbsp;:</term>
+                  <listitem><simpara>a <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>.
+                  </simpara></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term><emphasis>Returns</emphasis>&nbsp;:</term>
+                    <listitem><simpara>a <link linkend="class-giofileinfo"><classname>gio.FileInfo</classname></link>,
+                    or <literal>None</literal> on error.
+                    </simpara></listitem>
+                </varlistentry>
+            </variablelist>
+    
+            <para>
+                The <methodname>query_info_finish</methodname>() method finishes an asynchronous
+                file append operation started with
+                <methodname><link linkend="method-giofileinputstream--query-info-async">gio.FileInputStream.query_info_async</link></methodname>().
+            </para>
+        </refsect2>
+    </refsect1>
+</refentry>
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 7a2fe58..1a86406 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -44,6 +44,7 @@ GIO_OVERRIDES = 			\
 	gfileattribute.override		\
 	gfileenumerator.override	\
 	gfileinfo.override		\
+	gfileinputstream.override	\
 	gicon.override			\
 	ginputstream.override 		\
 	gmount.override			\
diff --git a/gio/gfileinputstream.override b/gio/gfileinputstream.override
new file mode 100644
index 0000000..cb0258d
--- /dev/null
+++ b/gio/gfileinputstream.override
@@ -0,0 +1,68 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygobject - Python bindings for GObject
+ * Copyright (C) 2009  Gian Mario Tagliaretti
+ *
+ *   gfileinputstream.override: module overrides for GFileInputStream
+ *
+ * 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_input_stream_query_info_async kwargs
+static PyObject *
+_wrap_g_file_input_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.File.query_info_async",
+                                     kwlist,
+                                     &attributes,
+                                     &notify->callback,
+                                     &io_priority,
+                                     &pycancellable,
+                                     &notify->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_input_stream_query_info_async(G_FILE_INPUT_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 e68f725..39d85b7 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -236,6 +236,7 @@ include
   gfileattribute.override
   gfileenumerator.override
   gfileinfo.override
+  gfileinputstream.override
   gicon.override
   gmount.override
   ginputstream.override
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 2d33e8f..203f933 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -984,3 +984,30 @@ class TestVolume(unittest.TestCase):
                 for id in ids:
                     if id is not None:
                         self.failUnless(isinstance(id, str))
+
+class TestFileInputStream(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()
+
+        inputstream = self.file.read()
+        inputstream.query_info_async("standard", callback)
+
+        loop = glib.MainLoop()
+        loop.run()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]