cleanup the output buffer support to at least get the basic to work fixes
* python/generator.py python/libxml.c python/libxml_wrap.h:
cleanup the output buffer support to at least get the basic
to work
* python/tests/outbuf.py python/tests/serialize.py: fixes and
cleanup.
* include/libxml/xmlwriter.h: cleanup
Daniel
diff --git a/python/generator.py b/python/generator.py
index 55bdd0b..3896177 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -321,6 +321,10 @@
return 1
if name == "xmlTextReaderValue":
return 1
+ if name == "xmlOutputBufferClose": # handled by by the superclass
+ return 1
+ if name == "xmlOutputBufferFlush": # handled by by the superclass
+ return 1
return 0
def print_function_wrapper(name, output, export, include):
@@ -996,7 +1000,7 @@
rlist = reference_keepers[classname]
for ref in rlist:
classes.write(" self.%s = None\n" % ref[1])
- classes.write(" self._o = None\n")
+ classes.write(" self._o = _obj\n")
classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
classes_ancestor[classname]))
if classes_ancestor[classname] == "xmlCore" or \
diff --git a/python/libxml.c b/python/libxml.c
index bf4c652..dd66d86 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -269,7 +269,7 @@
xmlPythonFileWrite (void * context, const char * buffer, int len) {
PyObject *file;
PyObject *string;
- PyObject *ret;
+ PyObject *ret = NULL;
int written = -1;
#ifdef DEBUG_FILES
@@ -279,7 +279,13 @@
if (file == NULL) return(-1);
string = PyString_FromStringAndSize(buffer, len);
if (string == NULL) return(-1);
- ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)", string);
+ if (PyObject_HasAttrString(file, (char *) "io_write")) {
+ ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)",
+ string);
+ } else if (PyObject_HasAttrString(file, (char *) "write")) {
+ ret = PyEval_CallMethod(file, (char *) "write", (char *) "(O)",
+ string);
+ }
Py_DECREF(string);
if (ret == NULL) {
printf("xmlPythonFileWrite: result is NULL\n");
@@ -305,14 +311,18 @@
*/
static int
xmlPythonFileClose (void * context) {
- PyObject *file, *ret;
+ PyObject *file, *ret = NULL;
#ifdef DEBUG_FILES
printf("xmlPythonFileClose\n");
#endif
file = (PyObject *) context;
if (file == NULL) return(-1);
- ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()");
+ if (PyObject_HasAttrString(file, (char *) "io_close")) {
+ ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()");
+ } else if (PyObject_HasAttrString(file, (char *) "flush")) {
+ ret = PyEval_CallMethod(file, (char *) "flush", (char *) "()");
+ }
if (ret != NULL) {
Py_DECREF(ret);
}
@@ -369,6 +379,79 @@
py_retval = libxml_xmlOutputBufferPtrWrap(buffer);
return(py_retval);
}
+
+/**
+ * libxml_outputBufferGetPythonFile:
+ * @buffer: the I/O buffer
+ *
+ * read the Python I/O from the CObject
+ *
+ * Returns the new parser output or NULL
+ */
+static PyObject *
+libxml_outputBufferGetPythonFile(ATTRIBUTE_UNUSED PyObject *self,
+ PyObject *args) {
+ PyObject *buffer;
+ PyObject *file;
+ xmlOutputBufferPtr obj;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:outputBufferGetPythonFile",
+ &buffer))
+ return(NULL);
+
+ obj = PyoutputBuffer_Get(buffer);
+ if (obj == NULL) {
+ fprintf(stderr,
+ "outputBufferGetPythonFile: obj == NULL\n");
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+ if (obj->closecallback != xmlPythonFileClose) {
+ fprintf(stderr,
+ "outputBufferGetPythonFile: not a python file wrapper\n");
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+ file = (PyObject *) obj->context;
+ if (file == NULL) {
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+ Py_INCREF(file);
+ return(file);
+}
+
+PyObject *
+libxml_xmlOutputBufferClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ int c_retval;
+ xmlOutputBufferPtr out;
+ PyObject *pyobj_out;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferClose", &pyobj_out))
+ return(NULL);
+ out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out);
+
+ c_retval = xmlOutputBufferClose(out);
+ py_retval = libxml_intWrap((int) c_retval);
+ return(py_retval);
+}
+
+PyObject *
+libxml_xmlOutputBufferFlush(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ int c_retval;
+ xmlOutputBufferPtr out;
+ PyObject *pyobj_out;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferFlush", &pyobj_out))
+ return(NULL);
+ out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out);
+
+ c_retval = xmlOutputBufferFlush(out);
+ py_retval = libxml_intWrap((int) c_retval);
+ return(py_retval);
+}
#endif /* LIBXML_OUTPUT_ENABLED */
@@ -2793,6 +2876,9 @@
{(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL},
{(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL},
{(char *) "outputBufferCreate", libxml_xmlCreateOutputBuffer, METH_VARARGS, NULL},
+ {(char *) "outputBufferGetPythonFile", libxml_outputBufferGetPythonFile, METH_VARARGS, NULL},
+ {(char *) "xmlOutputBufferClose", libxml_xmlOutputBufferClose, METH_VARARGS, NULL},
+ { (char *)"xmlOutputBufferFlush", libxml_xmlOutputBufferFlush, METH_VARARGS, NULL },
#endif /* LIBXML_OUTPUT_ENABLED */
{(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL},
{(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL},
diff --git a/python/libxml2class.txt b/python/libxml2class.txt
index 48b8053..271dbeb 100644
--- a/python/libxml2class.txt
+++ b/python/libxml2class.txt
@@ -1013,8 +1013,6 @@
saveFormatFileTo()
# functions from module xmlIO
- close()
- flush()
write()
writeString()
Class xmlTextReaderLocator()
diff --git a/python/libxml_wrap.h b/python/libxml_wrap.h
index 260e6b4..064f8a8 100644
--- a/python/libxml_wrap.h
+++ b/python/libxml_wrap.h
@@ -113,7 +113,7 @@
} PyoutputBuffer_Object;
#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
- (((PyURI_Object *)(v))->obj))
+ (((PyoutputBuffer_Object *)(v))->obj))
typedef struct {
PyObject_HEAD
@@ -121,7 +121,7 @@
} PyinputBuffer_Object;
#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
- (((PyURI_Object *)(v))->obj))
+ (((PyinputBuffer_Object *)(v))->obj))
typedef struct {
PyObject_HEAD
diff --git a/python/tests/outbuf.py b/python/tests/outbuf.py
index ba8b25e..4213159 100755
--- a/python/tests/outbuf.py
+++ b/python/tests/outbuf.py
@@ -3,8 +3,8 @@
import libxml2
import StringIO
-print "Skipped"
-sys.exit(1)
+#print "Skipped"
+#sys.exit(1)
# Memory debug specific
libxml2.debugMemory(1)
@@ -15,12 +15,12 @@
buf.write(3, "foo")
buf.writeString("bar")
buf.close()
-del buf
if f.getvalue() != "foobar":
print "Failed to save to StringIO"
sys.exit(1)
+del buf
del f
# Memory debug specific
diff --git a/python/tests/serialize.py b/python/tests/serialize.py
index d7226c4..5b969a9 100755
--- a/python/tests/serialize.py
+++ b/python/tests/serialize.py
@@ -69,19 +69,19 @@
#
doc = libxml2.htmlParseDoc("""<html><head><title>Hello</title><body><p>hello</body></html>""", None)
str = doc.serialize()
-if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title>Hello</title></head><body><p>hello</p></body></html>
""":
print "error serializing HTML document 1"
sys.exit(1)
str = doc.serialize("ISO-8859-1")
-if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Hello</title></head><body><p>hello</p></body></html>
""":
print "error serializing HTML document 2"
sys.exit(1)
str = doc.serialize(format=1)
-if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
@@ -93,7 +93,7 @@
print "error serializing HTML document 3"
sys.exit(1)
str = doc.serialize("iso-8859-1", 1)
-if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">