summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:04:36 +0000
committerFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:04:36 +0000
commit87f9e0f350b879b7d721889cc6fbc6f878f4cd0f (patch)
tree0cb15d69dc0950ba47de2f40033ca42b689a7a09
parentc8762f405baaac8cbb6475b39d4fbd701a34060a (diff)
downloadlasso-87f9e0f350b879b7d721889cc6fbc6f878f4cd0f.tar.gz
lasso-87f9e0f350b879b7d721889cc6fbc6f878f4cd0f.tar.xz
lasso-87f9e0f350b879b7d721889cc6fbc6f878f4cd0f.zip
[project @ fpeters@0d.be-20071103211651-8vperiqd97t0987s]
support for list of xmlNode* (such as LibAuthnRequest/Extension) Original author: Frederic Peters <fpeters@0d.be> Date: 2007-11-03 22:16:51.610000+01:00
-rw-r--r--bindings/lang_python.py26
-rw-r--r--bindings/lang_python_wrapper_top.c17
2 files changed, 41 insertions, 2 deletions
diff --git a/bindings/lang_python.py b/bindings/lang_python.py
index 5e4dc4ae..a7dda28f 100644
--- a/bindings/lang_python.py
+++ b/bindings/lang_python.py
@@ -249,7 +249,7 @@ import lasso
print >> fd, ' t = _lasso.%s_%s_get(self._cptr)' % (
klassname, mname)
print >> fd, ' return cptrToPy(t)'
- elif m[0] == 'GList*' and options.get('elem_type') != 'char*':
+ elif m[0] == 'GList*' and options.get('elem_type') not in ('char*', 'xmlNode*'):
print >> fd, ' l = _lasso.%s_%s_get(self._cptr)' % (
klassname, mname)
print >> fd, ' if not l: return l'
@@ -271,7 +271,7 @@ import lasso
print >> fd, ' def set_%s(self, value):' % mname
if self.is_pygobject(m[0]):
print >> fd, ' value = value._cptr'
- elif m[0] == 'GList*' and options.get('elem_type') != 'char*':
+ elif m[0] == 'GList*' and options.get('elem_type') not in ('char*', 'xmlNode*'):
print >> fd, ' value = tuple([x._cptr for x in value])'
print >> fd, ' _lasso.%s_%s_set(self._cptr, value)' % (
klassname, mname)
@@ -562,6 +562,22 @@ register_constants(PyObject *d)
PyObject *pystr = PyTuple_GET_ITEM(cvt_value, i);
this->%(v)s = g_list_append(this->%(v)s, g_strdup(PyString_AsString(pystr)));
}''' % {'v': m[1]}
+ elif elem_type == 'xmlNode*':
+ # each item is a xmlNode*
+ print >> fd, '''\
+ if (this->%(v)s) {
+ /* free existing list */
+ g_list_foreach(this->%(v)s, (GFunc)xmlFreeNode, NULL);
+ g_list_free(this->%(v)s);
+ }
+ this->%(v)s = NULL;
+ /* create new list */
+ l = PyTuple_Size(cvt_value);
+ for (i=0; i<l; i++) {
+ xmlNode *item_node = get_xml_node_from_pystring(PyTuple_GET_ITEM(cvt_value, i));
+ this->%(v)s = g_list_append(this->%(v)s, item_node);
+ }''' % {'v': m[1]}
+ pass
else:
# assumes type is GObject
print >> fd, '''\
@@ -638,6 +654,12 @@ register_constants(PyObject *d)
PyTuple_SetItem(return_pyvalue, i, PyString_FromString(item->data));
item = g_list_next(item);
}'''
+ elif elem_type == 'xmlNode*':
+ print >> fd, '''\
+ for (i = 0; item; i++) {
+ PyTuple_SetItem(return_pyvalue, i, get_pystring_from_xml_node(item->data));
+ item = g_list_next(item);
+ }'''
else:
# assume GObject*
print >> fd, '''\
diff --git a/bindings/lang_python_wrapper_top.c b/bindings/lang_python_wrapper_top.c
index a80bbde3..1e9c682f 100644
--- a/bindings/lang_python_wrapper_top.c
+++ b/bindings/lang_python_wrapper_top.c
@@ -7,6 +7,7 @@ GQuark lasso_wrapper_key;
PyMODINIT_FUNC init_lasso(void);
static PyObject* get_pystring_from_xml_node(xmlNode *xmlnode);
+static xmlNode* get_xml_node_from_pystring(PyObject *string);
static PyObject* get_dict_from_hashtable_of_strings(GHashTable *value);
static PyObject* get_dict_from_hashtable_of_objects(GHashTable *value);
static PyObject* PyGObjectPtr_New(GObject *obj);
@@ -136,6 +137,22 @@ get_pystring_from_xml_node(xmlNode *xmlnode)
return pystring;
}
+static xmlNode*
+get_xml_node_from_pystring(PyObject *string) {
+ xmlDoc *doc;
+ xmlNode *node;
+
+ doc = xmlReadDoc((xmlChar*)PyString_AsString(string), NULL, NULL, XML_PARSE_NONET);
+ node = xmlDocGetRootElement(doc);
+ if (node != NULL) {
+ node = xmlCopyNode(node, 1);
+ }
+ xmlFreeDoc(doc);
+
+ return node;
+}
+
+
/* wrapper around GObject */
typedef struct {