diff options
-rw-r--r-- | unit-tests/Makefile | 33 | ||||
-rw-r--r-- | unit-tests/POCDemo.py | 12 | ||||
-rw-r--r-- | unit-tests/demo.c | 99 | ||||
-rw-r--r-- | unit-tests/demo.h | 14 | ||||
-rw-r--r-- | unit-tests/dmixml.c | 248 | ||||
-rw-r--r-- | unit-tests/dmixml.h | 43 | ||||
-rw-r--r-- | unit-tests/libxml2mod.so | bin | 0 -> 380000 bytes | |||
-rw-r--r-- | unit-tests/libxml_wrap.h | 249 | ||||
-rwxr-xr-x | unit-tests/unit (renamed from examples/test.py) | 20 |
9 files changed, 718 insertions, 0 deletions
diff --git a/unit-tests/Makefile b/unit-tests/Makefile new file mode 100644 index 0000000..24fbfa9 --- /dev/null +++ b/unit-tests/Makefile @@ -0,0 +1,33 @@ +## This one is important to get right ... +## We need to link in the libxml2mod.so file from here +PYLIBDIR := /usr/lib64/python2.5/site-packages +PYLIBDIR := /usr/lib/python-support/python-libxml2/python2.5 + +# Defaults, should be fine +CFLAGS=-I. $(shell xml2-config --cflags) -g -Wall $(shell python-config --cflags) + +LIBS=$(shell xml2-config --libs) -lxml2mod $(shell python-config --libs) +LIBDIR=-L $(PYLIBDIR) + +.SUFFIX=.c .o .so + +all : test + +demomodule.so : demo.o dmixml.o + @echo "Linking: $@" + @gcc -fPIC --shared -o $@ $^ $(LIBS) $(LIBDIR) + +.c.o : + @echo "Compiling $<" + @gcc -fPIC -c $< $(CFLAGS) + +test : demomodule.so + @echo "==========================================" + @echo " Running proof-of-concept code" + @echo "==========================================" + @echo "" + @python unit + +clean : + rm -f demomodule.so *.{py[oc],o} *~ + diff --git a/unit-tests/POCDemo.py b/unit-tests/POCDemo.py new file mode 100644 index 0000000..475a62b --- /dev/null +++ b/unit-tests/POCDemo.py @@ -0,0 +1,12 @@ +import libxml2 +import demomodule # This is our core module + +class POCDemo: + """Demo of a wrapper class to return proper python libxml2 objects""" + + def GetXMLdoc(self): + return libxml2.xmlDoc( _obj = demomodule.dump_doc() ) + + def GetXMLnode(self): + return libxml2.xmlNode( _obj = demomodule.dump_node() ) + diff --git a/unit-tests/demo.c b/unit-tests/demo.c new file mode 100644 index 0000000..265f3cb --- /dev/null +++ b/unit-tests/demo.c @@ -0,0 +1,99 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + */ + +#include "demo.h" + +xmlNode *gen_nodes(const char *entry ) { + xmlNode *c_xmlNode_root = NULL; + xmlNode *c_xmlNode_tag = NULL; + + // Prepare a root node + c_xmlNode_root = xmlNewNode(NULL, (xmlChar *) "dmixml_demo"); + assert( c_xmlNode_root != NULL ); + + dmixml_AddAttribute(c_xmlNode_root, "entrypoint", "%s", entry); + + // Populate XML + dmixml_AddTextChild(c_xmlNode_root, "Test", "Yes, just testing"); + + c_xmlNode_tag = dmixml_AddTextChild(c_xmlNode_root, "tag1", "Another test"); + dmixml_AddAttribute(c_xmlNode_tag, "TestTagID", "%i", 1); + + c_xmlNode_tag = c_xmlNode_root; + int i; + for(i = 0; i <= 3; ++i) { + c_xmlNode_tag = xmlNewChild(c_xmlNode_tag, NULL, (xmlChar *) "subtag", NULL); + dmixml_AddAttribute(c_xmlNode_tag, "SubLevel", "%i", i); + } + dmixml_AddTextContent(c_xmlNode_tag, "%s - Adding data to the tag at sublevel %i", "TEST", i-1); + + return c_xmlNode_root; +} + + + + +PyObject* demo_dump_doc() { + PyObject *py_xmlDoc = NULL; + xmlDoc *c_xmlDoc = NULL; + + // Create an XML document + c_xmlDoc = xmlNewDoc((xmlChar *) "1.0"); + assert( c_xmlDoc != NULL ); + + // Generate XML nodes and assign the root node to the document + xmlDocSetRootElement( c_xmlDoc, gen_nodes("demo_dump_doc") ); + + py_xmlDoc = libxml_xmlDocPtrWrap((xmlDocPtr) c_xmlDoc); + Py_INCREF(py_xmlDoc); + + return py_xmlDoc; +} + +PyObject* demo_dump_node() { + PyObject *py_xmlNode = NULL; + xmlNode *nodes = NULL; + + nodes = gen_nodes("demo_dump_node"); + py_xmlNode = libxml_xmlNodePtrWrap((xmlNodePtr) nodes); + Py_INCREF(py_xmlNode); + + return py_xmlNode; +} + + + +static PyMethodDef DemoMethods[] = { + { "dump_doc", demo_dump_doc, METH_NOARGS, (char *)"Return an XML document" }, + { "dump_node", demo_dump_node, METH_NOARGS, (char *)"Retuen an XML node" }, + { NULL, NULL, 0, NULL } +}; + +PyMODINIT_FUNC initdemomodule(void) { + PyObject *module = + Py_InitModule3((char *)"demomodule", DemoMethods, + "LibXML2 DMIDecode Proof-of-Concept Python Module"); + + PyObject *version = PyString_FromString("0.10"); + Py_INCREF(version); + PyModule_AddObject(module, "version", version); +} diff --git a/unit-tests/demo.h b/unit-tests/demo.h new file mode 100644 index 0000000..21a5468 --- /dev/null +++ b/unit-tests/demo.h @@ -0,0 +1,14 @@ +#include <Python.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include <libxml/tree.h> +#include "libxml_wrap.h" + +#include "dmixml.h" + +extern PyObject* demo_dump(void); +PyMODINIT_FUNC initdemomodule(void); +PyObject* demo_dump_doc(void); +PyObject* demo_dump_node(void); diff --git a/unit-tests/dmixml.c b/unit-tests/dmixml.c new file mode 100644 index 0000000..dbca0c3 --- /dev/null +++ b/unit-tests/dmixml.c @@ -0,0 +1,248 @@ +/* Simplified XML API for dmidecode + * + * Copyright 2009 David Sommerseth <davids@redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + */ + +#include <string.h> +#include <stdarg.h> +#include <assert.h> + +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlstring.h> + +// Internal function for dmixml_* functions ... builds up a variable xmlChar* string +xmlChar *dmixml_buildstr(size_t len, const char *fmt, va_list ap) { + xmlChar *ret = NULL, *xmlfmt = NULL; + xmlChar *ptr = NULL; + + ret = (xmlChar *) malloc(len+2); + assert( ret != NULL ); + memset(ret, 0, len+2); + + xmlfmt = xmlCharStrdup(fmt); + assert( xmlfmt != NULL ); + + xmlStrVPrintf(ret, len, xmlfmt, ap); + free(xmlfmt); + + // Right trim the string + ptr = ret + xmlStrlen(ret)-1; + while( (ptr >= ret) && (*ptr == ' ') ) { + *ptr = 0; + ptr--; + } + return ret; +} + + +// Adds an XML property/attribute to the given XML node +// +// xmldata_n = "<test/>"; +// dmixml_AddAttribute(xmldata_n, "value", "1234"); +// gives: xmldata_n = "<test value="1234/>" +// + +xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...) +{ + xmlChar *val_s = NULL, *atrname_s = NULL; + xmlAttr *res = NULL; + va_list ap; + + if( (node == NULL) || (atrname == NULL) || (fmt == NULL) ) { + return NULL; + } + + atrname_s = xmlCharStrdup(atrname); + assert( atrname_s != NULL ); + + va_start(ap, fmt); + val_s = dmixml_buildstr(2048, fmt, ap); + va_end(ap); + + res = xmlNewProp(node, atrname_s, + (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s)); + + free(atrname_s); + free(val_s); + + assert( res != NULL ); + return res; +} + + +// Adds a new XML tag to the current node with the given tag name and value. +// +// xmldata_n = "<test>"; +// dmixml_AddTextChild(xmldata_n, "sublevel1", "value"); +// gives: xmldata_n = "<test><sublevel1>value</sublevel1></test>" +// +xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...) +{ + xmlChar *val_s = NULL, *tagname_s = NULL; + xmlNode *res = NULL; + va_list ap; + + if( (node == NULL) || (tagname == NULL) || (fmt == NULL) ) { + return NULL; + } + + tagname_s = xmlCharStrdup(tagname); + assert( tagname_s != NULL ); + + va_start(ap, fmt); + val_s = dmixml_buildstr(2048, fmt, ap); + va_end(ap); + + // Do not add any contents if the string contents is "(null)" + res = xmlNewTextChild(node, NULL, tagname_s, + (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s)); + + free(tagname_s); + free(val_s); + + assert( res != NULL ); + return res; +} + +// Adds a text node child to the current XML node +// +// xmldata_n = "<testdata/>; +// dmixml_AddTextContent(xmldata_n, "some data value"); +// gives: xmldata_n = "<testdata>some data value</testdata>" +// +xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...) +{ + xmlChar *val_s = NULL; + xmlNode *res = NULL; + va_list ap; + + if( (node == NULL) || (fmt == NULL) ) { + return NULL; + } + + va_start(ap, fmt); + val_s = dmixml_buildstr(2048, fmt, ap); + va_end(ap); + + if( xmlStrcmp(val_s, (xmlChar *) "(null)") != 0 ) { + res = xmlAddChild(node, xmlNewText(val_s)); + } else { + res = node; + } + free(val_s); + + assert( res != NULL ); + return res; +} + + +char *dmixml_GetAttrValue(xmlNode *node, const char *key) { + xmlAttr *aptr = NULL; + xmlChar *key_s = NULL; + + if( node == NULL ) { + return NULL; + } + + key_s = xmlCharStrdup(key); + assert( key_s != NULL ); + + for( aptr = node->properties; aptr != NULL; aptr = aptr->next ) { + if( xmlStrcmp(aptr->name, key_s) == 0 ) { + free(key_s); key_s = NULL; + // FIXME: Should find better way how to return UTF-8 data + return (char *)(aptr->children != NULL ? aptr->children->content : NULL); + } + } + free(key_s); key_s = NULL; + return NULL; +} + +xmlNode *dmixml_FindNode(xmlNode *node, const char *key) { + xmlNode *ptr_n = NULL; + xmlChar *key_s = NULL; + + if( node->children == NULL ) { + return NULL; + } + + key_s = xmlCharStrdup(key); + assert( key_s != NULL ); + + for( ptr_n = node->children; ptr_n != NULL; ptr_n = ptr_n->next ) { + if( (ptr_n->type == XML_ELEMENT_NODE) + && (xmlStrcmp(ptr_n->name, key_s) == 0) ) { + free(key_s); key_s = NULL; + return ptr_n; + } + } + free(key_s); key_s = NULL; + return NULL; +} + +inline char *dmixml_GetContent(xmlNode *node) { + // FIXME: Should find better way how to return UTF-8 data + return (((node != NULL) && (node->children != NULL)) ? (char *) node->children->content : NULL); +} + +inline char *dmixml_GetNodeContent(xmlNode *node, const char *key) { + return dmixml_GetContent(dmixml_FindNode(node, key)); +} + +char *dmixml_GetXPathContent(char *buf, size_t buflen, xmlXPathObject *xpo, int idx) { + memset(buf, 0, buflen); + + if( xpo == NULL ) { + return NULL; + } + + switch( xpo->type ) { + case XPATH_STRING: + strncpy(buf, (char *)xpo->stringval, buflen-1); + break; + + case XPATH_NUMBER: + snprintf(buf, buflen-1, "%f", xpo->floatval); + break; + + case XPATH_NODESET: + if( (xpo->nodesetval != NULL) && (xpo->nodesetval->nodeNr >= (idx+1)) ) { + char *str = dmixml_GetContent(xpo->nodesetval->nodeTab[idx]); + if( str != NULL ) { + strncpy(buf, str, buflen-1); + } else { + memset(buf, 0, buflen); + } + } + break; + + default: + fprintf(stderr, "dmixml_GetXPathContent(...):: " + "Do not know how to handle XPath type %i\n", + xpo->type); + return NULL; + } + return buf; +} + diff --git a/unit-tests/dmixml.h b/unit-tests/dmixml.h new file mode 100644 index 0000000..b1d86c6 --- /dev/null +++ b/unit-tests/dmixml.h @@ -0,0 +1,43 @@ +/* Simplified XML API for dmidecode + * + * Copyright 2009 David Sommerseth <davids@redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + */ + +#ifndef _XMLHELPER_H +#define _XMLHELPER_H + +#include <stdarg.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> + +xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); +xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); +xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...); + +char *dmixml_GetAttrValue(xmlNode *node, const char *key); +xmlNode *dmixml_FindNode(xmlNode *, const char *key); +inline char *dmixml_GetContent(xmlNode *node); +inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); +char *dmixml_GetXPathContent(char *buf, size_t buflen, xmlXPathObject *xpo, int idx); + +#endif diff --git a/unit-tests/libxml2mod.so b/unit-tests/libxml2mod.so Binary files differnew file mode 100644 index 0000000..4043179 --- /dev/null +++ b/unit-tests/libxml2mod.so diff --git a/unit-tests/libxml_wrap.h b/unit-tests/libxml_wrap.h new file mode 100644 index 0000000..eaa5e96 --- /dev/null +++ b/unit-tests/libxml_wrap.h @@ -0,0 +1,249 @@ +#include <Python.h> +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/parserInternals.h> +#include <libxml/catalog.h> +#include <libxml/threads.h> +#include <libxml/nanoftp.h> +#include <libxml/nanohttp.h> +#include <libxml/uri.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> +#include <libxml/debugXML.h> +#include <libxml/HTMLparser.h> +#include <libxml/HTMLtree.h> +#include <libxml/xinclude.h> +#include <libxml/xpointer.h> +#include <libxml/xmlunicode.h> +#include <libxml/xmlregexp.h> +#include <libxml/xmlautomata.h> +#include <libxml/xmlreader.h> +#ifdef LIBXML_SCHEMAS_ENABLED +#include <libxml/relaxng.h> +#include <libxml/xmlschemas.h> +#endif + +/** + * ATTRIBUTE_UNUSED: + * + * Macro used to signal to GCC unused function parameters + * Repeated here since the definition is not available when + * compiled outside the libxml2 build tree. + */ +#ifdef __GNUC__ +#ifdef ATTRIBUTE_UNUSED +#undef ATTRIBUTE_UNUSED +#endif +#ifndef ATTRIBUTE_UNUSED +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#endif /* ATTRIBUTE_UNUSED */ +#else +#define ATTRIBUTE_UNUSED +#endif + +#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlNode_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlNodePtr obj; +} PyxmlNode_Object; + +#define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlXPathContext_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlXPathContextPtr obj; +} PyxmlXPathContext_Object; + +#define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlXPathParserContext_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlXPathParserContextPtr obj; +} PyxmlXPathParserContext_Object; + +#define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PyparserCtxt_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlParserCtxtPtr obj; +} PyparserCtxt_Object; + +#define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PyValidCtxt_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlValidCtxtPtr obj; +} PyValidCtxt_Object; + +#define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \ + (((Pycatalog_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlCatalogPtr obj; +} Pycatalog_Object; + +#ifdef LIBXML_REGEXP_ENABLED +#define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlReg_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlRegexpPtr obj; +} PyxmlReg_Object; +#endif /* LIBXML_REGEXP_ENABLED */ + +#ifdef LIBXML_READER_ENABLED +#define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlTextReader_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlTextReaderPtr obj; +} PyxmlTextReader_Object; + +#define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlTextReaderLocator_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlTextReaderLocatorPtr obj; +} PyxmlTextReaderLocator_Object; +#endif + +#define PyURI_Get(v) (((v) == Py_None) ? NULL : \ + (((PyURI_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlErrorPtr obj; +} PyError_Object; + +#define PyError_Get(v) (((v) == Py_None) ? NULL : \ + (((PyError_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlOutputBufferPtr obj; +} PyoutputBuffer_Object; + +#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \ + (((PyoutputBuffer_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlParserInputBufferPtr obj; +} PyinputBuffer_Object; + +#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \ + (((PyinputBuffer_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlURIPtr obj; +} PyURI_Object; + +/* FILE * have their own internal representation */ +#define PyFile_Get(v) (((v) == Py_None) ? NULL : \ + (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout)) + +#ifdef LIBXML_SCHEMAS_ENABLED +typedef struct { + PyObject_HEAD + xmlRelaxNGPtr obj; +} PyrelaxNgSchema_Object; + +#define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \ + (((PyrelaxNgSchema_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlRelaxNGParserCtxtPtr obj; +} PyrelaxNgParserCtxt_Object; + +#define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PyrelaxNgParserCtxt_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlRelaxNGValidCtxtPtr obj; +} PyrelaxNgValidCtxt_Object; + +#define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PyrelaxNgValidCtxt_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlSchemaPtr obj; +} PySchema_Object; + +#define PySchema_Get(v) (((v) == Py_None) ? NULL : \ + (((PySchema_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlSchemaParserCtxtPtr obj; +} PySchemaParserCtxt_Object; + +#define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PySchemaParserCtxt_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlSchemaValidCtxtPtr obj; +} PySchemaValidCtxt_Object; + +#define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PySchemaValidCtxt_Object *)(v))->obj)) + +#endif /* LIBXML_SCHEMAS_ENABLED */ + +PyObject * libxml_intWrap(int val); +PyObject * libxml_longWrap(long val); +PyObject * libxml_xmlCharPtrWrap(xmlChar *str); +PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str); +PyObject * libxml_charPtrWrap(char *str); +PyObject * libxml_constcharPtrWrap(const char *str); +PyObject * libxml_charPtrConstWrap(const char *str); +PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str); +PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc); +PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node); +PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr); +PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns); +PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns); +PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns); +PyObject * libxml_doubleWrap(double val); +PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt); +PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt); +PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt); +PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj); +PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid); +PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj); +PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri); +PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer); +PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer); +#ifdef LIBXML_REGEXP_ENABLED +PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp); +#endif /* LIBXML_REGEXP_ENABLED */ +#ifdef LIBXML_READER_ENABLED +PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader); +PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator); +#endif + +xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj); +#ifdef LIBXML_SCHEMAS_ENABLED +PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt); +PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt); +PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid); +PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt); +PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt); +PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid); +#endif /* LIBXML_SCHEMAS_ENABLED */ +PyObject * libxml_xmlErrorPtrWrap(xmlErrorPtr error); +PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args); diff --git a/examples/test.py b/unit-tests/unit index b3a7be7..160641a 100755 --- a/examples/test.py +++ b/unit-tests/unit @@ -4,6 +4,8 @@ from pprint import pprint import os, sys, random, tempfile, time import commands +import libxml2 +from POCDemo import POCDemo DUMPS_D = "private" @@ -165,6 +167,24 @@ try: except ImportError: failed() + + +test = POCDemo() +print "Please note the dmixml_demo/@entrypoint attribute in the root node" +print +print "-------- xmlDoc ---------------" +xmldoc = test.GetXMLdoc() +xmldoc.saveFormatFileEnc("-", "UTF-8", 1) + +print +print "-------- xmlNode ---------------" +xmldoc2 = libxml2.newDoc("1.0") +xmlnode = test.GetXMLnode() +xmldoc2.setRootElement(xmlnode) +xmldoc2.saveFormatFileEnc("-", "UTF-8", 1) + + + sys.stdout.write(LINE) sys.stdout.write("Devices : %s\n"%cyan(len(devices))) sys.stdout.write("Total : %s\n"%blue(score["total"])) |