Skip to content

Commit

Permalink
Wrap gio.memory_input_stream_new_from_data
Browse files Browse the repository at this point in the history
Add the wrapper for gio.memory_input_stream_new_from_data including
docs and a test.
  • Loading branch information
gianmt committed Jun 8, 2009
1 parent fcc3cb0 commit dfbdf23
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 35 deletions.
4 changes: 3 additions & 1 deletion docs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions docs/reference/pygio-classes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
151 changes: 151 additions & 0 deletions docs/reference/pygio-memoryinputstream.xml
Original file line number Diff line number Diff line change
@@ -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>&nbsp;:</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>&nbsp;:</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>&nbsp;:</term>
<listitem><simpara>input data.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><emphasis>Returns</emphasis>&nbsp;:</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>
1 change: 1 addition & 0 deletions gio/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ GIO_OVERRIDES = \
gfileoutputstream.override \
gicon.override \
ginputstream.override \
gmemoryinputstream.override \
gmount.override \
goutputstream.override \
gvolume.override \
Expand Down
34 changes: 0 additions & 34 deletions gio/ginputstream.override
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions gio/gio.override
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ include
gfileinputstream.override
gfileoutputstream.override
gicon.override
gmemoryinputstream.override
gmount.override
ginputstream.override
goutputstream.override
Expand Down
91 changes: 91 additions & 0 deletions gio/gmemoryinputstream.override
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 4 additions & 0 deletions tests/test_gio.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,10 @@ def test_add_data(self):
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):
Expand Down

0 comments on commit dfbdf23

Please sign in to comment.