diff options
| author | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:04:16 +0000 |
|---|---|---|
| committer | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:04:16 +0000 |
| commit | 08ce85ccd01a5c7431e4e69d8db7ae26f9b935c4 (patch) | |
| tree | 6c9f4745794bcd2acedd59144a35e8e3ebfc7b0a | |
| parent | 60bc045cc318300c2bcb5b2e883ff840a7305260 (diff) | |
| download | lasso-08ce85ccd01a5c7431e4e69d8db7ae26f9b935c4.tar.gz lasso-08ce85ccd01a5c7431e4e69d8db7ae26f9b935c4.tar.xz lasso-08ce85ccd01a5c7431e4e69d8db7ae26f9b935c4.zip | |
[project @ fpeters@0d.be-20071101160226-jj7ou71gblw0uymq]
added support for converting xmlNode* as return type to PyString
Original author: Frederic Peters <fpeters@0d.be>
Date: 2007-11-01 17:02:26.261000+01:00
| -rw-r--r-- | bindings/lang_python.py | 15 | ||||
| -rw-r--r-- | bindings/lang_python_wrapper_top.c | 33 |
2 files changed, 47 insertions, 1 deletions
diff --git a/bindings/lang_python.py b/bindings/lang_python.py index b9691398..5144bc5c 100644 --- a/bindings/lang_python.py +++ b/bindings/lang_python.py @@ -572,8 +572,21 @@ register_constants(PyObject *d) print >> fd, '''\ return return_pyvalue; }''' + elif vtype == 'xmlNode*': + # convert xmlNode* to strings + print >> fd, ' if (return_value) {' + print >> fd, ' return_pyvalue = get_pystring_from_xml_node(return_value);' + #print >> fd, ' Py_INCREF(return_pyvalue);' + print >> fd, ' return return_pyvalue;' + print >> fd, ' } else {' + print >> fd, ' Py_INCREF(Py_None);' + print >> fd, ' return Py_None;' + print >> fd, ' }' + elif vtype in ('GList*',): + + pass else: - # return a tuple with (object type, cPtr) + # return a PyGObjectPtr (wrapper around GObject) print >> fd, '''\ if (return_value) { return_pyvalue = PyGObjectPtr_New(G_OBJECT(return_value)); 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 |
