mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-07-29 15:41:13 +03:00
committed by
Nick Wellnhofer
parent
2c20c70cd8
commit
a2db8da1ac
107
configure.ac
107
configure.ac
@ -204,7 +204,7 @@ dnl
|
|||||||
if test "${NEED_TRIO}" = "1" ; then
|
if test "${NEED_TRIO}" = "1" ; then
|
||||||
echo Reusing trio library for string functions
|
echo Reusing trio library for string functions
|
||||||
WITH_TRIO=1
|
WITH_TRIO=1
|
||||||
else
|
else
|
||||||
WITH_TRIO=0
|
WITH_TRIO=0
|
||||||
fi
|
fi
|
||||||
AC_SUBST(WITH_TRIO)
|
AC_SUBST(WITH_TRIO)
|
||||||
@ -230,76 +230,107 @@ dnl
|
|||||||
PYTHON_VERSION=
|
PYTHON_VERSION=
|
||||||
PYTHON_INCLUDES=
|
PYTHON_INCLUDES=
|
||||||
PYTHON_SITE_PACKAGES=
|
PYTHON_SITE_PACKAGES=
|
||||||
|
PYTHON_TESTS=
|
||||||
pythondir=
|
pythondir=
|
||||||
AC_ARG_WITH(python, [ --with-python[=DIR] Build Python bindings if found])
|
AC_ARG_WITH(python,
|
||||||
|
[ --with-python[[=DIR]] build Python bindings if found])
|
||||||
|
AC_ARG_WITH(python_install_dir,
|
||||||
|
[ --with-python-install-dir=DIR
|
||||||
|
install Python bindings in DIR])
|
||||||
if test "$with_python" != "no" ; then
|
if test "$with_python" != "no" ; then
|
||||||
if test -x "$with_python/bin/python"
|
if test -x "$with_python/bin/python"
|
||||||
then
|
then
|
||||||
echo Found python in $with_python/bin/python
|
echo Found python in $with_python/bin/python
|
||||||
PYTHON="$with_python/bin/python"
|
PYTHON="$with_python/bin/python"
|
||||||
else
|
else
|
||||||
if test -x "$with_python"
|
if test -x "$with_python/python.exe"
|
||||||
then
|
then
|
||||||
echo Found python in $with_python
|
echo Found python in $with_python/python.exe
|
||||||
PYTHON="$with_python"
|
PYTHON="$with_python/python.exe"
|
||||||
else
|
else
|
||||||
if test -x "$PYTHON"
|
if test -x "$with_python"
|
||||||
then
|
then
|
||||||
echo Found python in environment PYTHON=$PYTHON
|
echo Found python in $with_python
|
||||||
with_python=`$PYTHON -c "import sys; print sys.exec_prefix"`
|
PYTHON="$with_python"
|
||||||
else
|
else
|
||||||
AC_PATH_PROG(PYTHON, python python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5)
|
if test -x "$PYTHON"
|
||||||
|
then
|
||||||
|
echo Found python in environment PYTHON=$PYTHON
|
||||||
|
with_python=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
|
||||||
|
else
|
||||||
|
AC_PATH_PROG(PYTHON, python python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if test "$PYTHON" != ""
|
if test "$PYTHON" != ""
|
||||||
then
|
then
|
||||||
echo "PYTHON is pointing at $PYTHON"
|
PYTHON_VERSION=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_version())"`
|
||||||
PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
|
PYTHON_INCLUDES=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_inc())"`
|
||||||
|
# does not work as it produce a /usr/lib/python path instead of/usr/lib64/python
|
||||||
|
#
|
||||||
|
# PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib())"`
|
||||||
echo Found Python version $PYTHON_VERSION
|
echo Found Python version $PYTHON_VERSION
|
||||||
LIBXML2_PYTHON=`$PYTHON -c "try : import libxml2 ; print 1
|
LIBXML2_PYTHON=`$PYTHON -c "import sys
|
||||||
except: print 0"`
|
try:
|
||||||
|
import libxml2
|
||||||
|
sys.stdout.write('1')
|
||||||
|
except:
|
||||||
|
sys.stdout.write('0')
|
||||||
|
"`
|
||||||
if test "$LIBXML2_PYTHON" = "1"
|
if test "$LIBXML2_PYTHON" = "1"
|
||||||
then
|
then
|
||||||
echo Found libxml2-python module
|
echo Found libxml2-python module
|
||||||
else
|
else
|
||||||
echo Warning: Missing libxml2-python
|
echo Warning: Missing libxml2-python
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if test "$PYTHON_VERSION" != ""
|
if test "$PYTHON_VERSION" != "" -a "$PYTHON_INCLUDES" = ""
|
||||||
then
|
then
|
||||||
if test -r $with_python/include/python$PYTHON_VERSION/Python.h -a \
|
if test -r $with_python/include/python$PYTHON_VERSION/Python.h
|
||||||
-d $with_python/lib/python$PYTHON_VERSION/site-packages
|
|
||||||
then
|
then
|
||||||
PYTHON_INCLUDES=$with_python/include/python$PYTHON_VERSION
|
PYTHON_INCLUDES=$with_python/include/python$PYTHON_VERSION
|
||||||
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
|
|
||||||
else
|
else
|
||||||
if test -r $prefix/include/python$PYTHON_VERSION/Python.h
|
if test -r $prefix/include/python$PYTHON_VERSION/Python.h
|
||||||
then
|
then
|
||||||
PYTHON_INCLUDES=$prefix/include/python$PYTHON_VERSION
|
PYTHON_INCLUDES=$prefix/include/python$PYTHON_VERSION
|
||||||
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
|
|
||||||
else
|
else
|
||||||
if test -r /usr/include/python$PYTHON_VERSION/Python.h
|
if test -r /usr/include/python$PYTHON_VERSION/Python.h
|
||||||
then
|
then
|
||||||
PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION
|
PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION
|
||||||
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
|
|
||||||
else
|
else
|
||||||
echo could not find python$PYTHON_VERSION/Python.h
|
if test -r $with_python/include/Python.h
|
||||||
|
then
|
||||||
|
PYTHON_INCLUDES=$with_python/include
|
||||||
|
else
|
||||||
|
echo could not find python$PYTHON_VERSION/Python.h or $with_python/include/Python.h
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if test ! -d "$PYTHON_SITE_PACKAGES"
|
fi
|
||||||
|
fi
|
||||||
|
if test "$with_python_install_dir" != ""
|
||||||
|
then
|
||||||
|
PYTHON_SITE_PACKAGES="$with_python_install_dir"
|
||||||
|
fi
|
||||||
|
if test "$PYTHON_VERSION" != "" -a "$PYTHON_SITE_PACKAGES" = ""
|
||||||
|
then
|
||||||
|
if test -d $libdir/python$PYTHON_VERSION/site-packages
|
||||||
|
then
|
||||||
|
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
|
||||||
|
else
|
||||||
|
if test -d $with_python/lib/site-packages
|
||||||
then
|
then
|
||||||
PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"`
|
PYTHON_SITE_PACKAGES=$with_python/lib/site-packages
|
||||||
|
else
|
||||||
|
PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib())"`
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
PYTHON_LIBS=`python$PYTHON_VERSION-config --libs`
|
|
||||||
fi
|
|
||||||
if test "$with_python" != ""
|
|
||||||
then
|
|
||||||
pythondir=$PYTHON_SITE_PACKAGES
|
|
||||||
else
|
|
||||||
pythondir=$libdir/python$PYTHON_VERSION/site-packages
|
|
||||||
fi
|
fi
|
||||||
|
pythondir='$(PYTHON_SITE_PACKAGES)'
|
||||||
|
PYTHON_LIBS=`python$PYTHON_VERSION-config --ldflags`
|
||||||
|
else
|
||||||
|
PYTHON=
|
||||||
fi
|
fi
|
||||||
AM_CONDITIONAL(WITH_PYTHON, test "$PYTHON_INCLUDES" != "")
|
AM_CONDITIONAL(WITH_PYTHON, test "$PYTHON_INCLUDES" != "")
|
||||||
if test "$PYTHON_INCLUDES" != ""
|
if test "$PYTHON_INCLUDES" != ""
|
||||||
@ -374,7 +405,7 @@ AC_ARG_WITH(debug, [ --with-debug Add the debugging code (on)])
|
|||||||
if test "$with_debug" = "no" ; then
|
if test "$with_debug" = "no" ; then
|
||||||
echo Disabling debug support
|
echo Disabling debug support
|
||||||
WITH_XSLT_DEBUG=0
|
WITH_XSLT_DEBUG=0
|
||||||
else
|
else
|
||||||
WITH_XSLT_DEBUG=1
|
WITH_XSLT_DEBUG=1
|
||||||
fi
|
fi
|
||||||
AC_SUBST(WITH_XSLT_DEBUG)
|
AC_SUBST(WITH_XSLT_DEBUG)
|
||||||
@ -383,12 +414,12 @@ AC_ARG_WITH(mem_debug, [ --with-mem-debug Add the memory debugging modul
|
|||||||
if test "$with_mem_debug" = "yes" ; then
|
if test "$with_mem_debug" = "yes" ; then
|
||||||
echo Enabling memory debug support
|
echo Enabling memory debug support
|
||||||
WITH_MEM_DEBUG=1
|
WITH_MEM_DEBUG=1
|
||||||
else
|
else
|
||||||
WITH_MEM_DEBUG=0
|
WITH_MEM_DEBUG=0
|
||||||
fi
|
fi
|
||||||
AC_SUBST(WITH_MEM_DEBUG)
|
AC_SUBST(WITH_MEM_DEBUG)
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Is debugger support requested
|
dnl Is debugger support requested
|
||||||
dnl
|
dnl
|
||||||
AC_ARG_WITH(debugger, [ --with-debugger Add the debugging support (on)])
|
AC_ARG_WITH(debugger, [ --with-debugger Add the debugging support (on)])
|
||||||
@ -432,7 +463,7 @@ AC_ARG_WITH(libxml-prefix,
|
|||||||
[ --with-libxml-prefix=[PFX] Specify location of libxml config],
|
[ --with-libxml-prefix=[PFX] Specify location of libxml config],
|
||||||
LIBXML_CONFIG_PREFIX=$withval
|
LIBXML_CONFIG_PREFIX=$withval
|
||||||
)
|
)
|
||||||
|
|
||||||
AC_ARG_WITH(libxml-include-prefix,
|
AC_ARG_WITH(libxml-include-prefix,
|
||||||
[ --with-libxml-include-prefix=[PFX] Specify location of libxml headers],
|
[ --with-libxml-include-prefix=[PFX] Specify location of libxml headers],
|
||||||
LIBXML_CFLAGS="-I$withval"
|
LIBXML_CFLAGS="-I$withval"
|
||||||
@ -462,7 +493,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl imported from libxml2, c.f. #77827
|
dnl imported from libxml2, c.f. #77827
|
||||||
dnl
|
dnl
|
||||||
if test "${GCC}" != "yes" ; then
|
if test "${GCC}" != "yes" ; then
|
||||||
case "${host}" in
|
case "${host}" in
|
||||||
|
@ -2,11 +2,15 @@
|
|||||||
#
|
#
|
||||||
# generate python wrappers from the XML API description
|
# generate python wrappers from the XML API description
|
||||||
#
|
#
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
functions = {}
|
functions = {}
|
||||||
enums = {} # { enumType: { enumConstant: enumValue } }
|
enums = {} # { enumType: { enumConstant: enumValue } }
|
||||||
|
import sys
|
||||||
import string
|
if sys.version_info < (3, 0):
|
||||||
|
import string as re_str
|
||||||
|
else:
|
||||||
|
re_str=str
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
@ -39,19 +43,19 @@ class docParser(xml.sax.handler.ContentHandler):
|
|||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if debug:
|
if debug:
|
||||||
print "close"
|
print("close")
|
||||||
|
|
||||||
def getmethodname(self):
|
def getmethodname(self):
|
||||||
return self._methodname
|
return self._methodname
|
||||||
|
|
||||||
def data(self, text):
|
def data(self, text):
|
||||||
if debug:
|
if debug:
|
||||||
print "data %s" % text
|
print("data %s" % text)
|
||||||
self._data.append(text)
|
self._data.append(text)
|
||||||
|
|
||||||
def start(self, tag, attrs):
|
def start(self, tag, attrs):
|
||||||
if debug:
|
if debug:
|
||||||
print "start %s, %s" % (tag, attrs)
|
print("start %s, %s" % (tag, attrs))
|
||||||
if tag == 'function':
|
if tag == 'function':
|
||||||
self._data = []
|
self._data = []
|
||||||
self.in_function = 1
|
self.in_function = 1
|
||||||
@ -60,9 +64,9 @@ class docParser(xml.sax.handler.ContentHandler):
|
|||||||
self.function_descr = None
|
self.function_descr = None
|
||||||
self.function_return = None
|
self.function_return = None
|
||||||
self.function_file = None
|
self.function_file = None
|
||||||
if attrs.has_key('name'):
|
if 'name' in attrs:
|
||||||
self.function = attrs['name']
|
self.function = attrs['name']
|
||||||
if attrs.has_key('file'):
|
if 'file' in attrs:
|
||||||
self.function_file = attrs['file']
|
self.function_file = attrs['file']
|
||||||
elif tag == 'info':
|
elif tag == 'info':
|
||||||
self._data = []
|
self._data = []
|
||||||
@ -71,31 +75,31 @@ class docParser(xml.sax.handler.ContentHandler):
|
|||||||
self.function_arg_name = None
|
self.function_arg_name = None
|
||||||
self.function_arg_type = None
|
self.function_arg_type = None
|
||||||
self.function_arg_info = None
|
self.function_arg_info = None
|
||||||
if attrs.has_key('name'):
|
if 'name' in attrs:
|
||||||
self.function_arg_name = attrs['name']
|
self.function_arg_name = attrs['name']
|
||||||
if attrs.has_key('type'):
|
if 'type' in attrs:
|
||||||
self.function_arg_type = attrs['type']
|
self.function_arg_type = attrs['type']
|
||||||
if attrs.has_key('info'):
|
if 'info' in attrs:
|
||||||
self.function_arg_info = attrs['info']
|
self.function_arg_info = attrs['info']
|
||||||
elif tag == 'return':
|
elif tag == 'return':
|
||||||
if self.in_function == 1:
|
if self.in_function == 1:
|
||||||
self.function_return_type = None
|
self.function_return_type = None
|
||||||
self.function_return_info = None
|
self.function_return_info = None
|
||||||
self.function_return_field = None
|
self.function_return_field = None
|
||||||
if attrs.has_key('type'):
|
if 'type' in attrs:
|
||||||
self.function_return_type = attrs['type']
|
self.function_return_type = attrs['type']
|
||||||
if attrs.has_key('info'):
|
if 'info' in attrs:
|
||||||
self.function_return_info = attrs['info']
|
self.function_return_info = attrs['info']
|
||||||
if attrs.has_key('field'):
|
if 'field' in attrs:
|
||||||
self.function_return_field = attrs['field']
|
self.function_return_field = attrs['field']
|
||||||
elif tag == 'enum':
|
elif tag == 'enum':
|
||||||
enum(attrs['type'],attrs['name'],attrs['value'])
|
enum(attrs['type'],attrs['name'],attrs['value'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def end(self, tag):
|
def end(self, tag):
|
||||||
if debug:
|
if debug:
|
||||||
print "end %s" % tag
|
print("end %s" % tag)
|
||||||
if tag == 'function':
|
if tag == 'function':
|
||||||
if self.function != None:
|
if self.function != None:
|
||||||
function(self.function, self.function_descr,
|
function(self.function, self.function_descr,
|
||||||
@ -118,15 +122,15 @@ class docParser(xml.sax.handler.ContentHandler):
|
|||||||
str = str + c
|
str = str + c
|
||||||
if self.in_function == 1:
|
if self.in_function == 1:
|
||||||
self.function_descr = str
|
self.function_descr = str
|
||||||
|
|
||||||
|
|
||||||
def function(name, desc, ret, args, file):
|
def function(name, desc, ret, args, file):
|
||||||
functions[name] = (desc, ret, args, file)
|
functions[name] = (desc, ret, args, file)
|
||||||
|
|
||||||
def enum(type, name, value):
|
def enum(type, name, value):
|
||||||
if not enums.has_key(type):
|
if type not in enums:
|
||||||
enums[type] = {}
|
enums[type] = {}
|
||||||
enums[type][name] = value
|
enums[type][name] = value
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
@ -264,10 +268,10 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
try:
|
try:
|
||||||
(desc, ret, args, file) = functions[name]
|
(desc, ret, args, file) = functions[name]
|
||||||
except:
|
except:
|
||||||
print "failed to get function %s infos"
|
print("failed to get function %s infos")
|
||||||
return
|
return
|
||||||
|
|
||||||
if skipped_modules.has_key(file):
|
if file in skipped_modules:
|
||||||
return 0
|
return 0
|
||||||
if skip_function(name) == 1:
|
if skip_function(name) == 1:
|
||||||
return 0
|
return 0
|
||||||
@ -283,7 +287,7 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
if arg[1][0:6] == "const ":
|
if arg[1][0:6] == "const ":
|
||||||
arg[1] = arg[1][6:]
|
arg[1] = arg[1][6:]
|
||||||
c_args = c_args + " %s %s;\n" % (arg[1], arg[0])
|
c_args = c_args + " %s %s;\n" % (arg[1], arg[0])
|
||||||
if py_types.has_key(arg[1]):
|
if arg[1] in py_types:
|
||||||
(f, t, n, c, p) = py_types[arg[1]]
|
(f, t, n, c, p) = py_types[arg[1]]
|
||||||
if f != None:
|
if f != None:
|
||||||
format = format + f
|
format = format + f
|
||||||
@ -299,9 +303,9 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
c_call = c_call + ", "
|
c_call = c_call + ", "
|
||||||
c_call = c_call + "%s" % (arg[0])
|
c_call = c_call + "%s" % (arg[0])
|
||||||
else:
|
else:
|
||||||
if skipped_types.has_key(arg[1]):
|
if arg[1] in skipped_types:
|
||||||
return 0
|
return 0
|
||||||
if unknown_types.has_key(arg[1]):
|
if arg[1] in unknown_types:
|
||||||
lst = unknown_types[arg[1]]
|
lst = unknown_types[arg[1]]
|
||||||
lst.append(name)
|
lst.append(name)
|
||||||
else:
|
else:
|
||||||
@ -323,7 +327,7 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
else:
|
else:
|
||||||
c_call = "\n %s(%s);\n" % (name, c_call)
|
c_call = "\n %s(%s);\n" % (name, c_call)
|
||||||
ret_convert = " Py_INCREF(Py_None);\n return(Py_None);\n"
|
ret_convert = " Py_INCREF(Py_None);\n return(Py_None);\n"
|
||||||
elif py_types.has_key(ret[0]):
|
elif ret[0] in py_types:
|
||||||
(f, t, n, c, p) = py_types[ret[0]]
|
(f, t, n, c, p) = py_types[ret[0]]
|
||||||
c_return = " %s c_retval;\n" % (ret[0])
|
c_return = " %s c_retval;\n" % (ret[0])
|
||||||
if file == "python_accessor" and ret[2] != None:
|
if file == "python_accessor" and ret[2] != None:
|
||||||
@ -332,7 +336,7 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
c_call = "\n c_retval = %s(%s);\n" % (name, c_call)
|
c_call = "\n c_retval = %s(%s);\n" % (name, c_call)
|
||||||
ret_convert = " py_retval = %s%sWrap((%s) c_retval);\n" % (p,n,c)
|
ret_convert = " py_retval = %s%sWrap((%s) c_retval);\n" % (p,n,c)
|
||||||
ret_convert = ret_convert + " return(py_retval);\n"
|
ret_convert = ret_convert + " return(py_retval);\n"
|
||||||
elif py_return_types.has_key(ret[0]):
|
elif ret[0] in py_return_types:
|
||||||
(f, t, n, c, p) = py_return_types[ret[0]]
|
(f, t, n, c, p) = py_return_types[ret[0]]
|
||||||
c_return = " %s c_retval;\n" % (ret[0])
|
c_return = " %s c_retval;\n" % (ret[0])
|
||||||
if file == "python_accessor" and ret[2] != None:
|
if file == "python_accessor" and ret[2] != None:
|
||||||
@ -342,9 +346,9 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
ret_convert = " py_retval = %s%sWrap((%s) c_retval);\n" % (p,n,c)
|
ret_convert = " py_retval = %s%sWrap((%s) c_retval);\n" % (p,n,c)
|
||||||
ret_convert = ret_convert + " return(py_retval);\n"
|
ret_convert = ret_convert + " return(py_retval);\n"
|
||||||
else:
|
else:
|
||||||
if skipped_types.has_key(ret[0]):
|
if ret[0] in skipped_types:
|
||||||
return 0
|
return 0
|
||||||
if unknown_types.has_key(ret[0]):
|
if ret[0] in unknown_types:
|
||||||
lst = unknown_types[ret[0]]
|
lst = unknown_types[ret[0]]
|
||||||
lst.append(name)
|
lst.append(name)
|
||||||
else:
|
else:
|
||||||
@ -381,7 +385,7 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
output.write(" return(NULL);\n")
|
output.write(" return(NULL);\n")
|
||||||
if c_convert != "":
|
if c_convert != "":
|
||||||
output.write(c_convert)
|
output.write(c_convert)
|
||||||
|
|
||||||
output.write(c_call)
|
output.write(c_call)
|
||||||
output.write(ret_convert)
|
output.write(ret_convert)
|
||||||
output.write("}\n\n")
|
output.write("}\n\n")
|
||||||
@ -398,18 +402,18 @@ def buildStubs():
|
|||||||
(parser, target) = getparser()
|
(parser, target) = getparser()
|
||||||
parser.feed(data)
|
parser.feed(data)
|
||||||
parser.close()
|
parser.close()
|
||||||
except IOError, msg:
|
except IOError as msg:
|
||||||
try:
|
try:
|
||||||
f = open("%s/../doc/libxslt-api.xml" % srcdir)
|
f = open("%s/../doc/libxslt-api.xml" % srcdir)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
(parser, target) = getparser()
|
(parser, target) = getparser()
|
||||||
parser.feed(data)
|
parser.feed(data)
|
||||||
parser.close()
|
parser.close()
|
||||||
except IOError, msg:
|
except IOError as msg:
|
||||||
print "../doc/libxslt-api.xml", ":", msg
|
print("../doc/libxslt-api.xml", ":", msg)
|
||||||
|
|
||||||
n = len(functions.keys())
|
n = len(list(functions.keys()))
|
||||||
print "Found %d functions in libxslt-api.xml" % (n)
|
print("Found %d functions in libxslt-api.xml" % (n))
|
||||||
|
|
||||||
py_types['pythonObject'] = ('O', "pythonObject", "pythonObject",
|
py_types['pythonObject'] = ('O', "pythonObject", "pythonObject",
|
||||||
"pythonObject", "libxml_")
|
"pythonObject", "libxml_")
|
||||||
@ -419,12 +423,12 @@ def buildStubs():
|
|||||||
(parser, target) = getparser()
|
(parser, target) = getparser()
|
||||||
parser.feed(data)
|
parser.feed(data)
|
||||||
parser.close()
|
parser.close()
|
||||||
except IOError, msg:
|
except IOError as msg:
|
||||||
print "libxslt-python-api.xml", ":", msg
|
print("libxslt-python-api.xml", ":", msg)
|
||||||
|
|
||||||
|
|
||||||
print "Found %d functions in libxslt-python-api.xml" % (
|
print("Found %d functions in libxslt-python-api.xml" % (
|
||||||
len(functions.keys()) - n)
|
len(list(functions.keys())) - n))
|
||||||
nb_wrap = 0
|
nb_wrap = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
@ -439,7 +443,7 @@ def buildStubs():
|
|||||||
wrapper.write("#include <libxslt/xsltconfig.h>\n")
|
wrapper.write("#include <libxslt/xsltconfig.h>\n")
|
||||||
wrapper.write("#include \"libxslt_wrap.h\"\n")
|
wrapper.write("#include \"libxslt_wrap.h\"\n")
|
||||||
wrapper.write("#include \"libxslt-py.h\"\n\n")
|
wrapper.write("#include \"libxslt-py.h\"\n\n")
|
||||||
for function in functions.keys():
|
for function in list(functions.keys()):
|
||||||
ret = print_function_wrapper(function, wrapper, export, include)
|
ret = print_function_wrapper(function, wrapper, export, include)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
failed = failed + 1
|
failed = failed + 1
|
||||||
@ -453,12 +457,12 @@ def buildStubs():
|
|||||||
export.close()
|
export.close()
|
||||||
wrapper.close()
|
wrapper.close()
|
||||||
|
|
||||||
print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
|
print("Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
|
||||||
failed, skipped)
|
failed, skipped))
|
||||||
print "Missing type converters:"
|
print("Missing type converters:")
|
||||||
for type in unknown_types.keys():
|
for type in list(unknown_types.keys()):
|
||||||
print "%s:%d " % (type, len(unknown_types[type])),
|
print("%s:%d " % (type, len(unknown_types[type])), end=' ')
|
||||||
print
|
print()
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
@ -533,55 +537,55 @@ def nameFixup(name, classe, type, file):
|
|||||||
l = len(classe)
|
l = len(classe)
|
||||||
if name[0:l] == listname:
|
if name[0:l] == listname:
|
||||||
func = name[l:]
|
func = name[l:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:12] == "xmlParserGet" and file == "python_accessor":
|
elif name[0:12] == "xmlParserGet" and file == "python_accessor":
|
||||||
func = name[12:]
|
func = name[12:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:12] == "xmlParserSet" and file == "python_accessor":
|
elif name[0:12] == "xmlParserSet" and file == "python_accessor":
|
||||||
func = name[12:]
|
func = name[12:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:10] == "xmlNodeGet" and file == "python_accessor":
|
elif name[0:10] == "xmlNodeGet" and file == "python_accessor":
|
||||||
func = name[10:]
|
func = name[10:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:18] == "xsltXPathParserGet" and file == "python_accessor":
|
elif name[0:18] == "xsltXPathParserGet" and file == "python_accessor":
|
||||||
func = name[18:]
|
func = name[18:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:12] == "xsltXPathGet" and file == "python_accessor":
|
elif name[0:12] == "xsltXPathGet" and file == "python_accessor":
|
||||||
func = name[12:]
|
func = name[12:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:16] == "xsltTransformGet" and file == "python_accessor":
|
elif name[0:16] == "xsltTransformGet" and file == "python_accessor":
|
||||||
func = name[16:]
|
func = name[16:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:16] == "xsltTransformSet" and file == "python_accessor":
|
elif name[0:16] == "xsltTransformSet" and file == "python_accessor":
|
||||||
func = name[13:]
|
func = name[13:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:17] == "xsltStylesheetGet" and file == "python_accessor":
|
elif name[0:17] == "xsltStylesheetGet" and file == "python_accessor":
|
||||||
func = name[17:]
|
func = name[17:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:17] == "xsltStylesheetSet" and file == "python_accessor":
|
elif name[0:17] == "xsltStylesheetSet" and file == "python_accessor":
|
||||||
func = name[14:]
|
func = name[14:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:l] == classe:
|
elif name[0:l] == classe:
|
||||||
func = name[l:]
|
func = name[l:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:7] == "libxml_":
|
elif name[0:7] == "libxml_":
|
||||||
func = name[7:]
|
func = name[7:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:8] == "libxslt_":
|
elif name[0:8] == "libxslt_":
|
||||||
func = name[8:]
|
func = name[8:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:6] == "xmlGet":
|
elif name[0:6] == "xmlGet":
|
||||||
func = name[6:]
|
func = name[6:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:3] == "xml":
|
elif name[0:3] == "xml":
|
||||||
func = name[3:]
|
func = name[3:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:7] == "xsltGet":
|
elif name[0:7] == "xsltGet":
|
||||||
func = name[7:]
|
func = name[7:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
elif name[0:4] == "xslt":
|
elif name[0:4] == "xslt":
|
||||||
func = name[4:]
|
func = name[4:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = re_str.lower(func[0:1]) + func[1:]
|
||||||
else:
|
else:
|
||||||
func = name
|
func = name
|
||||||
if func[0:5] == "xPath":
|
if func[0:5] == "xPath":
|
||||||
@ -598,6 +602,25 @@ def nameFixup(name, classe, type, file):
|
|||||||
func = "UTF8" + func[4:]
|
func = "UTF8" + func[4:]
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
def cmp_to_key(mycmp):
|
||||||
|
'Convert a cmp= function into a key= function'
|
||||||
|
class K(object):
|
||||||
|
def __init__(self, obj, *args):
|
||||||
|
self.obj = obj
|
||||||
|
def __lt__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) < 0
|
||||||
|
def __gt__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) > 0
|
||||||
|
def __eq__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) == 0
|
||||||
|
def __le__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) <= 0
|
||||||
|
def __ge__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) >= 0
|
||||||
|
def __ne__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) != 0
|
||||||
|
return K
|
||||||
|
|
||||||
def functionCompare(info1, info2):
|
def functionCompare(info1, info2):
|
||||||
(index1, func1, name1, ret1, args1, file1) = info1
|
(index1, func1, name1, ret1, args1, file1) = info1
|
||||||
(index2, func2, name2, ret2, args2, file2) = info2
|
(index2, func2, name2, ret2, args2, file2) = info2
|
||||||
@ -620,7 +643,7 @@ def writeDoc(name, args, indent, output):
|
|||||||
if functions[name][0] == None or functions[name][0] == "":
|
if functions[name][0] == None or functions[name][0] == "":
|
||||||
return
|
return
|
||||||
val = functions[name][0]
|
val = functions[name][0]
|
||||||
val = string.replace(val, "NULL", "None")
|
val = val.replace("NULL", "None")
|
||||||
output.write(indent)
|
output.write(indent)
|
||||||
output.write('"""')
|
output.write('"""')
|
||||||
while len(val) > 60:
|
while len(val) > 60:
|
||||||
@ -628,7 +651,7 @@ def writeDoc(name, args, indent, output):
|
|||||||
val = val[1:]
|
val = val[1:]
|
||||||
continue
|
continue
|
||||||
str = val[0:60]
|
str = val[0:60]
|
||||||
i = string.rfind(str, " ")
|
i = str.rfind(" ")
|
||||||
if i < 0:
|
if i < 0:
|
||||||
i = 60
|
i = 60
|
||||||
str = val[0:i]
|
str = val[0:i]
|
||||||
@ -659,9 +682,9 @@ def buildWrappers():
|
|||||||
global classes_destructors
|
global classes_destructors
|
||||||
|
|
||||||
function_classes["None"] = []
|
function_classes["None"] = []
|
||||||
for type in classes_type.keys():
|
for type in list(classes_type.keys()):
|
||||||
function_classes[classes_type[type][2]] = []
|
function_classes[classes_type[type][2]] = []
|
||||||
|
|
||||||
#
|
#
|
||||||
# Build the list of C types to look for ordered to start with
|
# Build the list of C types to look for ordered to start with
|
||||||
# primary classes
|
# primary classes
|
||||||
@ -671,23 +694,23 @@ def buildWrappers():
|
|||||||
for classe in primary_classes:
|
for classe in primary_classes:
|
||||||
classes_list.append(classe)
|
classes_list.append(classe)
|
||||||
classes_processed[classe] = ()
|
classes_processed[classe] = ()
|
||||||
for type in classes_type.keys():
|
for type in list(classes_type.keys()):
|
||||||
tinfo = classes_type[type]
|
tinfo = classes_type[type]
|
||||||
if tinfo[2] == classe:
|
if tinfo[2] == classe:
|
||||||
ctypes.append(type)
|
ctypes.append(type)
|
||||||
ctypes_processed[type] = ()
|
ctypes_processed[type] = ()
|
||||||
for type in classes_type.keys():
|
for type in list(classes_type.keys()):
|
||||||
if ctypes_processed.has_key(type):
|
if type in ctypes_processed:
|
||||||
continue
|
continue
|
||||||
tinfo = classes_type[type]
|
tinfo = classes_type[type]
|
||||||
if not classes_processed.has_key(tinfo[2]):
|
if tinfo[2] not in classes_processed:
|
||||||
classes_list.append(tinfo[2])
|
classes_list.append(tinfo[2])
|
||||||
classes_processed[tinfo[2]] = ()
|
classes_processed[tinfo[2]] = ()
|
||||||
|
|
||||||
ctypes.append(type)
|
ctypes.append(type)
|
||||||
ctypes_processed[type] = ()
|
ctypes_processed[type] = ()
|
||||||
|
|
||||||
for name in functions.keys():
|
for name in list(functions.keys()):
|
||||||
found = 0
|
found = 0
|
||||||
(desc, ret, args, file) = functions[name]
|
(desc, ret, args, file) = functions[name]
|
||||||
for type in ctypes:
|
for type in ctypes:
|
||||||
@ -725,9 +748,9 @@ def buildWrappers():
|
|||||||
txt.write(" Generated Classes for libxslt-python\n\n")
|
txt.write(" Generated Classes for libxslt-python\n\n")
|
||||||
|
|
||||||
txt.write("#\n# Global functions of the module\n#\n\n")
|
txt.write("#\n# Global functions of the module\n#\n\n")
|
||||||
if function_classes.has_key("None"):
|
if "None" in function_classes:
|
||||||
flist = function_classes["None"]
|
flist = function_classes["None"]
|
||||||
flist.sort(functionCompare)
|
flist.sort(key=cmp_to_key(functionCompare))
|
||||||
oldfile = ""
|
oldfile = ""
|
||||||
for info in flist:
|
for info in flist:
|
||||||
(index, func, name, ret, args, file) = info
|
(index, func, name, ret, args, file) = info
|
||||||
@ -747,12 +770,12 @@ def buildWrappers():
|
|||||||
writeDoc(name, args, ' ', classes)
|
writeDoc(name, args, ' ', classes)
|
||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if classes_type.has_key(arg[1]):
|
if arg[1] in classes_type:
|
||||||
classes.write(" if %s == None: %s__o = None\n" %
|
classes.write(" if %s == None: %s__o = None\n" %
|
||||||
(arg[0], arg[0]))
|
(arg[0], arg[0]))
|
||||||
classes.write(" else: %s__o = %s%s\n" %
|
classes.write(" else: %s__o = %s%s\n" %
|
||||||
(arg[0], arg[0], classes_type[arg[1]][0]))
|
(arg[0], arg[0], classes_type[arg[1]][0]))
|
||||||
elif libxml2_classes_type.has_key(arg[1]):
|
elif arg[1] in libxml2_classes_type:
|
||||||
classes.write(" if %s == None: %s__o = None\n" %
|
classes.write(" if %s == None: %s__o = None\n" %
|
||||||
(arg[0], arg[0]))
|
(arg[0], arg[0]))
|
||||||
classes.write(" else: %s__o = %s%s\n" %
|
classes.write(" else: %s__o = %s%s\n" %
|
||||||
@ -767,19 +790,19 @@ def buildWrappers():
|
|||||||
if n != 0:
|
if n != 0:
|
||||||
classes.write(", ")
|
classes.write(", ")
|
||||||
classes.write("%s" % arg[0])
|
classes.write("%s" % arg[0])
|
||||||
if classes_type.has_key(arg[1]):
|
if arg[1] in classes_type:
|
||||||
classes.write("__o")
|
classes.write("__o")
|
||||||
if libxml2_classes_type.has_key(arg[1]):
|
if arg[1] in libxml2_classes_type:
|
||||||
classes.write("__o")
|
classes.write("__o")
|
||||||
n = n + 1
|
n = n + 1
|
||||||
classes.write(")\n")
|
classes.write(")\n")
|
||||||
if ret[0] != "void":
|
if ret[0] != "void":
|
||||||
if classes_type.has_key(ret[0]):
|
if ret[0] in classes_type:
|
||||||
classes.write(" if ret == None: return None\n")
|
classes.write(" if ret == None: return None\n")
|
||||||
classes.write(" return ")
|
classes.write(" return ")
|
||||||
classes.write(classes_type[ret[0]][1] % ("ret"))
|
classes.write(classes_type[ret[0]][1] % ("ret"))
|
||||||
classes.write("\n")
|
classes.write("\n")
|
||||||
elif libxml2_classes_type.has_key(ret[0]):
|
elif ret[0] in libxml2_classes_type:
|
||||||
classes.write(" if ret == None: return None\n")
|
classes.write(" if ret == None: return None\n")
|
||||||
classes.write(" return libxml2.")
|
classes.write(" return libxml2.")
|
||||||
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"))
|
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"))
|
||||||
@ -793,7 +816,7 @@ def buildWrappers():
|
|||||||
if classname == "None":
|
if classname == "None":
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if classes_ancestor.has_key(classname):
|
if classname in classes_ancestor:
|
||||||
txt.write("\n\nClass %s(%s)\n" % (classname,
|
txt.write("\n\nClass %s(%s)\n" % (classname,
|
||||||
classes_ancestor[classname]))
|
classes_ancestor[classname]))
|
||||||
classes.write("class %s(%s):\n" % (classname,
|
classes.write("class %s(%s):\n" % (classname,
|
||||||
@ -814,7 +837,7 @@ def buildWrappers():
|
|||||||
classes.write(" def __init__(self, _obj=None):\n")
|
classes.write(" def __init__(self, _obj=None):\n")
|
||||||
classes.write(" if _obj != None:self._o = _obj;return\n")
|
classes.write(" if _obj != None:self._o = _obj;return\n")
|
||||||
classes.write(" self._o = None\n\n")
|
classes.write(" self._o = None\n\n")
|
||||||
if classes_destructors.has_key(classname):
|
if classname in classes_destructors:
|
||||||
classes.write(" def __del__(self):\n")
|
classes.write(" def __del__(self):\n")
|
||||||
if classes_destructors[classname] == "pass":
|
if classes_destructors[classname] == "pass":
|
||||||
classes.write(" pass\n")
|
classes.write(" pass\n")
|
||||||
@ -824,7 +847,7 @@ def buildWrappers():
|
|||||||
classes_destructors[classname])
|
classes_destructors[classname])
|
||||||
classes.write(" self._o = None\n\n")
|
classes.write(" self._o = None\n\n")
|
||||||
flist = function_classes[classname]
|
flist = function_classes[classname]
|
||||||
flist.sort(functionCompare)
|
flist.sort(key=cmp_to_key(functionCompare))
|
||||||
oldfile = ""
|
oldfile = ""
|
||||||
for info in flist:
|
for info in flist:
|
||||||
(index, func, name, ret, args, file) = info
|
(index, func, name, ret, args, file) = info
|
||||||
@ -850,13 +873,13 @@ def buildWrappers():
|
|||||||
writeDoc(name, args, ' ', classes)
|
writeDoc(name, args, ' ', classes)
|
||||||
n = 0
|
n = 0
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if classes_type.has_key(arg[1]):
|
if arg[1] in classes_type:
|
||||||
if n != index:
|
if n != index:
|
||||||
classes.write(" if %s == None: %s__o = None\n" %
|
classes.write(" if %s == None: %s__o = None\n" %
|
||||||
(arg[0], arg[0]))
|
(arg[0], arg[0]))
|
||||||
classes.write(" else: %s__o = %s%s\n" %
|
classes.write(" else: %s__o = %s%s\n" %
|
||||||
(arg[0], arg[0], classes_type[arg[1]][0]))
|
(arg[0], arg[0], classes_type[arg[1]][0]))
|
||||||
elif libxml2_classes_type.has_key(arg[1]):
|
elif arg[1] in libxml2_classes_type:
|
||||||
classes.write(" if %s == None: %s__o = None\n" %
|
classes.write(" if %s == None: %s__o = None\n" %
|
||||||
(arg[0], arg[0]))
|
(arg[0], arg[0]))
|
||||||
classes.write(" else: %s__o = %s%s\n" %
|
classes.write(" else: %s__o = %s%s\n" %
|
||||||
@ -874,30 +897,30 @@ def buildWrappers():
|
|||||||
classes.write(", ")
|
classes.write(", ")
|
||||||
if n != index:
|
if n != index:
|
||||||
classes.write("%s" % arg[0])
|
classes.write("%s" % arg[0])
|
||||||
if classes_type.has_key(arg[1]):
|
if arg[1] in classes_type:
|
||||||
classes.write("__o")
|
classes.write("__o")
|
||||||
elif libxml2_classes_type.has_key(arg[1]):
|
elif arg[1] in libxml2_classes_type:
|
||||||
classes.write("__o")
|
classes.write("__o")
|
||||||
else:
|
else:
|
||||||
classes.write("self")
|
classes.write("self")
|
||||||
if classes_type.has_key(arg[1]):
|
if arg[1] in classes_type:
|
||||||
classes.write(classes_type[arg[1]][0])
|
classes.write(classes_type[arg[1]][0])
|
||||||
elif libxml2_classes_type.has_key(arg[1]):
|
elif arg[1] in libxml2_classes_type:
|
||||||
classes.write(libxml2_classes_type[arg[1]][0])
|
classes.write(libxml2_classes_type[arg[1]][0])
|
||||||
n = n + 1
|
n = n + 1
|
||||||
classes.write(")\n")
|
classes.write(")\n")
|
||||||
if ret[0] != "void":
|
if ret[0] != "void":
|
||||||
if classes_type.has_key(ret[0]):
|
if ret[0] in classes_type:
|
||||||
classes.write(" if ret == None: return None\n")
|
classes.write(" if ret == None: return None\n")
|
||||||
classes.write(" return ")
|
classes.write(" return ")
|
||||||
classes.write(classes_type[ret[0]][1] % ("ret"))
|
classes.write(classes_type[ret[0]][1] % ("ret"))
|
||||||
classes.write("\n")
|
classes.write("\n")
|
||||||
elif libxml2_classes_type.has_key(ret[0]):
|
elif ret[0] in libxml2_classes_type:
|
||||||
classes.write(" if ret == None: return None\n")
|
classes.write(" if ret == None: return None\n")
|
||||||
classes.write(" return libxml2.")
|
classes.write(" return libxml2.")
|
||||||
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"))
|
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"))
|
||||||
classes.write("\n")
|
classes.write("\n")
|
||||||
elif converter_type.has_key(ret[0]):
|
elif ret[0] in converter_type:
|
||||||
classes.write(" if ret == None: return None\n")
|
classes.write(" if ret == None: return None\n")
|
||||||
classes.write(" return ")
|
classes.write(" return ")
|
||||||
classes.write(converter_type[ret[0]] % ("ret"))
|
classes.write(converter_type[ret[0]] % ("ret"))
|
||||||
@ -909,13 +932,13 @@ def buildWrappers():
|
|||||||
#
|
#
|
||||||
# Generate enum constants
|
# Generate enum constants
|
||||||
#
|
#
|
||||||
for type,enum in enums.items():
|
for type,enum in list(enums.items()):
|
||||||
classes.write("# %s\n" % type)
|
classes.write("# %s\n" % type)
|
||||||
items = enum.items()
|
items = list(enum.items())
|
||||||
items.sort(lambda i1,i2: cmp(long(i1[1]),long(i2[1])))
|
items.sort(key=lambda x: x[1])
|
||||||
for name,value in items:
|
for name,value in items:
|
||||||
classes.write("%s = %s\n" % (name,value))
|
classes.write("%s = %s\n" % (name,value))
|
||||||
classes.write("\n");
|
classes.write("\n");
|
||||||
|
|
||||||
txt.close()
|
txt.close()
|
||||||
classes.close()
|
classes.close()
|
||||||
|
@ -15,6 +15,16 @@
|
|||||||
#include <libxml/xinclude.h>
|
#include <libxml/xinclude.h>
|
||||||
#include <libxml/xpointer.h>
|
#include <libxml/xpointer.h>
|
||||||
|
|
||||||
|
PyObject* PY_IMPORT_INT(long ival);
|
||||||
|
PyObject* PY_IMPORT_STRING(const char *u);
|
||||||
|
PyObject* PY_IMPORT_CPTRD(void *po, const char *na, void *de);
|
||||||
|
int PY_IMPORT_LONG_CHECK(PyObject *o);
|
||||||
|
int PY_IMPORT_STRING_CHECK(PyObject *o);
|
||||||
|
int PY_IMPORT_CPTR_CHECK(PyObject *o);
|
||||||
|
Py_ssize_t PY_IMPORT_STRING_GET_SIZE(PyObject *o);
|
||||||
|
char* PY_IMPORT_AS_STRING(PyObject *o);
|
||||||
|
long PY_IMPORT_AS_LONG(PyObject *io);
|
||||||
|
|
||||||
#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
|
#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
|
||||||
(((PyxmlNode_Object *)(v))->obj))
|
(((PyxmlNode_Object *)(v))->obj))
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
/* snprintf emulation taken from http://stackoverflow.com/a/8712996/1956010 */
|
/* snprintf emulation taken from http://stackoverflow.com/a/8712996/1956010 */
|
||||||
#if _MSC_VER < 1900
|
#if _MSC_VER < 1900
|
||||||
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define vsnprintf c99_vsnprintf
|
#define vsnprintf c99_vsnprintf
|
||||||
@ -77,9 +78,8 @@ libxslt_xsltStylesheetPtrWrap(xsltStylesheetPtr style) {
|
|||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return(Py_None);
|
return(Py_None);
|
||||||
}
|
}
|
||||||
ret = PyCObject_FromVoidPtrAndDesc((void *) style,
|
ret = PY_IMPORT_CPTRD((void *) style,
|
||||||
(char *)"xsltStylesheetPtr", NULL);
|
(char *)"xsltStylesheetPtr", NULL);
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +94,9 @@ libxslt_xsltTransformContextPtrWrap(xsltTransformContextPtr ctxt) {
|
|||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return(Py_None);
|
return(Py_None);
|
||||||
}
|
}
|
||||||
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
|
ret = PY_IMPORT_CPTRD((void *) ctxt,
|
||||||
(char *)"xsltTransformContextPtr", NULL);
|
(char *)"xsltTransformContextPtr", NULL);
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +111,8 @@ libxslt_xsltElemPreCompPtrWrap(xsltElemPreCompPtr ctxt) {
|
|||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return(Py_None);
|
return(Py_None);
|
||||||
}
|
}
|
||||||
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
|
ret = PY_IMPORT_CPTRD((void *) ctxt,
|
||||||
(char *)"xsltElemPreCompPtr", NULL);
|
(char *)"xsltElemPreCompPtr", NULL);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,8 +129,7 @@ libxslt_xsltGetTransformContextHashCode(PyObject *self ATTRIBUTE_UNUSED, PyObjec
|
|||||||
|
|
||||||
tctxt = (xsltTransformContextPtr) PytransformCtxt_Get(py_tctxt);
|
tctxt = (xsltTransformContextPtr) PytransformCtxt_Get(py_tctxt);
|
||||||
hash_code = (ptrdiff_t) tctxt;
|
hash_code = (ptrdiff_t) tctxt;
|
||||||
|
ret = PY_IMPORT_INT(hash_code);
|
||||||
ret = PyInt_FromLong(hash_code);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,8 @@ libxslt_xsltGetStylesheetHashCode(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg
|
|||||||
style = (xsltStylesheetPtr) Pystylesheet_Get(py_style);
|
style = (xsltStylesheetPtr) Pystylesheet_Get(py_style);
|
||||||
hash_code = (ptrdiff_t) style;
|
hash_code = (ptrdiff_t) style;
|
||||||
|
|
||||||
ret = PyInt_FromLong(hash_code);
|
ret = PY_IMPORT_INT(hash_code);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +621,8 @@ libxslt_xsltSetLoaderFunc(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
|
|||||||
pythonDocLoaderObject = loader;
|
pythonDocLoaderObject = loader;
|
||||||
xsltSetLoaderFunc(pythonDocLoaderFuncWrapper);
|
xsltSetLoaderFunc(pythonDocLoaderFuncWrapper);
|
||||||
|
|
||||||
py_retval = PyInt_FromLong(0);
|
py_retval = PY_IMPORT_INT(0);
|
||||||
|
|
||||||
return(py_retval);
|
return(py_retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,12 +715,23 @@ libxslt_xsltApplyStylesheetUser(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
|
|||||||
const char *tmp;
|
const char *tmp;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
tmp = PyUnicode_AsUTF8AndSize(name, &size);
|
||||||
|
#else
|
||||||
|
|
||||||
tmp = PyString_AS_STRING(name);
|
tmp = PyString_AS_STRING(name);
|
||||||
size = PyString_GET_SIZE(name);
|
size = PyString_GET_SIZE(name);
|
||||||
|
#endif
|
||||||
params[j * 2] = (char *) xmlCharStrndup(tmp, size);
|
params[j * 2] = (char *) xmlCharStrndup(tmp, size);
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
if (PyUnicode_Check(value)) {
|
||||||
|
tmp = PyUnicode_AsUTF8AndSize(value, &size);
|
||||||
|
#else
|
||||||
if (PyString_Check(value)) {
|
if (PyString_Check(value)) {
|
||||||
tmp = PyString_AS_STRING(value);
|
tmp = PyString_AS_STRING(value);
|
||||||
size = PyString_GET_SIZE(value);
|
size = PyString_GET_SIZE(value);
|
||||||
|
#endif
|
||||||
params[(j * 2) + 1] = (char *)
|
params[(j * 2) + 1] = (char *)
|
||||||
xmlCharStrndup(tmp, size);
|
xmlCharStrndup(tmp, size);
|
||||||
} else {
|
} else {
|
||||||
@ -789,12 +802,22 @@ libxslt_xsltApplyStylesheet(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
|
|||||||
const char *tmp;
|
const char *tmp;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
tmp = PyUnicode_AsUTF8AndSize(name, &size);
|
||||||
|
#else
|
||||||
tmp = PyString_AS_STRING(name);
|
tmp = PyString_AS_STRING(name);
|
||||||
size = PyString_GET_SIZE(name);
|
size = PyString_GET_SIZE(name);
|
||||||
|
#endif
|
||||||
params[j * 2] = (char *) xmlCharStrndup(tmp, size);
|
params[j * 2] = (char *) xmlCharStrndup(tmp, size);
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
if (PyUnicode_Check(value)) {
|
||||||
|
tmp = PyUnicode_AsUTF8AndSize(value, &size);
|
||||||
|
#else
|
||||||
if (PyString_Check(value)) {
|
if (PyString_Check(value)) {
|
||||||
tmp = PyString_AS_STRING(value);
|
tmp = PyString_AS_STRING(value);
|
||||||
size = PyString_GET_SIZE(value);
|
size = PyString_GET_SIZE(value);
|
||||||
|
#endif
|
||||||
params[(j * 2) + 1] = (char *)
|
params[(j * 2) + 1] = (char *)
|
||||||
xmlCharStrndup(tmp, size);
|
xmlCharStrndup(tmp, size);
|
||||||
} else {
|
} else {
|
||||||
@ -859,11 +882,19 @@ libxslt_xsltSaveResultToString(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
|
|||||||
if(size)
|
if(size)
|
||||||
{
|
{
|
||||||
buffer[size] = '\0';
|
buffer[size] = '\0';
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
py_retval = PyUnicode_DecodeUTF8((char *) buffer, size, NULL);
|
||||||
|
#else
|
||||||
py_retval = PyString_FromString((char *) buffer);
|
py_retval = PyString_FromString((char *) buffer);
|
||||||
|
#endif
|
||||||
xmlFree(buffer);
|
xmlFree(buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
py_retval = PyUnicode_DecodeUTF8("", 0, NULL);
|
||||||
|
#else
|
||||||
py_retval = PyString_FromString("");
|
py_retval = PyString_FromString("");
|
||||||
|
#endif
|
||||||
return(py_retval);
|
return(py_retval);
|
||||||
FAIL:
|
FAIL:
|
||||||
return(0);
|
return(0);
|
||||||
@ -1197,19 +1228,52 @@ static PyMethodDef libxsltMethods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MERGED_MODULES
|
#ifdef MERGED_MODULES
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
extern PyObject* PyInit_libxml2mod(void);
|
||||||
|
#else
|
||||||
extern void initlibxml2mod(void);
|
extern void initlibxml2mod(void);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
static struct PyModuleDef moduledef = {
|
||||||
|
PyModuleDef_HEAD_INIT,
|
||||||
|
"libxsltmod",
|
||||||
|
NULL,
|
||||||
|
-1,
|
||||||
|
libxsltMethods,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyObject* PyInit_libxsltmod(void){
|
||||||
|
#else
|
||||||
void initlibxsltmod(void) {
|
void initlibxsltmod(void) {
|
||||||
|
#endif
|
||||||
static int initialized = 0;
|
static int initialized = 0;
|
||||||
|
PyObject *m;
|
||||||
|
|
||||||
#ifdef MERGED_MODULES
|
#ifdef MERGED_MODULES
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyInit_libxml2mod();
|
||||||
|
#else
|
||||||
initlibxml2mod();
|
initlibxml2mod();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (initialized != 0)
|
if (initialized != 0)
|
||||||
return;
|
return;
|
||||||
Py_InitModule((char *)"libxsltmod", libxsltMethods);
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
m = PyModule_Create(&moduledef);
|
||||||
|
#else
|
||||||
|
m = Py_InitModule((char *)"libxsltmod", libxsltMethods);
|
||||||
|
#endif
|
||||||
|
if (!m)
|
||||||
|
return;
|
||||||
initialized = 1;
|
initialized = 1;
|
||||||
/*
|
/*
|
||||||
* Specific XSLT initializations
|
* Specific XSLT initializations
|
||||||
@ -1222,6 +1286,7 @@ void initlibxsltmod(void) {
|
|||||||
* Register the EXSLT extensions and the test module
|
* Register the EXSLT extensions and the test module
|
||||||
*/
|
*/
|
||||||
exsltRegisterAll();
|
exsltRegisterAll();
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
return m;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/python -u
|
#!/usr/bin/python -u
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import libxml2
|
import libxml2
|
||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
@ -14,7 +16,7 @@ result = style.applyStylesheet(doc, None)
|
|||||||
style.saveResultToFilename("foo", result, 0)
|
style.saveResultToFilename("foo", result, 0)
|
||||||
stringval = style.saveResultToString(result)
|
stringval = style.saveResultToString(result)
|
||||||
if (len(stringval) != 68):
|
if (len(stringval) != 68):
|
||||||
print "Error in saveResultToString"
|
print("Error in saveResultToString")
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
style.freeStylesheet()
|
style.freeStylesheet()
|
||||||
doc.freeDoc()
|
doc.freeDoc()
|
||||||
@ -23,8 +25,8 @@ result.freeDoc()
|
|||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxslt.cleanup()
|
libxslt.cleanup()
|
||||||
if libxml2.debugMemory(1) == 0:
|
if libxml2.debugMemory(1) == 0:
|
||||||
print "OK"
|
print("OK")
|
||||||
else:
|
else:
|
||||||
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
||||||
libxml2.dumpMemory()
|
libxml2.dumpMemory()
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/python -u
|
#!/usr/bin/python -u
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import libxml2
|
import libxml2
|
||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
@ -44,14 +46,14 @@ expect="""<?xml version="1.0"?>
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if stringval != expect:
|
if stringval != expect:
|
||||||
print "Exslt processing failed"
|
print("Exslt processing failed")
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
|
||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxslt.cleanup()
|
libxslt.cleanup()
|
||||||
if libxml2.debugMemory(1) == 0:
|
if libxml2.debugMemory(1) == 0:
|
||||||
print "OK"
|
print("OK")
|
||||||
else:
|
else:
|
||||||
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
||||||
libxml2.dumpMemory()
|
libxml2.dumpMemory()
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
#!/usr/bin/python -u
|
#!/usr/bin/python -u
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
import StringIO
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
import StringIO as io
|
||||||
|
else:
|
||||||
|
import io
|
||||||
|
|
||||||
import libxml2
|
import libxml2
|
||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxml2.debugMemory(1)
|
libxml2.debugMemory(1)
|
||||||
@ -34,7 +42,7 @@ def transform_test(ctx, node, inst, comp):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
tctxt.insertNode().addContent('SUCCESS')
|
tctxt.insertNode().addContent('SUCCESS')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
styledoc = libxml2.parseDoc("""
|
styledoc = libxml2.parseDoc("""
|
||||||
@ -58,23 +66,23 @@ style.freeStylesheet()
|
|||||||
doc.freeDoc()
|
doc.freeDoc()
|
||||||
|
|
||||||
|
|
||||||
extensions = StringIO.StringIO()
|
extensions = io.StringIO()
|
||||||
libxslt.debugDumpExtensions(extensions)
|
libxslt.debugDumpExtensions(extensions)
|
||||||
|
|
||||||
if 0 and extensions.buf.find(EXT_URL) < 0:
|
if 0 and extensions.buf.find(EXT_URL) < 0:
|
||||||
print "Element extension not registered (or dumping broken)"
|
print("Element extension not registered (or dumping broken)")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
root = result.children
|
root = result.children
|
||||||
|
|
||||||
if root.name != "article":
|
if root.name != "article":
|
||||||
print "Unexpected root node name"
|
print("Unexpected root node name")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if root.content != "SUCCESS":
|
if root.content != "SUCCESS":
|
||||||
print "Unexpected root node content, extension function failed"
|
print("Unexpected root node content, extension function failed")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if insertNodeName != 'article':
|
if insertNodeName != 'article':
|
||||||
print "The function callback failed to access its context"
|
print("The function callback failed to access its context")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
result.dump(sys.stdout)
|
result.dump(sys.stdout)
|
||||||
@ -83,8 +91,8 @@ result.freeDoc()
|
|||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxslt.cleanup()
|
libxslt.cleanup()
|
||||||
if libxml2.debugMemory(1) == 0:
|
if libxml2.debugMemory(1) == 0:
|
||||||
print "OK"
|
print("OK")
|
||||||
else:
|
else:
|
||||||
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
||||||
libxml2.dumpMemory()
|
libxml2.dumpMemory()
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/python -u
|
#!/usr/bin/python -u
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
import libxml2
|
import libxml2
|
||||||
@ -46,13 +48,13 @@ doc.freeDoc()
|
|||||||
|
|
||||||
root = result.children
|
root = result.children
|
||||||
if root.name != "article":
|
if root.name != "article":
|
||||||
print "Unexpected root node name"
|
print("Unexpected root node name")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if root.content != "SUCCESS":
|
if root.content != "SUCCESS":
|
||||||
print "Unexpected root node content, extension function failed"
|
print("Unexpected root node content, extension function failed")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if nodeName != 'article':
|
if nodeName != 'article':
|
||||||
print "The function callback failed to access its context"
|
print("The function callback failed to access its context")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
result.freeDoc()
|
result.freeDoc()
|
||||||
@ -60,8 +62,8 @@ result.freeDoc()
|
|||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxslt.cleanup()
|
libxslt.cleanup()
|
||||||
if libxml2.debugMemory(1) == 0:
|
if libxml2.debugMemory(1) == 0:
|
||||||
print "OK"
|
print("OK")
|
||||||
else:
|
else:
|
||||||
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
||||||
libxml2.dumpMemory()
|
libxml2.dumpMemory()
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
# bindings, not complete yet and shows up the things missing
|
# bindings, not complete yet and shows up the things missing
|
||||||
# from the existing python interfaces
|
# from the existing python interfaces
|
||||||
#
|
#
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
@ -41,7 +43,7 @@ def endTimer(msg):
|
|||||||
global endtime
|
global endtime
|
||||||
|
|
||||||
endtime = time.time()
|
endtime = time.time()
|
||||||
print "%s took %d ms" % (msg, (endtime - begin) * 1000)
|
print("%s took %d ms" % (msg, (endtime - begin) * 1000))
|
||||||
|
|
||||||
def xsltProcess(doc, cur, filename):
|
def xsltProcess(doc, cur, filename):
|
||||||
global timing
|
global timing
|
||||||
@ -72,7 +74,7 @@ def xsltProcess(doc, cur, filename):
|
|||||||
# if ctxt == None:
|
# if ctxt == None:
|
||||||
# return
|
# return
|
||||||
if profile:
|
if profile:
|
||||||
print "TODO: Profiling not yet supported"
|
print("TODO: Profiling not yet supported")
|
||||||
else:
|
else:
|
||||||
res = cur.applyStylesheet(doc, params)
|
res = cur.applyStylesheet(doc, params)
|
||||||
if timing:
|
if timing:
|
||||||
@ -82,7 +84,7 @@ def xsltProcess(doc, cur, filename):
|
|||||||
endTimer("Applying stylesheet")
|
endTimer("Applying stylesheet")
|
||||||
doc.freeDoc()
|
doc.freeDoc()
|
||||||
if res == None:
|
if res == None:
|
||||||
print "no result for %s" % (filename)
|
print("no result for %s" % (filename))
|
||||||
return
|
return
|
||||||
if noout != 0:
|
if noout != 0:
|
||||||
res.freeDoc()
|
res.freeDoc()
|
||||||
@ -97,35 +99,35 @@ def xsltProcess(doc, cur, filename):
|
|||||||
endTimer("Saving result")
|
endTimer("Saving result")
|
||||||
res.freeDoc()
|
res.freeDoc()
|
||||||
else:
|
else:
|
||||||
print "TODO: xsltRunStylesheet not yet mapped"
|
print("TODO: xsltRunStylesheet not yet mapped")
|
||||||
|
|
||||||
def usage(name = 'pyxsltproc'):
|
def usage(name = 'pyxsltproc'):
|
||||||
print "Usage: %s [options] stylesheet file [file ...]" % (name)
|
print("Usage: %s [options] stylesheet file [file ...]" % (name))
|
||||||
print "a reimplementation of xsltproc(1) on top of libxslt-python"
|
print("a reimplementation of xsltproc(1) on top of libxslt-python")
|
||||||
print " Options:"
|
print(" Options:")
|
||||||
print "\t--version or -V: show the version of libxml and libxslt used"
|
print("\t--version or -V: show the version of libxml and libxslt used")
|
||||||
print "\t--verbose or -v: show logs of what's happening"
|
print("\t--verbose or -v: show logs of what's happening")
|
||||||
print "\t--output file or -o file: save to a given file"
|
print("\t--output file or -o file: save to a given file")
|
||||||
print "\t--timing: display the time used"
|
print("\t--timing: display the time used")
|
||||||
print "\t--repeat: run the transformation 20 times"
|
print("\t--repeat: run the transformation 20 times")
|
||||||
print "\t--debug: dump the tree of the result instead"
|
print("\t--debug: dump the tree of the result instead")
|
||||||
print "\t--novalid skip the Dtd loading phase"
|
print("\t--novalid skip the Dtd loading phase")
|
||||||
print "\t--noout: do not dump the result"
|
print("\t--noout: do not dump the result")
|
||||||
print "\t--maxdepth val : increase the maximum depth"
|
print("\t--maxdepth val : increase the maximum depth")
|
||||||
print "\t--html: the input document is(are) an HTML file(s)"
|
print("\t--html: the input document is(are) an HTML file(s)")
|
||||||
print "\t--param name value : pass a (parameter,value) pair"
|
print("\t--param name value : pass a (parameter,value) pair")
|
||||||
print "\t value is an XPath expression."
|
print("\t value is an XPath expression.")
|
||||||
print "\t string values must be quoted like \"'string'\""
|
print("\t string values must be quoted like \"'string'\"")
|
||||||
print "\t or use stringparam to avoid it"
|
print("\t or use stringparam to avoid it")
|
||||||
print "\t--stringparam name value : pass a (parameter,string value) pair"
|
print("\t--stringparam name value : pass a (parameter,string value) pair")
|
||||||
print "\t--nonet refuse to fetch DTDs or entities over network"
|
print("\t--nonet refuse to fetch DTDs or entities over network")
|
||||||
print "\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES"
|
print("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES")
|
||||||
print "\t otherwise XML Catalogs starting from "
|
print("\t otherwise XML Catalogs starting from ")
|
||||||
print "\t file:///etc/xml/catalog are activated by default"
|
print("\t file:///etc/xml/catalog are activated by default")
|
||||||
print "\t--xinclude : do XInclude processing on document input"
|
print("\t--xinclude : do XInclude processing on document input")
|
||||||
print "\t--profile or --norman : dump profiling information "
|
print("\t--profile or --norman : dump profiling information ")
|
||||||
print "\nProject libxslt home page: http://xmlsoft.org/XSLT/"
|
print("\nProject libxslt home page: http://xmlsoft.org/XSLT/")
|
||||||
print "To report bugs and get help: http://xmlsoft.org/XSLT/bugs.html"
|
print("To report bugs and get help: http://xmlsoft.org/XSLT/bugs.html")
|
||||||
|
|
||||||
def main(args = None):
|
def main(args = None):
|
||||||
global debug
|
global debug
|
||||||
@ -148,7 +150,7 @@ def main(args = None):
|
|||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
if len(args) <= 0:
|
if len(args) <= 0:
|
||||||
usage(sys.argv[0])
|
usage(sys.argv[0])
|
||||||
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(args):
|
while i < len(args):
|
||||||
@ -163,10 +165,10 @@ def main(args = None):
|
|||||||
debug = 1
|
debug = 1
|
||||||
elif args[i] == "-verbose" or args[i] == "--verbose" or \
|
elif args[i] == "-verbose" or args[i] == "--verbose" or \
|
||||||
args[i] == "-v":
|
args[i] == "-v":
|
||||||
print "TODO: xsltSetGenericDebugFunc() mapping missing"
|
print("TODO: xsltSetGenericDebugFunc() mapping missing")
|
||||||
elif args[i] == "-version" or args[i] == "--version" or \
|
elif args[i] == "-version" or args[i] == "--version" or \
|
||||||
args[i] == "-V":
|
args[i] == "-V":
|
||||||
print "TODO: version information mapping missing"
|
print("TODO: version information mapping missing")
|
||||||
elif args[i] == "-verbose" or args[i] == "--verbose" or \
|
elif args[i] == "-verbose" or args[i] == "--verbose" or \
|
||||||
args[i] == "-v":
|
args[i] == "-v":
|
||||||
if repeat == 0:
|
if repeat == 0:
|
||||||
@ -174,14 +176,14 @@ def main(args = None):
|
|||||||
else:
|
else:
|
||||||
repeat = 100
|
repeat = 100
|
||||||
elif args[i] == "-novalid" or args[i] == "--novalid":
|
elif args[i] == "-novalid" or args[i] == "--novalid":
|
||||||
print "TODO: xmlLoadExtDtdDefaultValue mapping missing"
|
print("TODO: xmlLoadExtDtdDefaultValue mapping missing")
|
||||||
novalid = 1
|
novalid = 1
|
||||||
elif args[i] == "-noout" or args[i] == "--noout":
|
elif args[i] == "-noout" or args[i] == "--noout":
|
||||||
noout = 1
|
noout = 1
|
||||||
elif args[i] == "-html" or args[i] == "--html":
|
elif args[i] == "-html" or args[i] == "--html":
|
||||||
html = 1
|
html = 1
|
||||||
elif args[i] == "-nonet" or args[i] == "--nonet":
|
elif args[i] == "-nonet" or args[i] == "--nonet":
|
||||||
print "TODO: xmlSetExternalEntityLoader mapping missing"
|
print("TODO: xmlSetExternalEntityLoader mapping missing")
|
||||||
nonet = 1
|
nonet = 1
|
||||||
elif args[i] == "-catalogs" or args[i] == "--catalogs":
|
elif args[i] == "-catalogs" or args[i] == "--catalogs":
|
||||||
try:
|
try:
|
||||||
@ -191,7 +193,7 @@ def main(args = None):
|
|||||||
if catalogs != none:
|
if catalogs != none:
|
||||||
libxml2.xmlLoadCatalogs(catalogs)
|
libxml2.xmlLoadCatalogs(catalogs)
|
||||||
else:
|
else:
|
||||||
print "Variable $SGML_CATALOG_FILES not set"
|
print("Variable $SGML_CATALOG_FILES not set")
|
||||||
elif args[i] == "-xinclude" or args[i] == "--xinclude":
|
elif args[i] == "-xinclude" or args[i] == "--xinclude":
|
||||||
xinclude = 1
|
xinclude = 1
|
||||||
libxslt.setXIncludeDefault(1)
|
libxslt.setXIncludeDefault(1)
|
||||||
@ -204,17 +206,17 @@ def main(args = None):
|
|||||||
params[args[i]] = "'%s'" % (args[i + 1])
|
params[args[i]] = "'%s'" % (args[i + 1])
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elif args[i] == "-maxdepth" or args[i] == "--maxdepth":
|
elif args[i] == "-maxdepth" or args[i] == "--maxdepth":
|
||||||
print "TODO: xsltMaxDepth mapping missing"
|
print("TODO: xsltMaxDepth mapping missing")
|
||||||
else:
|
else:
|
||||||
print "Unknown option %s" % (args[i])
|
print("Unknown option %s" % (args[i]))
|
||||||
usage()
|
usage()
|
||||||
return(3)
|
return(3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
libxml2.lineNumbersDefault(1)
|
libxml2.lineNumbersDefault(1)
|
||||||
libxml2.substituteEntitiesDefault(1)
|
libxml2.substituteEntitiesDefault(1)
|
||||||
# TODO: xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS
|
# TODO: xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS
|
||||||
@ -247,7 +249,7 @@ def main(args = None):
|
|||||||
if timing:
|
if timing:
|
||||||
endTimer("Parsing stylesheet %s" % (args[i]))
|
endTimer("Parsing stylesheet %s" % (args[i]))
|
||||||
if style == None:
|
if style == None:
|
||||||
print "cannot parse %s" % (args[i])
|
print("cannot parse %s" % (args[i]))
|
||||||
cur = None
|
cur = None
|
||||||
errorno = 4
|
errorno = 4
|
||||||
done = 1
|
done = 1
|
||||||
@ -273,7 +275,7 @@ def main(args = None):
|
|||||||
else:
|
else:
|
||||||
doc = libxml2.parseFile(args[i])
|
doc = libxml2.parseFile(args[i])
|
||||||
if doc == None:
|
if doc == None:
|
||||||
print "unable to parse %s" % (args[i])
|
print("unable to parse %s" % (args[i]))
|
||||||
errorno = 6
|
errorno = 6
|
||||||
i = i + 1
|
i = i + 1
|
||||||
continue
|
continue
|
||||||
@ -292,7 +294,7 @@ if __name__ == "__main__":
|
|||||||
# Memory debug specific
|
# Memory debug specific
|
||||||
libxslt.cleanup()
|
libxslt.cleanup()
|
||||||
if libxml2.debugMemory(1) != 0:
|
if libxml2.debugMemory(1) != 0:
|
||||||
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
|
print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
|
||||||
libxml2.dumpMemory()
|
libxml2.dumpMemory()
|
||||||
|
|
||||||
sys.exit(errorno)
|
sys.exit(errorno)
|
||||||
|
202
python/types.c
202
python/types.c
@ -13,6 +13,102 @@ xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL,
|
|||||||
#include "libxml_wrap.h"
|
#include "libxml_wrap.h"
|
||||||
#include <libxml/xpathInternals.h>
|
#include <libxml/xpathInternals.h>
|
||||||
|
|
||||||
|
/* Helper functions */
|
||||||
|
|
||||||
|
PyObject* PY_IMPORT_INT(long ival){
|
||||||
|
PyObject *ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyLong_FromLong(ival);
|
||||||
|
#else
|
||||||
|
ret=PyInt_FromLong(ival);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject* PY_IMPORT_STRING(const char *u){
|
||||||
|
PyObject *ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyUnicode_FromString(u);
|
||||||
|
#else
|
||||||
|
ret=PyString_FromString(u);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject* PY_IMPORT_CPTRD(void *po,
|
||||||
|
const char *na,
|
||||||
|
void *de){
|
||||||
|
PyObject *ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyCapsule_New(po,na,de);
|
||||||
|
#else
|
||||||
|
ret=PyCObject_FromVoidPtrAndDesc(po,(void *)na,de);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PY_IMPORT_LONG_CHECK(PyObject *o){
|
||||||
|
int ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyLong_Check(o);
|
||||||
|
#else
|
||||||
|
ret=PyInt_Check(o);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PY_IMPORT_STRING_CHECK(PyObject *o){
|
||||||
|
int ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyUnicode_Check(o);
|
||||||
|
#else
|
||||||
|
ret=PyString_Check(o);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PY_IMPORT_CPTR_CHECK(PyObject *o){
|
||||||
|
int ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyCapsule_CheckExact(o);
|
||||||
|
#else
|
||||||
|
ret=PyCObject_Check(o);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_ssize_t PY_IMPORT_STRING_GET_SIZE(PyObject *o){
|
||||||
|
Py_ssize_t ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyUnicode_GET_SIZE(o);
|
||||||
|
#else
|
||||||
|
ret=PyString_GET_SIZE(o);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* PY_IMPORT_AS_STRING(PyObject *o){
|
||||||
|
char *ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyUnicode_AS_DATA(o);
|
||||||
|
#else
|
||||||
|
ret=PyString_AS_STRING(o);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
long PY_IMPORT_AS_LONG(PyObject *io){
|
||||||
|
long ret;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
ret=PyLong_AS_LONG(io);
|
||||||
|
#else
|
||||||
|
ret=PyInt_AS_LONG(io);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
libxml_intWrap(int val)
|
libxml_intWrap(int val)
|
||||||
{
|
{
|
||||||
@ -21,7 +117,7 @@ libxml_intWrap(int val)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("libxml_intWrap: val = %d\n", val);
|
printf("libxml_intWrap: val = %d\n", val);
|
||||||
#endif
|
#endif
|
||||||
ret = PyInt_FromLong((long) val);
|
ret = PY_IMPORT_INT((long) val);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +129,9 @@ libxml_longWrap(long val)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("libxml_longWrap: val = %ld\n", val);
|
printf("libxml_longWrap: val = %ld\n", val);
|
||||||
#endif
|
#endif
|
||||||
ret = PyInt_FromLong(val);
|
|
||||||
|
ret = PY_IMPORT_INT(val);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +160,7 @@ libxml_charPtrWrap(char *str)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
/* TODO: look at deallocation */
|
||||||
ret = PyString_FromString(str);
|
ret = PY_IMPORT_STRING(str);
|
||||||
xmlFree(str);
|
xmlFree(str);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -79,8 +177,7 @@ libxml_charPtrConstWrap(const char *str)
|
|||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
ret = PY_IMPORT_STRING(str);
|
||||||
ret = PyString_FromString(str);
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +194,7 @@ libxml_xmlCharPtrWrap(xmlChar * str)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
/* TODO: look at deallocation */
|
||||||
ret = PyString_FromString((char *) str);
|
ret = PY_IMPORT_STRING((char *) str);
|
||||||
xmlFree(str);
|
xmlFree(str);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -115,7 +212,7 @@ libxml_xmlCharPtrConstWrap(const xmlChar * str)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
/* TODO: look at deallocation */
|
||||||
ret = PyString_FromString((char *) str);
|
ret = PY_IMPORT_STRING((char *) str);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +229,7 @@ libxml_constcharPtrWrap(const char *str)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
/* TODO: look at deallocation */
|
||||||
ret = PyString_FromString(str);
|
ret = PY_IMPORT_STRING((char *) str);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +246,7 @@ libxml_constxmlCharPtrWrap(const xmlChar * str)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
/* TODO: look at deallocation */
|
||||||
ret = PyString_FromString((char *) str);
|
ret = PY_IMPORT_STRING((char *) str);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +263,7 @@ libxml_xmlDocPtrWrap(xmlDocPtr doc)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
/* TODO: look at deallocation */
|
/* TODO: look at deallocation */
|
||||||
ret =
|
ret = PY_IMPORT_CPTRD((void *) doc, (char *) "xmlDocPtr",
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr",
|
|
||||||
NULL);
|
NULL);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -185,8 +281,9 @@ libxml_xmlNodePtrWrap(xmlNodePtr node)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr",
|
PY_IMPORT_CPTRD((void *) node, (char *) "xmlNodePtr",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,8 +300,9 @@ libxml_xmlURIPtrWrap(xmlURIPtr uri)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) uri, (char *) "xmlURIPtr",
|
PY_IMPORT_CPTRD((void *) uri, (char *) "xmlURIPtr",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +319,7 @@ libxml_xmlNsPtrWrap(xmlNsPtr ns)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) ns, (char *) "xmlNsPtr",
|
PY_IMPORT_CPTRD((void *) ns, (char *) "xmlNsPtr",
|
||||||
NULL);
|
NULL);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -239,8 +337,9 @@ libxml_xmlAttrPtrWrap(xmlAttrPtr attr)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) attr, (char *) "xmlAttrPtr",
|
PY_IMPORT_CPTRD((void *) attr, (char *) "xmlAttrPtr",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,8 +356,9 @@ libxml_xmlAttributePtrWrap(xmlAttributePtr attr)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) attr,
|
PY_IMPORT_CPTRD((void *) attr,
|
||||||
(char *) "xmlAttributePtr", NULL);
|
(char *) "xmlAttributePtr", NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +375,7 @@ libxml_xmlElementPtrWrap(xmlElementPtr elem)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) elem,
|
PY_IMPORT_CPTRD((void *) elem,
|
||||||
(char *) "xmlElementPtr", NULL);
|
(char *) "xmlElementPtr", NULL);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -292,9 +392,11 @@ libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt)
|
|||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) ctxt,
|
PY_IMPORT_CPTRD((void *) ctxt,
|
||||||
(char *) "xmlXPathContextPtr", NULL);
|
(char *) "xmlXPathContextPtr", NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +412,7 @@ libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt)
|
|||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
|
ret = PY_IMPORT_CPTRD((void *) ctxt,
|
||||||
(char *) "xmlXPathParserContextPtr",
|
(char *) "xmlXPathParserContextPtr",
|
||||||
NULL);
|
NULL);
|
||||||
return (ret);
|
return (ret);
|
||||||
@ -329,7 +431,7 @@ libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) ctxt,
|
PY_IMPORT_CPTRD((void *) ctxt,
|
||||||
(char *) "xmlParserCtxtPtr", NULL);
|
(char *) "xmlParserCtxtPtr", NULL);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -404,9 +506,9 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
|
|||||||
node = obj->nodesetval->nodeTab[i];
|
node = obj->nodesetval->nodeTab[i];
|
||||||
if (node->type == XML_NAMESPACE_DECL) {
|
if (node->type == XML_NAMESPACE_DECL) {
|
||||||
PyObject *ns =
|
PyObject *ns =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) node,
|
PY_IMPORT_CPTRD((void *) node,
|
||||||
(char *) "xmlNsPtr",
|
(char *) "xmlNsPtr",
|
||||||
libxml_xmlXPathDestructNsNode);
|
libxml_xmlXPathDestructNsNode);
|
||||||
PyList_SetItem(ret, i, ns);
|
PyList_SetItem(ret, i, ns);
|
||||||
/* make sure the xmlNsPtr is not destroyed now */
|
/* make sure the xmlNsPtr is not destroyed now */
|
||||||
obj->nodesetval->nodeTab[i] = NULL;
|
obj->nodesetval->nodeTab[i] = NULL;
|
||||||
@ -417,13 +519,13 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XPATH_BOOLEAN:
|
case XPATH_BOOLEAN:
|
||||||
ret = PyInt_FromLong((long) obj->boolval);
|
ret = PY_IMPORT_INT((long) obj->boolval);
|
||||||
break;
|
break;
|
||||||
case XPATH_NUMBER:
|
case XPATH_NUMBER:
|
||||||
ret = PyFloat_FromDouble(obj->floatval);
|
ret = PyFloat_FromDouble(obj->floatval);
|
||||||
break;
|
break;
|
||||||
case XPATH_STRING:
|
case XPATH_STRING:
|
||||||
ret = PyString_FromString((char *) obj->stringval);
|
ret = PY_IMPORT_STRING((char *) obj->stringval);
|
||||||
break;
|
break;
|
||||||
case XPATH_POINT:
|
case XPATH_POINT:
|
||||||
case XPATH_RANGE:
|
case XPATH_RANGE:
|
||||||
@ -453,11 +555,9 @@ libxml_xmlXPathObjectPtrConvert(PyObject * obj)
|
|||||||
if PyFloat_Check
|
if PyFloat_Check
|
||||||
(obj) {
|
(obj) {
|
||||||
ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
|
ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
|
||||||
} else if PyInt_Check(obj) {
|
} else if (PY_IMPORT_LONG_CHECK (obj)) {
|
||||||
|
ret = xmlXPathNewFloat((double) PY_IMPORT_AS_LONG(obj));
|
||||||
ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
|
} else if (PyBool_Check (obj)) {
|
||||||
|
|
||||||
} else if PyBool_Check (obj) {
|
|
||||||
|
|
||||||
if (obj == Py_True) {
|
if (obj == Py_True) {
|
||||||
ret = xmlXPathNewBoolean(1);
|
ret = xmlXPathNewBoolean(1);
|
||||||
@ -465,16 +565,13 @@ libxml_xmlXPathObjectPtrConvert(PyObject * obj)
|
|||||||
else {
|
else {
|
||||||
ret = xmlXPathNewBoolean(0);
|
ret = xmlXPathNewBoolean(0);
|
||||||
}
|
}
|
||||||
|
} else if (PY_IMPORT_STRING_CHECK(obj)) {
|
||||||
} else if PyString_Check
|
|
||||||
(obj) {
|
|
||||||
xmlChar *str;
|
xmlChar *str;
|
||||||
|
|
||||||
str = xmlStrndup((const xmlChar *) PyString_AS_STRING(obj),
|
str = xmlStrndup((const xmlChar *) PY_IMPORT_AS_STRING(obj),
|
||||||
PyString_GET_SIZE(obj));
|
PY_IMPORT_STRING_GET_SIZE(obj));
|
||||||
ret = xmlXPathWrapString(str);
|
ret = xmlXPathWrapString(str);
|
||||||
} else if PyList_Check
|
} else if (PyList_Check(obj)) {
|
||||||
(obj) {
|
|
||||||
int i;
|
int i;
|
||||||
PyObject *node;
|
PyObject *node;
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
@ -488,17 +585,29 @@ libxml_xmlXPathObjectPtrConvert(PyObject * obj)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
cur = NULL;
|
cur = NULL;
|
||||||
if (PyCObject_Check(node)) {
|
if (PY_IMPORT_CPTR_CHECK(node)) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Got a CObject\n");
|
printf("Got a CObject\n");
|
||||||
#endif
|
#endif
|
||||||
cur = PyxmlNode_Get(node);
|
cur = PyxmlNode_Get(node);
|
||||||
} else if (PyInstance_Check(node)) {
|
}
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
else if ((PyObject_HasAttrString(node, (char *) "_o")) &&
|
||||||
|
(PyObject_HasAttrString(node, (char *) "get_doc"))) {
|
||||||
|
PyObject *wrapper;
|
||||||
|
|
||||||
|
wrapper = PyObject_GetAttrString(node, (char *) "_o");
|
||||||
|
if (wrapper != NULL)
|
||||||
|
cur = PyxmlNode_Get(wrapper);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
else if (PyInstance_Check(node)) {
|
||||||
PyInstanceObject *inst = (PyInstanceObject *) node;
|
PyInstanceObject *inst = (PyInstanceObject *) node;
|
||||||
PyObject *name = inst->in_class->cl_name;
|
PyObject *name = inst->in_class->cl_name;
|
||||||
|
|
||||||
if PyString_Check
|
if PyString_Check
|
||||||
(name) {
|
(name) {
|
||||||
|
|
||||||
char *type = PyString_AS_STRING(name);
|
char *type = PyString_AS_STRING(name);
|
||||||
PyObject *wrapper;
|
PyObject *wrapper;
|
||||||
|
|
||||||
@ -509,8 +618,10 @@ libxml_xmlXPathObjectPtrConvert(PyObject * obj)
|
|||||||
cur = PyxmlNode_Get(wrapper);
|
cur = PyxmlNode_Get(wrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Unknown object in Python return list\n");
|
printf("Unknown object in Python return list\n");
|
||||||
#endif
|
#endif
|
||||||
@ -542,7 +653,7 @@ libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) catal,
|
PY_IMPORT_CPTRD((void *) catal,
|
||||||
(char *) "xmlCatalogPtr", NULL);
|
(char *) "xmlCatalogPtr", NULL);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
@ -560,8 +671,9 @@ libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) buffer,
|
PY_IMPORT_CPTRD((void *) buffer,
|
||||||
(char *) "xmlOutputBufferPtr", NULL);
|
(char *) "xmlOutputBufferPtr", NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,8 +690,9 @@ libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) buffer,
|
PY_IMPORT_CPTRD((void *) buffer,
|
||||||
(char *) "xmlParserInputBufferPtr", NULL);
|
(char *) "xmlParserInputBufferPtr", NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,7 +709,8 @@ libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
ret =
|
ret =
|
||||||
PyCObject_FromVoidPtrAndDesc((void *) regexp,
|
PY_IMPORT_CPTRD((void *) regexp,
|
||||||
(char *) "xmlRegexpPtr", NULL);
|
(char *) "xmlRegexpPtr", NULL);
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user