diff options
-rw-r--r-- | docs/Makefile.am | 4 | ||||
-rw-r--r-- | docs/reference/pygio-classes.xml | 1 | ||||
-rw-r--r-- | docs/reference/pygio-memoryinputstream.xml | 151 | ||||
-rw-r--r-- | gio/Makefile.am | 1 | ||||
-rw-r--r-- | gio/ginputstream.override | 34 | ||||
-rw-r--r-- | gio/gio.override | 1 | ||||
-rw-r--r-- | gio/gmemoryinputstream.override | 91 | ||||
-rw-r--r-- | tests/test_gio.py | 4 |
8 files changed, 252 insertions, 35 deletions
diff --git a/docs/Makefile.am b/docs/Makefile.am index 85673c1..46bdc12 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -36,7 +36,8 @@ HTML_FILES = \ html/class-gioicon.html \ html/class-gioinputstream.html \ html/class-gioloadableicon.html \ - html/class-giomount.html \ + html/class-giomemoryinputstream.html \ + html/class-giomount.html \ html/class-giomountoperation.html \ html/class-giooutputstream.html \ html/class-gioseekable.html \ @@ -91,6 +92,7 @@ XML_FILES = \ reference/pygio-icon.xml \ reference/pygio-inputstream.xml \ reference/pygio-loadableicon.xml \ + reference/pygio-memoryinputstream.xml \ reference/pygio-mount.xml \ reference/pygio-mountoperation.xml \ reference/pygio-outputstream.xml \ diff --git a/docs/reference/pygio-classes.xml b/docs/reference/pygio-classes.xml index 0b385d6..8e5b191 100644 --- a/docs/reference/pygio-classes.xml +++ b/docs/reference/pygio-classes.xml @@ -27,6 +27,7 @@ <xi:include href="pygio-icon.xml"/> <xi:include href="pygio-inputstream.xml"/> <xi:include href="pygio-loadableicon.xml"/> +<xi:include href="pygio-memoryinputstream.xml"/> <xi:include href="pygio-mount.xml"/> <xi:include href="pygio-mountoperation.xml"/> <xi:include href="pygio-outputstream.xml"/> diff --git a/docs/reference/pygio-memoryinputstream.xml b/docs/reference/pygio-memoryinputstream.xml new file mode 100644 index 0000000..7d8cffb --- /dev/null +++ b/docs/reference/pygio-memoryinputstream.xml @@ -0,0 +1,151 @@ +<?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-giomemoryinputstream"> + <refnamediv> + <refname>gio.MemoryInputStream</refname> + <refpurpose>Base class for implementing streaming input</refpurpose> + </refnamediv> + + <refsect1> + <title>Synopsis</title> + + <classsynopsis language="python"> + <ooclass><classname>gio.MemoryInputStream</classname></ooclass> + <ooclass><classname><link linkend="class-gioinputstream">gio.InputStream</link></classname></ooclass> + + <constructorsynopsis language="python"> + <methodname><link linkend="constructor-giomemoryinputstream">gio.MemoryInputStream</link></methodname> + <methodparam></methodparam> + </constructorsynopsis> + + + <methodsynopsis language="python"> + <methodname><link linkend="method-giomemoryinputstream--add-data">add_data</link></methodname> + <methodparam><parameter role="keyword">data</parameter></methodparam> + </methodsynopsis> + + </classsynopsis> + +<programlisting> +<emphasis role="bold">Functions</emphasis> + +<methodsynopsis language="python"> + <methodname><link linkend="function-gio--memory-input-stream-new-from-data">gio.memory_input_stream_new_from_data</link></methodname> + <methodparam><parameter role="keyword">data</parameter></methodparam> +</methodsynopsis></programlisting> + + </refsect1> + + <refsect1> + <title>Ancestry</title> + +<synopsis>+-- <link linkend="class-gobject">gobject.GObject</link> + +-- <link linkend="class-gioinputstream">gio.InputStream</link> + +-- <link linkend="class-giomemoryinputstream">gio.MemoryInputStream</link> +</synopsis> + + </refsect1> + + <refsect1> + <title>Implemented Interfaces</title> + <para> + <link linkend="class-giomemoryinputstream"><classname>gio.MemoryInputStream</classname></link> + implements + <link linkend="class-gioseekable"><classname>gio.Seekable</classname></link> + </para> + </refsect1> + + <refsect1> + <title>Description</title> + + <para> + <link linkend="class-giomemoryinputstream"><classname>gio.MemoryInputStream</classname></link> + is a class for using arbitrary memory chunks as input for GIO streaming input operations. + </para> + </refsect1> + + <refsect1 id="constructor-giomemoryinputstream"> + <title>Constructor</title> + + <programlisting><constructorsynopsis language="python"> + <methodname>gio.MemoryInputStream</methodname> + <methodparam><parameter role="keyword">icon</parameter></methodparam> + </constructorsynopsis></programlisting> + <variablelist> + <varlistentry> + <term><emphasis>Returns</emphasis> :</term> + <listitem><simpara>a new + <link linkend="class-giomemoryinputstream"><classname>gio.MemoryInputStream</classname></link>. + </simpara></listitem> + </varlistentry> + </variablelist> + + <para> + Creates an empty + <link linkend="class-giomemoryinputstream"><classname>gio.MemoryInputStream</classname></link>. + </para> + + </refsect1> + + <refsect1> + <title>Methods</title> + + <refsect2 id="method-giomemoryinputstream--add-data"> + <title>gio.MemoryInputStream.add_data</title> + + <programlisting><methodsynopsis language="python"> + <methodname>add_data</methodname> + <methodparam><parameter role="keyword">data</parameter></methodparam> + </methodsynopsis></programlisting> + + <variablelist> + <varlistentry> + <term><parameter role="keyword">data</parameter> :</term> + <listitem><simpara>input data. + </simpara></listitem> + </varlistentry> + </variablelist> + + <para> + The <methodname>add_data</methodname>() method appends data to data + that can be read from the input stream + </para> + </refsect2> + </refsect1> + + <refsect1> + <title>Functions</title> + + <refsect2 id="function-gio--memory-input-stream-new-from-data"> + <title>gio.memory_input_stream_new_from_data</title> + + <programlisting><methodsynopsis language="python"> + <methodname>memory_input_stream_new_from_data</methodname> + <methodparam><parameter role="keyword">data</parameter></methodparam> + </methodsynopsis></programlisting> + + <variablelist> + <varlistentry> + <term><parameter>data</parameter> :</term> + <listitem><simpara>input data. + </simpara></listitem> + </varlistentry> + <varlistentry> + <term><emphasis>Returns</emphasis> :</term> + <listitem><simpara>A new + <link linkend="class-giomemoryinputstream"><classname>gio.MemoryInputStream</classname></link> + read from data + </simpara></listitem> + </varlistentry> + </variablelist> + + <para> + The <methodname>memory_input_stream_new_from_data</methodname>() function creates + a new <link linkend="class-giomemoryinputstream"><classname>gio.MemoryInputStream</classname></link> + with data in memory. + </para> + </refsect2> + </refsect1> +</refentry> diff --git a/gio/Makefile.am b/gio/Makefile.am index 1fd193a..ae1613e 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -48,6 +48,7 @@ GIO_OVERRIDES = \ gfileoutputstream.override \ gicon.override \ ginputstream.override \ + gmemoryinputstream.override \ gmount.override \ goutputstream.override \ gvolume.override \ diff --git a/gio/ginputstream.override b/gio/ginputstream.override index 075a20c..762a47a 100644 --- a/gio/ginputstream.override +++ b/gio/ginputstream.override @@ -293,40 +293,6 @@ _wrap_g_input_stream_close_async(PyGObject *self, return NULL; } %% -override g_memory_input_stream_add_data kwargs -static PyObject * -_wrap_g_memory_input_stream_add_data(PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "data", NULL }; - PyObject *data; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:gio.MemoryInputStream.add_data", - kwlist, &data)) - return NULL; - - if (data != Py_None) { - char *copy; - int length; - - if (!PyString_Check(data)) { - PyErr_SetString(PyExc_TypeError, "data must be a string or None"); - return NULL; - } - - length = PyString_Size(data); - copy = g_malloc(length); - memcpy(copy, PyString_AsString(data), length); - - g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(self->obj), - copy, length, (GDestroyNotify) g_free); - } - - Py_INCREF(Py_None); - return Py_None; -} -%% override g_input_stream_skip_async kwargs static PyObject * _wrap_g_input_stream_skip_async(PyGObject *self, diff --git a/gio/gio.override b/gio/gio.override index a175760..ac0515e 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -239,6 +239,7 @@ include gfileinputstream.override gfileoutputstream.override gicon.override + gmemoryinputstream.override gmount.override ginputstream.override goutputstream.override diff --git a/gio/gmemoryinputstream.override b/gio/gmemoryinputstream.override new file mode 100644 index 0000000..0495338 --- /dev/null +++ b/gio/gmemoryinputstream.override @@ -0,0 +1,91 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygobject - Python bindings for GObject + * Copyright (C) 2008 Johan Dahlin + * Copyright (C) 2009 Gian Mario Tagliaretti + * + * gmemoryinputstream.override: module overrides for GMemoryInputStream + * + * 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_memory_input_stream_add_data kwargs +static PyObject * +_wrap_g_memory_input_stream_add_data(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "data", NULL }; + PyObject *data; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:gio.MemoryInputStream.add_data", + kwlist, &data)) + return NULL; + + if (data != Py_None) { + char *copy; + int length; + + if (!PyString_Check(data)) { + PyErr_SetString(PyExc_TypeError, "data must be a string or None"); + return NULL; + } + + length = PyString_Size(data); + copy = g_malloc(length); + memcpy(copy, PyString_AsString(data), length); + + g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(self->obj), + copy, length, (GDestroyNotify) g_free); + } + + Py_INCREF(Py_None); + return Py_None; +} +%% +override g_memory_input_stream_new_from_data kwargs +static PyObject * +_wrap_g_memory_input_stream_new_from_data(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "data", NULL }; + PyObject *data; + GInputStream *stream = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:gio.memory_input_stream_new_from_data", + kwlist, &data)) + return NULL; + + if (data != Py_None) { + char *copy; + int length; + + if (!PyString_Check(data)) { + PyErr_SetString(PyExc_TypeError, "data must be a string or None"); + return NULL; + } + + length = PyString_Size(data); + copy = g_malloc(length); + memcpy(copy, PyString_AsString(data), length); + + stream = g_memory_input_stream_new_from_data(copy, length, + (GDestroyNotify) g_free); + } + + return pygobject_new((GObject *)stream); +} diff --git a/tests/test_gio.py b/tests/test_gio.py index fb7360e..de5409f 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -759,6 +759,10 @@ class TestMemoryInputStream(unittest.TestCase): self.stream.add_data(None) self.stream.add_data('spam') self.assertEquals('ham spam', self.stream.read()) + + def test_new_from_data(self): + stream = gio.memory_input_stream_new_from_data('spam') + self.assertEquals('spam', stream.read()) class TestOutputStream(unittest.TestCase): |