1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-07-29 15:41:13 +03:00

attempst to tweak to get full memory debug... the basic API starts to work

* configure.in python/Makefile.am: attempst to tweak to get
  full memory debug...
* python/generator.py python/libxsl.py python/libxslt-python-api.xml
  python/libxslt.c python/libxslt_wrap.h python/libxsltclass.txt:
  the basic API starts to work
* python/tests/test.*: first basic test
* libxslt/xsltutils.c: fixed a comment
Daniel
This commit is contained in:
Daniel Veillard
2002-02-05 23:23:15 +00:00
parent f6064ec0ba
commit f0cb070b69
13 changed files with 186 additions and 29 deletions

View File

@ -19,7 +19,7 @@ EXTRA_DIST = \
$(DOCS)
if WITH_PYTHON
all: _libxslt.so libxslt.py
all: _libxslt.so libxslt.py $(PYTHONSODV)
libxslt.py: $(srcdir)/libxsl.py libxsltclass.py
cat $(srcdir)/libxsl.py libxsltclass.py > libxslt.py
@ -27,6 +27,10 @@ libxslt.py: $(srcdir)/libxsl.py libxsltclass.py
_libxslt.so: libxslt.o libxslt-py.o types.o
$(CC) $(LINK_FLAGS) libxslt.o libxslt-py.o types.o $(LIBS) -o _libxslt.so
_libxslt.so.dv: libxslt.o libxslt-py.o types.o
rm -f _libxslt.so
$(CC) $(LINK_FLAGS) libxslt.o libxslt-py.o types.o -L../libxslt/.libs -L../libxslt -lxslt -L../libexslt/.libs -L../libexslt -lexslt $(HOME)/XML/python/_libxml.so $(HOME)/XML/.libs/libxml2.a -o _libxslt.so
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(PYTHON_SITE_PACKAGES)
-@INSTALL@ -m 0644 libxslt.py $(DESTDIR)$(PYTHON_SITE_PACKAGES)

View File

@ -265,6 +265,8 @@ py_types = {
'htmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr", "libxml_"),
'xsltTransformContextPtr': ('O', "transformCtxt", "xsltTransformContextPtr", "xsltTransformContextPtr", "libxslt_"),
'xsltTransformContext *': ('O', "transformCtxt", "xsltTransformContextPtr", "xsltTransformContextPtr", "libxslt_"),
'xsltStylesheetPtr': ('O', "stylesheet", "xsltStylesheetPtr", "xsltStylesheetPtr", "libxslt_"),
'xsltStylesheet *': ('O', "stylesheet", "xsltStylesheetPtr", "xsltStylesheetPtr", "libxslt_"),
}
py_return_types = {
@ -507,13 +509,13 @@ converter_type = {
"xmlXPathObjectPtr": "xpathObjectRet(%s)",
}
primary_classes = []
primary_classes = ["transformCtxt", "stylesheet"]
classes_ancestor = {
}
classes_destructors = {
"xpathContext": "xmlXPathFreeContext",
"parserCtxt": "xmlFreeParserCtxt",
"stylesheet": "xsltFreeStylesheet",
"transformCtxt": "xsltFreeTransformContext",
}
function_classes = {}
@ -607,27 +609,7 @@ for name in functions.keys():
for type in ctypes:
classe = classes_type[type][2]
if name[0:3] == "xml" and len(args) >= 1 and args[0][1] == type:
found = 1
func = nameFixup(name, classe, type, file)
info = (0, func, name, ret, args, file)
function_classes[classe].append(info)
elif name[0:3] == "xml" and len(args) >= 2 and args[1][1] == type:
found = 1
func = nameFixup(name, classe, type, file)
info = (1, func, name, ret, args, file)
function_classes[classe].append(info)
elif name[0:4] == "html" and len(args) >= 1 and args[0][1] == type:
found = 1
func = nameFixup(name, classe, type, file)
info = (0, func, name, ret, args, file)
function_classes[classe].append(info)
elif name[0:4] == "html" and len(args) >= 2 and args[1][1] == type:
found = 1
func = nameFixup(name, classe, type, file)
info = (1, func, name, ret, args, file)
function_classes[classe].append(info)
elif name[0:4] == "xslt" and len(args) >= 1 and args[0][1] == type:
if name[0:4] == "xslt" and len(args) >= 1 and args[0][1] == type:
found = 1
func = nameFixup(name, classe, type, file)
info = (0, func, name, ret, args, file)
@ -637,6 +619,11 @@ for name in functions.keys():
func = nameFixup(name, classe, type, file)
info = (1, func, name, ret, args, file)
function_classes[classe].append(info)
elif name[0:4] == "xslt" and len(args) >= 3 and args[2][1] == type:
found = 1
func = nameFixup(name, classe, type, file)
info = (2, func, name, ret, args, file)
function_classes[classe].append(info)
if found == 1:
break
if found == 1:

View File

@ -1,4 +1,4 @@
import libxml2
from libxml2 import *
import _libxslt
#

View File

@ -5,6 +5,13 @@
</file>
</files>
<symbols>
<function name='xsltApplyStylesheet' file='python'>
<info>Apply the stylesheet to the document</info>
<return type='xmlDocPtr' info="the result document or NULL in case of error"/>
<arg name='style' type='xsltStylesheetPtr' info='a parsed XSLT stylesheet'/>
<arg name='doc' type='xmlDocPtr' info='a parsed XML document'/>
<arg name='params' type='pythonObject' info='the parameters dictionnary'/>
</function>
<!--
<function name='xsltRegisterXPathFunction' file='python'>
<info>Register a Python written function to the XPath interpreter</info>

View File

@ -20,6 +20,42 @@
/* #define DEBUG_ERROR */
/* #define DEBUG_MEMORY */
/************************************************************************
* *
* Per type specific glue *
* *
************************************************************************/
PyObject *
libxslt_xsltStylesheetPtrWrap(xsltStylesheetPtr style) {
PyObject *ret;
#ifdef DEBUG
printf("libxslt_xsltStylesheetPtrWrap: style = %p\n", style);
#endif
if (style == NULL) {
Py_INCREF(Py_None);
return(Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) style, "xsltStylesheetPtr", NULL);
return(ret);
}
PyObject *
libxslt_xsltTransformContextPtrWrap(xsltTransformContextPtr ctxt) {
PyObject *ret;
#ifdef DEBUG
printf("libxslt_xsltTransformContextPtrWrap: ctxt = %p\n", ctxt);
#endif
if (ctxt == NULL) {
Py_INCREF(Py_None);
return(Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xsltTransformContextPtr", NULL);
return(ret);
}
/************************************************************************
* *
* Memory debug interface *
@ -105,6 +141,40 @@ libxslt_xmlDumpMemory(PyObject *self, PyObject *args) {
return(Py_None);
}
/************************************************************************
* *
* Some customized front-ends *
* *
************************************************************************/
PyObject *
libxslt_xsltApplyStylesheet(PyObject *self, PyObject *args) {
PyObject *py_retval;
xmlDocPtr c_retval;
xsltStylesheetPtr style;
PyObject *pyobj_style;
xmlDocPtr doc;
PyObject *pyobj_doc;
PyObject *pyobj_params;
char **params;
if (!PyArg_ParseTuple(args, "OOO:xsltApplyStylesheet", &pyobj_style, &pyobj_doc, &pyobj_params))
return(NULL);
if (pyobj_params != Py_None) {
printf("libxslt_xsltApplyStylesheet: parameters not yet supported\n");
Py_INCREF(Py_None);
return(Py_None);
} else {
params = NULL;
}
style = (xsltStylesheetPtr) Pystylesheet_Get(pyobj_style);
doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc);
c_retval = xsltApplyStylesheet(style, doc, params);
py_retval = libxml_xmlDocPtrWrap((xmlDocPtr) c_retval);
return(py_retval);
}
/************************************************************************
* *

View File

@ -34,5 +34,5 @@ typedef struct {
xsltTransformContextPtr obj;
} PytransformCtxt_Object;
PyObject * libxslt_xsltTransformContextPtr(xsltTransformContextPtr ctxt);
PyObject * libxslt_xsltStylesheetPtr(xsltStylesheetPtr ctxt);
PyObject * libxslt_xsltStylesheetPtrWrap(xsltStylesheetPtr ctxt);
PyObject * libxslt_xsltTransformContextPtrWrap(xsltTransformContextPtr ctxt);

View File

@ -27,6 +27,9 @@ cleanupGlobals()
# functions from module xsltInternals
isBlank()
loadStylesheetPI()
newStylesheet()
parseStylesheetDoc()
# functions from module xsltutils
calibrateAdjust()
@ -90,4 +93,59 @@ Class transformCtxt()
# functions from module xsltutils
message()
printErrorContext()
Class stylesheet()
# functions from module attributes
freeAttributeSetsHashes()
parseStylesheetAttributeSet()
# functions from module documents
freeStyleDocuments()
# functions from module extensions
checkExtPrefix()
freeExts()
registerExtPrefix()
shutdownExts()
# functions from module imports
nextImport()
parseStylesheetImport()
parseStylesheetInclude()
# functions from module keys
addKey()
freeKeys()
# functions from module namespaces
freeNamespaceAliasHashes()
namespaceAlias()
# functions from module pattern
cleanupTemplates()
freeTemplateHashes()
# functions from module preproc
freeStylePreComps()
stylePreCompute()
# functions from module python
applyStylesheet()
# functions from module transform
newTransformContext()
# functions from module variables
parseGlobalParam()
parseGlobalVariable()
# functions from module xsltInternals
freeStylesheet()
parseStylesheetOutput()
parseStylesheetProcess()
parseTemplateContent()
# functions from module xsltutils
saveResultToFd()
saveResultToFilename()

9
python/tests/test.py Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/python -u
import libxml2
import libxslt
styledoc = libxml2.parseFile("test.xsl")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile("test.xml")
result = style.applyStylesheet(doc, None)
result.saveFile("-")

1
python/tests/test.xml Normal file
View File

@ -0,0 +1 @@
<test/>

9
python/tests/test.xsl Normal file
View File

@ -0,0 +1,9 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<article>
<title>Hello World</title>
</article>
</xsl:template>
</xsl:stylesheet>