All pastes #106409 Raw Edit

James Livingston

public text v1 · immutable
#106409 ·published 2006-07-30 08:30 UTC
rendered paste body
Index: bindings/python/tinymail.override
===================================================================
--- bindings/python/tinymail.override	(revision 649)
+++ bindings/python/tinymail.override	(working copy)
@@ -105,4 +105,53 @@
 				      data);
     return Py_None;
 }
+%%
+override-slot TnyListIface.tp_as_sequence
 
+static int
+_wrap_tny_list_iface_tp_length(PyGObject *self)
+{
+    return tny_list_iface_length(TNY_LIST_IFACE(self->obj));
+}
+
+static PyObject *
+_wrap_tny_list_iface_tp_getitem(PyGObject *self, PyObject *key)
+{
+    GObject *ret = NULL;
+
+    if (PyInt_Check (key)) {
+        int index;
+        TnyIteratorIface *iter;
+
+        index = PyInt_AsLong (key);
+        if (index < 0)
+            index += _wrap_tny_list_iface_tp_length (self);
+
+        iter = tny_list_iface_create_iterator (TNY_LIST_IFACE (self->obj));
+        /* TODO: check for failure? */
+
+        ret = tny_iterator_iface_nth (iter, index);
+        g_object_unref (G_OBJECT (iter));
+    } else {
+        /* TODO: handle other keys */
+	PyErr_SetString(PyExc_TypeError, "key must be valid index");
+	return NULL;
+    }
+
+    return pygobject_new (ret);
+}
+
+
+static PySequenceMethods _wrap_tny_list_iface_tp_as_sequence = {
+    (inquiry) _wrap_tny_list_iface_tp_length,
+    (binaryfunc) NULL, /* concatenate (PyGObject, PyObject) -> new PyGObject */
+    (intargfunc) NULL, /* repeat (PyGObject, int) ->new PyGObject */
+    (intargfunc) _wrap_tny_list_iface_tp_getitem,
+    (intintargfunc) NULL, /* getslice (PyGObject, int, int) -> PyObject[tuple] */
+    (intobjargproc) NULL, /* setitem (PyGObject, int, PyObject) -> int */
+    (intintobjargproc) NULL, /* setslice (PyGObject, int, int, PyObject[tuple]) -> int */
+    (objobjproc) NULL, /* contains (PyGObject, PyObject) -> int */
+    (binaryfunc) NULL, /* sq_inplace_concat;*/
+    (intargfunc) NULL /* sq_inplace_repeat */
+};
+