summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/Makefile.am2
-rw-r--r--docs/reference/pygio-classes.xml1
-rw-r--r--docs/reference/pygio-fileoutputstream.xml257
-rw-r--r--gio/Makefile.am3
-rw-r--r--gio/gfileoutputstream.override68
-rw-r--r--gio/gio.override1
-rw-r--r--tests/test_gio.py27
7 files changed, 358 insertions, 1 deletions
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 @@
<xi:include href="pygio-fileinfo.xml"/>
<xi:include href="pygio-fileinputstream.xml"/>
<xi:include href="pygio-filemonitor.xml"/>
+<xi:include href="pygio-fileoutputstream.xml"/>
<xi:include href="pygio-icon.xml"/>
<xi:include href="pygio-inputstream.xml"/>
<xi:include href="pygio-loadableicon.xml"/>
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 @@
+<?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-giofileoutputstream">
+ <refnamediv>
+ <refname>gio.FileOutputStream</refname>
+ <refpurpose>Base class for implementing streaming input</refpurpose>
+ </refnamediv>
+
+ <refsect1>
+ <title>Synopsis</title>
+
+ <classsynopsis language="python">
+ <ooclass><classname>gio.FileOutputStream</classname></ooclass>
+ <ooclass><classname><link linkend="class-giooutputstream">gio.OutputStream</link></classname></ooclass>
+
+ <methodsynopsis language="python">
+ <methodname><link linkend="method-giofileoutputstream--get-etag">get_etag</link></methodname>
+ <methodparam></methodparam>
+ </methodsynopsis>
+ <methodsynopsis language="python">
+ <methodname><link linkend="method-giofileoutputstream--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-giofileoutputstream--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-giofileoutputstream--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-giooutputstream">gio.OutputStream</link>
+ +-- <link linkend="class-giofileoutputstream">gio.FileOutputStream</link>
+</synopsis>
+
+ </refsect1>
+
+ <refsect1>
+ <title>Implemented Interfaces</title>
+ <para>
+ <link linkend="class-giofileoutputstream"><classname>gio.FileOutputStream</classname></link>
+ implements
+ <link linkend="class-gioseekable"><classname>gio.Seekable</classname></link>
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para>
+ <link linkend="class-giofileoutputstream"><classname>gio.FileOutputStream</classname></link>
+ provides output streams that write their content to a file.
+ </para>
+ <para>
+ <link linkend="class-giofileoutputstream"><classname>gio.FileOutputStream</classname></link>
+ implements <link linkend="class-gioseekable"><classname>gio.Seekable</classname></link>,
+ 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,
+ <link linkend="class-giofileoutputstream"><classname>gio.FileOutputStream</classname></link>
+ has its own API for seeking and positioning. To find the position of a file output stream, use
+ <methodname><link linkend="method-gioseekable--tell">gio.Seekable.tell</link></methodname>().
+ To find out if a file output stream supports seeking, use
+ <methodname><link linkend="method-gioseekable--can_seek">gio.Seekable.can_seek</link></methodname>().
+ To position a file output stream, use
+ <methodname><link linkend="method-gioseekable--seek">gio.Seekable.seek</link></methodname>().
+ To find out if a file output stream supports truncating, use
+ <methodname><link linkend="method-gioseekable--can_truncate">gio.FileOutputStream.can_truncate</link></methodname>().
+ To truncate a file output stream, use
+ <methodname><link linkend="method-gioseekable--truncate">gio.Seekable.truncate</link></methodname>().
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Methods</title>
+
+ <refsect2 id="method-giofileoutputstream--get-etag">
+ <title>gio.FileOutputStream.get_etag</title>
+
+ <programlisting><methodsynopsis language="python">
+ <methodname>get_etag</methodname>
+ <methodparam></methodparam>
+ </methodsynopsis></programlisting>
+
+ <variablelist>
+ <varlistentry>
+ <term><emphasis>Returns</emphasis>&nbsp;:</term>
+ <listitem><simpara>the entity tag for the stream.
+ </simpara></listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ The <methodname>get_etag</methodname>() 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.
+ </para>
+ </refsect2>
+
+ <refsect2 id="method-giofileoutputstream--query-info">
+ <title>gio.FileOutputStream.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-giofileoutputstream--query-info-async">gio.FileOutputStream.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>
+ <para>
+ 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.
+ </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, and <literal>None</literal> will be returned.
+ </para>
+ </refsect2>
+
+ <refsect2 id="method-giofileoutputstream--query-info-async">
+ <title>gio.FileOutputStream.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-giofileoutputstream--query-info-finish">gio.FileOutputStream.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-giofileoutputstream--query-info">gio.FileOutputStream.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-giofileoutputstream--query-info-finish">
+ <title>gio.FileOutputStream.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-giofileoutputstream--query-info-async">gio.FileOutputStream.query_info_async</link></methodname>().
+ </para>
+ </refsect2>
+ </refsect1>
+</refentry>
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,
+ &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_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()