From 08ce85ccd01a5c7431e4e69d8db7ae26f9b935c4 Mon Sep 17 00:00:00 2001 From: Frederic Peters Date: Tue, 29 Apr 2008 12:04:16 +0000 Subject: [project @ fpeters@0d.be-20071101160226-jj7ou71gblw0uymq] added support for converting xmlNode* as return type to PyString Original author: Frederic Peters Date: 2007-11-01 17:02:26.261000+01:00 --- bindings/lang_python_wrapper_top.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'bindings/lang_python_wrapper_top.c') diff --git a/bindings/lang_python_wrapper_top.c b/bindings/lang_python_wrapper_top.c index 48ecc927..bcf670ec 100644 --- a/bindings/lang_python_wrapper_top.c +++ b/bindings/lang_python_wrapper_top.c @@ -5,6 +5,39 @@ GQuark lasso_wrapper_key; PyMODINIT_FUNC init_lasso(void); +static PyObject* get_pystring_from_xml_node(xmlNode *xmlnode); + +/* utility functions */ + +static PyObject* +get_pystring_from_xml_node(xmlNode *xmlnode) +{ + xmlOutputBufferPtr buf; + char *xmlString; + PyObject *pystring = NULL; + + if (xmlnode == NULL) { + return NULL; + } + + buf = xmlAllocOutputBuffer(NULL); + if (buf == NULL) { + xmlString = NULL; + } else { + xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); + xmlOutputBufferFlush(buf); + if (buf->conv == NULL) { + pystring = PyString_FromString((char*)buf->buffer->content); + } else { + pystring = PyString_FromString((char*)buf->conv->content); + } + xmlOutputBufferClose(buf); + } + + return pystring; +} + +/* wrapper around GObject */ typedef struct { PyObject_HEAD -- cgit