[xml] [patch] A python binding for xmlCatalogAddLocal



Daniel,

The attached patch implements an addLocalCatalog() method for the python parserCtxt class. It took me a while to actually get into the code enough to do this, but as you said[1], it wasn't especially long or difficult. It's slightly less general than xmlCatalogAddLocal() since it only operates on a parserCtxt, but that let me avoid the issue with passing around unknown void* pointers.

This is my first foray into the python bindings, so I'd appreciate any feedback. It seems to work, but I might have missed something (eg. do I need to free the URL string?)

Would it be worth wrapping xmlCatalogLocalResolve() and xmlCatalogLocalResolveURI() as well?

Thanks,
-- Brent

[1] http://mail.gnome.org/archives/xml/2002-October/msg00103.html

-------------------------------------------------------------------------

"The programmer, like the poet, works only slightly removed from pure
 thought-stuff.  He builds his castles in the air, from air, creating
 by exertion of the imagination.  Few media of creation are so
 flexible, so easy to polish and rework, so readily capable of
 realizing grand conceptual structures."
                        -- Frederick Brooks, Jr., The Mythical Man Month
Index: libxml.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/python/libxml.c,v
retrieving revision 1.41
diff -u -r1.41 libxml.c
--- libxml.c    26 Mar 2003 00:38:10 -0000      1.41
+++ libxml.c    22 Apr 2003 17:08:58 -0000
@@ -2545,6 +2545,39 @@
     return (py_retval);
 }
 
+
+/************************************************************************
+ *                                                                     *
+ *                     Local Catalog stuff                             *
+ *                                                                     *
+ ************************************************************************/
+PyObject *
+libxml_addLocalCatalog(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
+{
+    xmlChar *URL;
+    xmlParserCtxtPtr ctxt;
+    PyObject *pyobj_ctxt;
+
+    if (!PyArg_ParseTuple(args, (char *)"Os:addLocalCatalog", &pyobj_ctxt, &URL))
+        return(NULL);
+
+    ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
+
+    if (URL != NULL) {
+       ctxt->catalogs = xmlCatalogAddLocal(ctxt->catalogs, URL);
+    }
+
+#ifdef DEBUG
+    printf("LocalCatalog: %s\n", URL);
+#endif
+
+    Py_INCREF(Py_None);
+    return (Py_None);
+}
+
+
+
+
 /************************************************************************
  *                                                                     *
  *                     The registration stuff                          *
@@ -2574,6 +2607,7 @@
     {(char *)"xmlTextReaderSetErrorHandler", libxml_xmlTextReaderSetErrorHandler, METH_VARARGS, NULL },
     {(char *)"xmlTextReaderGetErrorHandler", libxml_xmlTextReaderGetErrorHandler, METH_VARARGS, NULL },
     {(char *)"xmlFreeTextReader", libxml_xmlFreeTextReader, METH_VARARGS, NULL },
+    {(char *)"addLocalCatalog", libxml_addLocalCatalog, METH_VARARGS, NULL },
     {NULL, NULL, 0, NULL}
 };
 
Index: libxml.py
===================================================================
RCS file: /cvs/gnome/gnome-xml/python/libxml.py,v
retrieving revision 1.23
diff -u -r1.23 libxml.py
--- libxml.py   20 Jan 2003 21:26:33 -0000      1.23
+++ libxml.py   22 Apr 2003 17:08:59 -0000
@@ -511,6 +511,11 @@
            or (None,None)."""
         return libxml2mod.xmlParserCtxtGetErrorHandler(self._o)
 
+    def addLocalCatalog(self, uri):
+        """Register a local catalog with the parser"""
+        return libxml2mod.addLocalCatalog(self._o, uri)
+    
+
 def _xmlTextReaderErrorFunc((f,arg),msg,severity,locator):
     """Intermediate callback to wrap the locator"""
     return f(arg,msg,severity,xmlTextReaderLocator(locator))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]