From 9589d4551e71b598202e799ea462b7e97d00a1da Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sat, 2 Feb 2002 10:28:17 +0000 Subject: [PATCH] Progressing through the TODOs, class description output, extra XML API, * libxml.spec.in python/Makefile.am python/TODO python/generator.py python/libxml.c python/libxml2-python-api.xml python/libxml2class.txt: Progressing through the TODOs, class description output, extra XML API, RPM now builds the wrappers for all python installed versions Daniel --- ChangeLog | 8 ++ libxml.spec.in | 18 ++++ python/Makefile.am | 2 +- python/TODO | 16 +-- python/generator.py | 36 ++++++- python/libxml.c | 1 + python/libxml2-python-api.xml | 18 ++++ python/libxml2class.txt | 197 +++++++++++++++++----------------- 8 files changed, 190 insertions(+), 106 deletions(-) create mode 100644 python/libxml2-python-api.xml diff --git a/ChangeLog b/ChangeLog index 32db962f..4e982995 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Feb 2 11:25:51 CET 2002 Daniel Veillard + + * libxml.spec.in python/Makefile.am python/TODO python/generator.py + python/libxml.c python/libxml2-python-api.xml + python/libxml2class.txt: Progressing through the TODOs, class + description output, extra XML API, RPM now builds the wrappers + for all python installed versions + Sat Feb 2 10:13:52 CET 2002 Daniel Veillard * configure.in libxml.spec.in python/Makefile.am python/TODO diff --git a/libxml.spec.in b/libxml.spec.in index 943a415d..e70ddd9f 100644 --- a/libxml.spec.in +++ b/libxml.spec.in @@ -87,6 +87,24 @@ install -d $RPM_BUILD_ROOT%{_mandir}/man1 install -d $RPM_BUILD_ROOT%{_mandir}/man4 make prefix=$RPM_BUILD_ROOT%{prefix} mandir=$RPM_BUILD_ROOT%{_mandir} install +# +# this is a bit ugly but tries to generate the bindings for all versions +# of python installed +for i in %{prefix}/include/python* +do + py_version=`echo $i | sed "s+%{prefix}/include/python++"` + if test -x %{prefix}/bin/python$py_version + then + echo generating bindings for Python $py_version + (cd python ; make clean ; \ + make PYTHON="%{prefix}/bin/python$py_version" \ + PYTHON_VERSION="$py_version"; \ + make PYTHON="%{prefix}/bin/python$py_version" \ + PYTHON_VERSION="$py_version" \ + prefix=$RPM_BUILD_ROOT%{prefix} \ + mandir=$RPM_BUILD_ROOT%{_mandir} install) + fi +done %clean rm -rf $RPM_BUILD_ROOT diff --git a/python/Makefile.am b/python/Makefile.am index 43bc4b07..c9d9f848 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -34,7 +34,7 @@ libxml2-py.o: libxml2-py.c libxml2-py.h libxml_wrap.h $(CC) $(SHCFLAGS) -c -o libxml2-py.o $(srcdir)/libxml2-py.c GENERATE = generator.py -API_DESC = $(top_srcdir)/doc/libxml2-api.xml +API_DESC = $(top_srcdir)/doc/libxml2-api.xml $(srcdir)/libxml2-python-api.xml GENERATED= $(srcdir)/libxml2class.py \ $(srcdir)/libxml2-export.c \ $(srcdir)/libxml2-py.c \ diff --git a/python/TODO b/python/TODO index b1fa7342..0fc997b0 100644 --- a/python/TODO +++ b/python/TODO @@ -1,6 +1,6 @@ TODO for the libxml2 Python wrappers - $Id$ + $Id$ Things to do: ------------- @@ -8,13 +8,8 @@ Things to do: - handling of node.content - SAX interfaces - error redirections and preformat -- class hierarchy: - + get the generator to output a classes.txt description -- extensions based on a python.xml description of the new specific - interfaces - memory debug interfaces - enums -> libxml.py -- spec file: automatically generate for pythonX.Y if found - access to XPath variables - parserCtxt exposure: - entry points @@ -33,9 +28,18 @@ Done: ----- - class hierarchy: + make specific node type inherit from xmlNode + done, had to sort the classes in the output + + get the generator to output a classes.txt description + done libxml2class.txt - add regression tests - tests/Makefile.am: export the Python class path - xpath queries - xpath extension +- extensions based on a python.xml description of the new specific + interfaces + file libxml2-python-api.xml , first entry is xmlRegisterXPathFunction +- spec file: automatically generate for pythonX.Y if found + Done, a bit ugly by running new makes in %install for each level + found. Daniel Veillard diff --git a/python/generator.py b/python/generator.py index ee477b01..80dca7bb 100755 --- a/python/generator.py +++ b/python/generator.py @@ -361,7 +361,13 @@ def print_function_wrapper(name, output, export, include): include.write("PyObject * ") include.write("libxml_%s(PyObject *self, PyObject *args);\n" % (name)) + export.write(" { \"%s\", libxml_%s, METH_VARARGS },\n" % (name, name)) + + if file == "python": + # Those have been manually generated + return 1 + output.write("PyObject *\n") output.write("libxml_%s(PyObject *self, PyObject *args) {\n" % (name)) if ret[0] != 'void': @@ -391,7 +397,22 @@ try: except IOError, msg: print file, ":", msg -print "Found %d functions in libxml2-api.xml" % (len(functions.keys())) +n = len(functions.keys()) +print "Found %d functions in libxml2-api.xml" % (n) + +py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject") +try: + f = open("libxml2-python-api.xml") + data = f.read() + (parser, target) = getparser() + parser.feed(data) + parser.close() +except IOError, msg: + print file, ":", msg + + +print "Found %d functions in libxml2-python-api.xml" % ( + len(functions.keys()) - n) nb_wrap = 0 failed = 0 skipped = 0 @@ -487,8 +508,12 @@ for type in classes_type.keys(): # Build the list of C types to look for ordered to start with primary classes # ctypes = [] +classes_list = [] ctypes_processed = {} +classes_processed = {} for classe in primary_classes: + classes_list.append(classe) + classes_processed[classe] = () for type in classes_type.keys(): tinfo = classes_type[type] if tinfo[2] == classe: @@ -498,6 +523,10 @@ for type in classes_type.keys(): if ctypes_processed.has_key(type): continue tinfo = classes_type[type] + if not classes_processed.has_key(tinfo[2]): + classes_list.append(tinfo[2]) + classes_processed[tinfo[2]] = () + ctypes.append(type) ctypes_processed[type] = () @@ -511,6 +540,9 @@ def nameFixup(function, classe, type): elif name[0:l] == classe: func = name[l:] func = string.lower(func[0:1]) + func[1:] + elif name[0:7] == "libxml_": + func = name[7:] + func = string.lower(func[0:1]) + func[1:] elif name[0:6] == "xmlGet": func = name[6:] func = string.lower(func[0:1]) + func[1:] @@ -656,7 +688,7 @@ if function_classes.has_key("None"): classes.write("\n"); txt.write("\n\n#\n# Set of classes of the module\n#\n\n") -for classname in function_classes.keys(): +for classname in classes_list: if classname == "None": pass else: diff --git a/python/libxml.c b/python/libxml.c index 61992c69..fcd8df80 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -419,6 +419,7 @@ libxml_registerXPathFunction(PyObject *self, PyObject *args) { libxml_xpathCallbacks[i].name = xmlStrdup(name); libxml_xpathCallbacks[i].ns_uri = xmlStrdup(ns_uri); libxml_xpathCallbacks[i].function = pyobj_f; + c_retval = 1; } done: py_retval = libxml_intWrap((int) c_retval); diff --git a/python/libxml2-python-api.xml b/python/libxml2-python-api.xml new file mode 100644 index 00000000..29dca230 --- /dev/null +++ b/python/libxml2-python-api.xml @@ -0,0 +1,18 @@ + + + + + + + + + + Register a Python written function to the XPath interpreter + + + + + + + + diff --git a/python/libxml2class.txt b/python/libxml2class.txt index c8e23596..a5c45d31 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -131,85 +131,6 @@ checkVersion() # Set of classes of the module # -Class xpathContext() - - # functions from module xpath - xpathEval() - xpathEvalExpression() - - # functions from module xpathInternals - xpathFreeContext() - xpathNsLookup() - xpathRegisterAllFunctions() - xpathRegisterNs() - xpathRegisteredFuncsCleanup() - xpathRegisteredNsCleanup() - xpathRegisteredVariablesCleanup() - xpathVariableLookup() - xpathVariableLookupNS() - - -Class xmlDoc(xmlNode) - - # functions from module HTMLparser - htmlAutoCloseTag() - htmlIsAutoClosed() - - # functions from module HTMLtree - htmlGetMetaEncoding() - htmlSaveFile() - htmlSaveFileEnc() - htmlSaveFileFormat() - htmlSetMetaEncoding() - - # functions from module entities - addDocEntity() - addDtdEntity() - docEntity() - dtdEntity() - encodeEntities() - encodeEntitiesReentrant() - encodeSpecialChars() - parameterEntity() - - # functions from module tree - copyDoc() - createIntSubset() - docCompressMode() - freeDoc() - getRootElement() - intSubset() - newCDataBlock() - newCharRef() - newDocComment() - newDocFragment() - newDocNode() - newDocProp() - newDocRawNode() - newDocText() - newDocTextLen() - newDtd() - newGlobalNs() - newReference() - saveFile() - saveFileEnc() - saveFormatFile() - saveFormatFileEnc() - setDocCompressMode() - stringGetNodeList() - stringLenGetNodeList() - - # functions from module valid - ID() - isMixedElement() - removeID() - removeRef() - - # functions from module xinclude - xincludeProcess() - - # functions from module xpathInternals - xpathNewContext() Class xmlNode(xmlCore) @@ -290,6 +211,90 @@ Class xmlNode(xmlCore) xpathNewValueTree() +Class xmlDoc(xmlNode) + + # functions from module HTMLparser + htmlAutoCloseTag() + htmlIsAutoClosed() + + # functions from module HTMLtree + htmlGetMetaEncoding() + htmlSaveFile() + htmlSaveFileEnc() + htmlSaveFileFormat() + htmlSetMetaEncoding() + + # functions from module entities + addDocEntity() + addDtdEntity() + docEntity() + dtdEntity() + encodeEntities() + encodeEntitiesReentrant() + encodeSpecialChars() + parameterEntity() + + # functions from module tree + copyDoc() + createIntSubset() + docCompressMode() + freeDoc() + getRootElement() + intSubset() + newCDataBlock() + newCharRef() + newDocComment() + newDocFragment() + newDocNode() + newDocProp() + newDocRawNode() + newDocText() + newDocTextLen() + newDtd() + newGlobalNs() + newReference() + saveFile() + saveFileEnc() + saveFormatFile() + saveFormatFileEnc() + setDocCompressMode() + stringGetNodeList() + stringLenGetNodeList() + + # functions from module valid + ID() + isMixedElement() + removeID() + removeRef() + + # functions from module xinclude + xincludeProcess() + + # functions from module xpathInternals + xpathNewContext() + + +Class xmlEntity(xmlNode) + + +Class xmlNs(xmlNode) + + # functions from module tree + copyNamespace() + copyNamespaceList() + freeNs() + freeNsList() + newNode() + + +Class xmlAttr(xmlNode) + + # functions from module tree + freeProp() + freePropList() + removeProp() + + Class xmlAttribute(xmlNode) @@ -306,25 +311,23 @@ Class xmlDtd(xmlNode) dtdQElementDesc() -Class xmlAttr(xmlNode) - - # functions from module tree - freeProp() - freePropList() - removeProp() - - -Class xmlEntity(xmlNode) - - Class xmlElement(xmlNode) +Class xpathContext() + # functions from module python + registerXPathFunction() -Class xmlNs(xmlNode) + # functions from module xpath + xpathEval() + xpathEvalExpression() - # functions from module tree - copyNamespace() - copyNamespaceList() - freeNs() - freeNsList() - newNode() + # functions from module xpathInternals + xpathFreeContext() + xpathNsLookup() + xpathRegisterAllFunctions() + xpathRegisterNs() + xpathRegisteredFuncsCleanup() + xpathRegisteredNsCleanup() + xpathRegisteredVariablesCleanup() + xpathVariableLookup() + xpathVariableLookupNS()