couple of bug fixes Daniel

* python/libxml.c: couple of bug fixes
Daniel
diff --git a/ChangeLog b/ChangeLog
index d8376d7..56b9799 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Feb 12 14:45:32 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+	* python/libxml.c: couple of bug fixes
+
 Mon Feb 11 19:41:29 CET 2002 Daniel Veillard <daniel@veillard.com>
 
 	* python/*.py: removed tabs and used spaces.
diff --git a/python/libxml.c b/python/libxml.c
index 2a700b7..1a21279 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -20,6 +20,7 @@
 #include "libxml2-py.h"
 
 /* #define DEBUG */
+/* #define DEBUG_SAX */
 /* #define DEBUG_XPATH */
 /* #define DEBUG_ERROR */
 /* #define DEBUG_MEMORY */
@@ -127,6 +128,9 @@
     PyObject *result;
     int type = 0;
 
+#ifdef DEBUG_SAX
+    printf("pythonStartElement(%s) called\n", name);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "startElement"))
         type = 1;
@@ -140,6 +144,8 @@
         if ((attrs == NULL) && (type == 1)) {
             Py_XINCREF(Py_None);
             dict = Py_None;
+	} else if (attrs == NULL) {
+	    dict = PyDict_New();
         } else {
             dict = PyDict_New();
             for (i = 0; attrs[i] != NULL; i++) {
@@ -174,6 +180,9 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonStartDocument() called\n");
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "startDocument")) {
         result = PyObject_CallMethod(handler, "startDocument", NULL);
@@ -189,6 +198,9 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonEndDocument() called\n");
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "endDocument")) {
         result = PyObject_CallMethod(handler, "endDocument", NULL);
@@ -208,12 +220,20 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonEndElement(%s) called\n", name);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "endElement")) {
         result = PyObject_CallMethod(handler, "endElement", "s", name);
 	if (PyErr_Occurred())
 	    PyErr_Print();
         Py_XDECREF(result);
+    } else if (PyObject_HasAttrString(handler, "end")) {
+        result = PyObject_CallMethod(handler, "end", "s", name);
+	if (PyErr_Occurred())
+	    PyErr_Print();
+        Py_XDECREF(result);
     }
 }
 
@@ -223,6 +243,9 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonReference(%s) called\n", name);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "reference")) {
         result = PyObject_CallMethod(handler, "reference", "s", name);
@@ -239,6 +262,9 @@
     PyObject *result;
     int type = 0;
 
+#ifdef DEBUG_SAX
+    printf("pythonCharacters(%s, %d) called\n", ch, len);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "characters"))
 	type = 1;
@@ -262,6 +288,9 @@
     PyObject *result;
     int type = 0;
 
+#ifdef DEBUG_SAX
+    printf("pythonIgnorableWhitespace(%s, %d) called\n", ch, len);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "ignorableWhitespace"))
         type = 1;
@@ -285,6 +314,9 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonProcessingInstruction(%s, %s) called\n", target, data);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "processingInstruction")) {
         result =
@@ -300,6 +332,9 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonComment(%s) called\n", value);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "comment")) {
         result = PyObject_CallMethod(handler, "comment", "s", value);
@@ -317,6 +352,9 @@
     va_list args;
     char buf[1024];
 
+#ifdef DEBUG_SAX
+    printf("pythonWarning(%s) called\n", msg);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "warning")) {
         va_start(args, msg);
@@ -338,6 +376,9 @@
     va_list args;
     char buf[1024];
 
+#ifdef DEBUG_SAX
+    printf("pythonError(%s) called\n", msg);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "error")) {
         va_start(args, msg);
@@ -359,6 +400,9 @@
     va_list args;
     char buf[1024];
 
+#ifdef DEBUG_SAX
+    printf("pythonFatalError(%s) called\n", msg);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "fatalError")) {
         va_start(args, msg);
@@ -379,6 +423,9 @@
     PyObject *result;
     int type = 0;
 
+#ifdef DEBUG_SAX
+    printf("pythonCdataBlock(%s, %d) called\n", ch, len);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "cdataBlock"))
 	type = 1;
@@ -403,6 +450,10 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonExternalSubset(%s, %s, %s) called\n",
+	    name, externalID, systemID);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "externalSubset")) {
         result =
@@ -544,6 +595,10 @@
     PyObject *handler;
     PyObject *result;
 
+#ifdef DEBUG_SAX
+    printf("pythonInternalSubset(%s, %s, %s) called\n",
+	    name, ExternalID, SystemID);
+#endif
     handler = (PyObject *) user_data;
     if (PyObject_HasAttrString(handler, "internalSubset")) {
         result = PyObject_CallMethod(handler, "internalSubset",
diff --git a/python/libxml.py b/python/libxml.py
index 87139e8..da736be 100644
--- a/python/libxml.py
+++ b/python/libxml.py
@@ -147,6 +147,7 @@
 def registerXPathFunction(ctxt, name, ns_uri, f):
     ret = libxml2mod.xmlRegisterXPathFunction(ctxt, name, ns_uri, f)
 
+    
 #
 # Everything below this point is automatically generated
 #