Commit 6cbd6c07 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

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
parent 7c5f5868
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>
 
* include/libxml/xmlversion.h.in
* doc/*
add WITH_TRIO comment so it shows up in the docs, rebuild
docs
* doc/*: add WITH_TRIO comment so it shows up in the docs, rebuild
docs
 
Wed Dec 3 13:10:08 CET 2003 Daniel Veillard <daniel@veillard.com>
 
......
......@@ -30,14 +30,14 @@ XMLPUBFUN xmlTextWriterPtr XMLCALL
xmlNewTextWriterFilename(const char *uri, int compression);
XMLPUBFUN xmlTextWriterPtr XMLCALL
xmlNewTextWriterMemory(xmlBufferPtr buf, int compression);
XMLPUBFUN xmlTextWriterPtr XMLCALL
XMLPUBFUN xmlTextWriterPtr XMLCALL
xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt, int compression);
XMLPUBFUN xmlTextWriterPtr XMLCALL
XMLPUBFUN xmlTextWriterPtr XMLCALL
xmlNewTextWriterDoc(xmlDocPtr * doc, int compression);
XMLPUBFUN xmlTextWriterPtr XMLCALL
XMLPUBFUN xmlTextWriterPtr XMLCALL
xmlNewTextWriterTree(xmlDocPtr doc,
xmlNodePtr node, int compression);
XMLPUBFUN void XMLCALL xmlFreeTextWriter(xmlTextWriterPtr writer);
XMLPUBFUN void XMLCALL xmlFreeTextWriter(xmlTextWriterPtr writer);
/*
* Functions
......@@ -208,7 +208,7 @@ XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlTextWriterStartPI (xmlTextWriterPtr writer,
const xmlChar * target);
XMLPUBFUN int XMLCALL xmlTextWriterEndPI(xmlTextWriterPtr writer);
XMLPUBFUN int XMLCALL xmlTextWriterEndPI(xmlTextWriterPtr writer);
/*
* PI conveniency functions
......@@ -230,8 +230,8 @@ XMLPUBFUN int XMLCALL
/*
* CDATA
*/
XMLPUBFUN int XMLCALL xmlTextWriterStartCDATA(xmlTextWriterPtr writer);
XMLPUBFUN int XMLCALL xmlTextWriterEndCDATA(xmlTextWriterPtr writer);
XMLPUBFUN int XMLCALL xmlTextWriterStartCDATA(xmlTextWriterPtr writer);
XMLPUBFUN int XMLCALL xmlTextWriterEndCDATA(xmlTextWriterPtr writer);
/*
* CDATA conveniency functions
......@@ -254,7 +254,7 @@ XMLPUBFUN int XMLCALL
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid);
XMLPUBFUN int XMLCALL xmlTextWriterEndDTD(xmlTextWriterPtr writer);
XMLPUBFUN int XMLCALL xmlTextWriterEndDTD(xmlTextWriterPtr writer);
/*
* DTD conveniency functions
......@@ -384,7 +384,7 @@ XMLPUBFUN int XMLCALL
/*
* misc
*/
XMLPUBFUN int XMLCALL xmlTextWriterFlush(xmlTextWriterPtr writer);
XMLPUBFUN int XMLCALL xmlTextWriterFlush(xmlTextWriterPtr writer);
#ifdef __cplusplus
}
......
......@@ -321,6 +321,10 @@ def skip_function(name):
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 @@ def buildWrappers():
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 \
......
......@@ -269,7 +269,7 @@ static int
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 @@ xmlPythonFileWrite (void * context, const char * buffer, int len) {
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 @@ xmlPythonFileWrite (void * context, const char * buffer, int len) {
*/
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 @@ libxml_xmlCreateOutputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
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 @@ static PyMethodDef libxmlMethods[] = {
{(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},
......
......@@ -1013,8 +1013,6 @@ Class outputBuffer(ioWriteWrapper)
saveFormatFileTo()
# functions from module xmlIO
close()
flush()
write()
writeString()
Class xmlTextReaderLocator()
......
......@@ -113,7 +113,7 @@ typedef struct {
} 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 @@ typedef struct {
} PyinputBuffer_Object;
#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
(((PyURI_Object *)(v))->obj))
(((PyinputBuffer_Object *)(v))->obj))
typedef struct {
PyObject_HEAD
......
......@@ -3,8 +3,8 @@ import sys
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 = libxml2.createOutputBuffer(f, "ISO-8859-1")
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
......
......@@ -69,19 +69,19 @@ doc.freeDoc()
#
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 @@ if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http
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">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment