pygobject r944 - in trunk: . gio tests
- From: paulp svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r944 - in trunk: . gio tests
- Date: Mon, 11 Aug 2008 22:05:06 +0000 (UTC)
Author: paulp
Date: Mon Aug 11 22:05:06 2008
New Revision: 944
URL: http://svn.gnome.org/viewvc/pygobject?rev=944&view=rev
Log:
2008-08-12 Paul Pogonyshev <pogonyshev gmx net>
Bug 547354 â wrap a few memory stream methods
* gio/ginputstream.override (_wrap_g_memory_input_stream_add_data):
New function.
* gio/gio.defs (gio.MemoryOutputStream.get_contents): Rename from
get_data() to avoid name clash.
* gio/goutputstream.override (_wrap_g_memory_output_stream_new)
(_wrap_g_memory_output_stream_get_data): New functions.
* tests/test_gio.py (TestMemoryInputStream)
(TestMemoryOutputStream): New test cases.
Modified:
trunk/ChangeLog
trunk/gio/ginputstream.override
trunk/gio/gio.defs
trunk/gio/goutputstream.override
trunk/tests/test_gio.py
Modified: trunk/gio/ginputstream.override
==============================================================================
--- trunk/gio/ginputstream.override (original)
+++ trunk/gio/ginputstream.override Mon Aug 11 22:05:06 2008
@@ -285,5 +285,39 @@
Py_INCREF(Py_None);
return Py_None;
}
+%%
+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;
+}
/* GInputStream.read_all: No ArgType for void* */
/* GInputStream.skip_async: No ArgType for GAsyncReadyCallback */
Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs (original)
+++ trunk/gio/gio.defs Mon Aug 11 22:05:06 2008
@@ -3667,7 +3667,8 @@
)
)
-(define-method get_data
+;; Note: name clash with gobject.GObject.get_data; renamed.
+(define-method get_contents
(of-object "GMemoryOutputStream")
(c-name "g_memory_output_stream_get_data")
(return-type "gpointer")
Modified: trunk/gio/goutputstream.override
==============================================================================
--- trunk/gio/goutputstream.override (original)
+++ trunk/gio/goutputstream.override Mon Aug 11 22:05:06 2008
@@ -156,6 +156,31 @@
Py_INCREF(Py_None);
return Py_None;
}
+%%
+override g_memory_output_stream_new noargs
+static int
+_wrap_g_memory_output_stream_new(PyGObject *self)
+{
+ self->obj = (GObject *)g_memory_output_stream_new(NULL, 0, g_realloc, g_free);
+
+ if (!self->obj) {
+ PyErr_SetString(PyExc_RuntimeError, "could not create gio.MemoryOutputStream object");
+ return -1;
+ }
+
+ pygobject_register_wrapper((PyObject *)self);
+ return 0;
+}
+%%
+override g_memory_output_stream_get_data noargs
+static PyObject *
+_wrap_g_memory_output_stream_get_data(PyGObject *self)
+{
+ GMemoryOutputStream *stream = G_MEMORY_OUTPUT_STREAM(self->obj);
+ return PyString_FromStringAndSize(g_memory_output_stream_get_data(stream),
+ g_seekable_tell(G_SEEKABLE(stream)));
+}
+
/* GOutputStream.write_all: No ArgType for const-void* */
/* GOutputStream.splice_async: No ArgType for GAsyncReadyCallback */
/* GOutputStream.flush_async: No ArgType for GAsyncReadyCallback */
Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py (original)
+++ trunk/tests/test_gio.py Mon Aug 11 22:05:06 2008
@@ -545,6 +545,20 @@
loop.run()
+class TestMemoryInputStream(unittest.TestCase):
+ def setUp(self):
+ self.stream = gio.MemoryInputStream()
+
+ def test_add_data(self):
+ self.stream.add_data('foobar')
+ self.assertEquals('foobar', self.stream.read())
+
+ self.stream.add_data('ham ')
+ self.stream.add_data(None)
+ self.stream.add_data('spam')
+ self.assertEquals('ham spam', self.stream.read())
+
+
class TestOutputStream(unittest.TestCase):
def setUp(self):
self._f = open("outputstream.txt", "w")
@@ -614,6 +628,18 @@
loop.run()
+class TestMemoryOutputStream(unittest.TestCase):
+ def setUp(self):
+ self.stream = gio.MemoryOutputStream()
+
+ def test_get_contents(self):
+ self.stream.write('foobar')
+ self.assertEquals('foobar', self.stream.get_contents())
+
+ self.stream.write('baz')
+ self.assertEquals('foobarbaz', self.stream.get_contents())
+
+
class TestVolumeMonitor(unittest.TestCase):
def setUp(self):
self.monitor = gio.volume_monitor_get()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]