mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-08-05 19:35:54 +03:00
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
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,8 +1,16 @@
|
|||||||
|
Thu Dec 4 13:29:19 CET 2003 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* 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
|
||||||
|
|
||||||
Wed Dec 3 21:38:56 MST 2003 John Fleck <jfleck@inkstain.net>
|
Wed Dec 3 21:38:56 MST 2003 John Fleck <jfleck@inkstain.net>
|
||||||
|
|
||||||
* include/libxml/xmlversion.h.in
|
* include/libxml/xmlversion.h.in
|
||||||
* doc/*
|
* doc/*: add WITH_TRIO comment so it shows up in the docs, rebuild
|
||||||
add WITH_TRIO comment so it shows up in the docs, rebuild
|
|
||||||
docs
|
docs
|
||||||
|
|
||||||
Wed Dec 3 13:10:08 CET 2003 Daniel Veillard <daniel@veillard.com>
|
Wed Dec 3 13:10:08 CET 2003 Daniel Veillard <daniel@veillard.com>
|
||||||
|
@@ -321,6 +321,10 @@ def skip_function(name):
|
|||||||
return 1
|
return 1
|
||||||
if name == "xmlTextReaderValue":
|
if name == "xmlTextReaderValue":
|
||||||
return 1
|
return 1
|
||||||
|
if name == "xmlOutputBufferClose": # handled by by the superclass
|
||||||
|
return 1
|
||||||
|
if name == "xmlOutputBufferFlush": # handled by by the superclass
|
||||||
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def print_function_wrapper(name, output, export, include):
|
def print_function_wrapper(name, output, export, include):
|
||||||
@@ -996,7 +1000,7 @@ def buildWrappers():
|
|||||||
rlist = reference_keepers[classname]
|
rlist = reference_keepers[classname]
|
||||||
for ref in rlist:
|
for ref in rlist:
|
||||||
classes.write(" self.%s = None\n" % ref[1])
|
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.write(" %s.__init__(self, _obj=_obj)\n\n" % (
|
||||||
classes_ancestor[classname]))
|
classes_ancestor[classname]))
|
||||||
if classes_ancestor[classname] == "xmlCore" or \
|
if classes_ancestor[classname] == "xmlCore" or \
|
||||||
|
@@ -269,7 +269,7 @@ static int
|
|||||||
xmlPythonFileWrite (void * context, const char * buffer, int len) {
|
xmlPythonFileWrite (void * context, const char * buffer, int len) {
|
||||||
PyObject *file;
|
PyObject *file;
|
||||||
PyObject *string;
|
PyObject *string;
|
||||||
PyObject *ret;
|
PyObject *ret = NULL;
|
||||||
int written = -1;
|
int written = -1;
|
||||||
|
|
||||||
#ifdef DEBUG_FILES
|
#ifdef DEBUG_FILES
|
||||||
@@ -279,7 +279,13 @@ xmlPythonFileWrite (void * context, const char * buffer, int len) {
|
|||||||
if (file == NULL) return(-1);
|
if (file == NULL) return(-1);
|
||||||
string = PyString_FromStringAndSize(buffer, len);
|
string = PyString_FromStringAndSize(buffer, len);
|
||||||
if (string == NULL) return(-1);
|
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);
|
Py_DECREF(string);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
printf("xmlPythonFileWrite: result is NULL\n");
|
printf("xmlPythonFileWrite: result is NULL\n");
|
||||||
@@ -305,14 +311,18 @@ xmlPythonFileWrite (void * context, const char * buffer, int len) {
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlPythonFileClose (void * context) {
|
xmlPythonFileClose (void * context) {
|
||||||
PyObject *file, *ret;
|
PyObject *file, *ret = NULL;
|
||||||
|
|
||||||
#ifdef DEBUG_FILES
|
#ifdef DEBUG_FILES
|
||||||
printf("xmlPythonFileClose\n");
|
printf("xmlPythonFileClose\n");
|
||||||
#endif
|
#endif
|
||||||
file = (PyObject *) context;
|
file = (PyObject *) context;
|
||||||
if (file == NULL) return(-1);
|
if (file == NULL) return(-1);
|
||||||
|
if (PyObject_HasAttrString(file, (char *) "io_close")) {
|
||||||
ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()");
|
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) {
|
if (ret != NULL) {
|
||||||
Py_DECREF(ret);
|
Py_DECREF(ret);
|
||||||
}
|
}
|
||||||
@@ -369,6 +379,79 @@ libxml_xmlCreateOutputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
|
|||||||
py_retval = libxml_xmlOutputBufferPtrWrap(buffer);
|
py_retval = libxml_xmlOutputBufferPtrWrap(buffer);
|
||||||
return(py_retval);
|
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 */
|
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||||
|
|
||||||
|
|
||||||
@@ -2793,6 +2876,9 @@ static PyMethodDef libxmlMethods[] = {
|
|||||||
{(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL},
|
{(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL},
|
||||||
{(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL},
|
{(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL},
|
||||||
{(char *) "outputBufferCreate", libxml_xmlCreateOutputBuffer, 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 */
|
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||||
{(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL},
|
{(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL},
|
||||||
{(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL},
|
{(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL},
|
||||||
|
@@ -1013,8 +1013,6 @@ Class outputBuffer(ioWriteWrapper)
|
|||||||
saveFormatFileTo()
|
saveFormatFileTo()
|
||||||
|
|
||||||
# functions from module xmlIO
|
# functions from module xmlIO
|
||||||
close()
|
|
||||||
flush()
|
|
||||||
write()
|
write()
|
||||||
writeString()
|
writeString()
|
||||||
Class xmlTextReaderLocator()
|
Class xmlTextReaderLocator()
|
||||||
|
@@ -113,7 +113,7 @@ typedef struct {
|
|||||||
} PyoutputBuffer_Object;
|
} PyoutputBuffer_Object;
|
||||||
|
|
||||||
#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
|
#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
|
||||||
(((PyURI_Object *)(v))->obj))
|
(((PyoutputBuffer_Object *)(v))->obj))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
@@ -121,7 +121,7 @@ typedef struct {
|
|||||||
} PyinputBuffer_Object;
|
} PyinputBuffer_Object;
|
||||||
|
|
||||||
#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
|
#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
|
||||||
(((PyURI_Object *)(v))->obj))
|
(((PyinputBuffer_Object *)(v))->obj))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@@ -3,8 +3,8 @@ import sys
|
|||||||
import libxml2
|
import libxml2
|
||||||
import StringIO
|
import StringIO
|
||||||
|
|
||||||
print "Skipped"
|
#print "Skipped"
|
||||||
sys.exit(1)
|
#sys.exit(1)
|
||||||
|
|
||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxml2.debugMemory(1)
|
libxml2.debugMemory(1)
|
||||||
@@ -15,12 +15,12 @@ buf = libxml2.createOutputBuffer(f, "ISO-8859-1")
|
|||||||
buf.write(3, "foo")
|
buf.write(3, "foo")
|
||||||
buf.writeString("bar")
|
buf.writeString("bar")
|
||||||
buf.close()
|
buf.close()
|
||||||
del buf
|
|
||||||
|
|
||||||
if f.getvalue() != "foobar":
|
if f.getvalue() != "foobar":
|
||||||
print "Failed to save to StringIO"
|
print "Failed to save to StringIO"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
del buf
|
||||||
del f
|
del f
|
||||||
|
|
||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
|
@@ -69,19 +69,19 @@ doc.freeDoc()
|
|||||||
#
|
#
|
||||||
doc = libxml2.htmlParseDoc("""<html><head><title>Hello</title><body><p>hello</body></html>""", None)
|
doc = libxml2.htmlParseDoc("""<html><head><title>Hello</title><body><p>hello</body></html>""", None)
|
||||||
str = doc.serialize()
|
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>
|
<html><head><title>Hello</title></head><body><p>hello</p></body></html>
|
||||||
""":
|
""":
|
||||||
print "error serializing HTML document 1"
|
print "error serializing HTML document 1"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
str = doc.serialize("ISO-8859-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>
|
<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"
|
print "error serializing HTML document 2"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
str = doc.serialize(format=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>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
@@ -93,7 +93,7 @@ if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http
|
|||||||
print "error serializing HTML document 3"
|
print "error serializing HTML document 3"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
str = doc.serialize("iso-8859-1", 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>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||||
|
Reference in New Issue
Block a user