From dfbdf23633a772e78b47b0e7b0c3e3b87855d9ff Mon Sep 17 00:00:00 2001 From: Gian Mario Tagliaretti Date: Mon, 8 Jun 2009 11:45:11 +0200 Subject: Wrap gio.memory_input_stream_new_from_data Add the wrapper for gio.memory_input_stream_new_from_data including docs and a test. --- docs/Makefile.am | 4 +- docs/reference/pygio-classes.xml | 1 + docs/reference/pygio-memoryinputstream.xml | 151 +++++++++++++++++++++++++++++ gio/Makefile.am | 1 + gio/ginputstream.override | 34 ------- gio/gio.override | 1 + gio/gmemoryinputstream.override | 91 +++++++++++++++++ tests/test_gio.py | 4 + 8 files changed, 252 insertions(+), 35 deletions(-) create mode 100644 docs/reference/pygio-memoryinputstream.xml create mode 100644 gio/gmemoryinputstream.override 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 @@ + 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 @@ + + + + + + gio.MemoryInputStream + Base class for implementing streaming input + + + + Synopsis + + + gio.MemoryInputStream + gio.InputStream + + + gio.MemoryInputStream + + + + + + add_data + data + + + + + +Functions + + + gio.memory_input_stream_new_from_data + data + + + + + + Ancestry + ++-- gobject.GObject + +-- gio.InputStream + +-- gio.MemoryInputStream + + + + + + Implemented Interfaces + + gio.MemoryInputStream + implements + gio.Seekable + + + + + Description + + + gio.MemoryInputStream + is a class for using arbitrary memory chunks as input for GIO streaming input operations. + + + + + Constructor + + + gio.MemoryInputStream + icon + + + + Returns : + a new + gio.MemoryInputStream. + + + + + + Creates an empty + gio.MemoryInputStream. + + + + + + Methods + + + gio.MemoryInputStream.add_data + + + add_data + data + + + + + data : + input data. + + + + + + The add_data() method appends data to data + that can be read from the input stream + + + + + + Functions + + + gio.memory_input_stream_new_from_data + + + memory_input_stream_new_from_data + data + + + + + data : + input data. + + + + Returns : + A new + gio.MemoryInputStream + read from data + + + + + + The memory_input_stream_new_from_data() function creates + a new gio.MemoryInputStream + with data in memory. + + + + 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): -- cgit