1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-08-04 12:22:09 +03:00

release of 1.1.24 syntactic cleanup (Martin) Daniel

* configure.in doc/*: release of 1.1.24
* python/generator.py: syntactic cleanup (Martin)
Daniel

svn path=/trunk/; revision=1473
This commit is contained in:
Daniel Veillard
2008-05-13 15:52:56 +00:00
parent 970091425f
commit ec5c63b43a
32 changed files with 1866 additions and 1707 deletions

View File

@@ -321,7 +321,7 @@ def print_function_wrapper(name, output, export, include):
if skip_function(name) == 1:
return 0
c_call = "";
c_call = ""
format=""
format_args=""
c_args=""
@@ -341,11 +341,11 @@ def print_function_wrapper(name, output, export, include):
c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0])
c_convert = c_convert + \
" %s = (%s) Py%s_Get(pyobj_%s);\n" % (arg[0],
arg[1], t, arg[0]);
arg[1], t, arg[0])
else:
format_args = format_args + ", &%s" % (arg[0])
if c_call != "":
c_call = c_call + ", ";
c_call = c_call + ", "
c_call = c_call + "%s" % (arg[0])
else:
if skipped_types.has_key(arg[1]):
@@ -361,16 +361,16 @@ def print_function_wrapper(name, output, export, include):
if ret[0] == 'void':
if file == "python_accessor":
if args[1][1] == "char *" or args[1][1] == "xmlChar *":
c_call = "\n if (%s->%s != NULL) xmlFree(%s->%s);\n" % (
args[0][0], args[1][0], args[0][0], args[1][0])
c_call = c_call + " %s->%s = xmlStrdup((const xmlChar *)%s);\n" % (args[0][0],
args[1][0], args[1][0])
else:
c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
args[1][0])
if args[1][1] == "char *" or args[1][1] == "xmlChar *":
c_call = "\n if (%s->%s != NULL) xmlFree(%s->%s);\n" % (
args[0][0], args[1][0], args[0][0], args[1][0])
c_call = c_call + " %s->%s = xmlStrdup((const xmlChar *)%s);\n" % (args[0][0],
args[1][0], args[1][0])
else:
c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
args[1][0])
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"
elif py_types.has_key(ret[0]):
(f, t, n, c, p) = py_types[ret[0]]
@@ -378,7 +378,7 @@ def print_function_wrapper(name, output, export, include):
if file == "python_accessor" and ret[2] != None:
c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2])
else:
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 = ret_convert + " return(py_retval);\n"
elif py_return_types.has_key(ret[0]):
@@ -387,7 +387,7 @@ def print_function_wrapper(name, output, export, include):
if file == "python_accessor" and ret[2] != None:
c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2])
else:
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 = ret_convert + " return(py_retval);\n"
else:
@@ -416,7 +416,7 @@ def print_function_wrapper(name, output, export, include):
output.write("libxslt_%s(PyObject *self ATTRIBUTE_UNUSED," % (name))
output.write(" PyObject *args")
if format == "":
output.write(" ATTRIBUTE_UNUSED")
output.write(" ATTRIBUTE_UNUSED")
output.write(") {\n")
if ret[0] != 'void':
output.write(" PyObject *py_retval;\n")
@@ -442,20 +442,20 @@ def buildStubs():
global unknown_types
try:
f = open("libxslt-api.xml")
data = f.read()
(parser, target) = getparser()
parser.feed(data)
parser.close()
f = open("libxslt-api.xml")
data = f.read()
(parser, target) = getparser()
parser.feed(data)
parser.close()
except IOError, msg:
try:
f = open("../doc/libxslt-api.xml")
data = f.read()
(parser, target) = getparser()
parser.feed(data)
parser.close()
except IOError, msg:
print "../doc/libxslt-api.xml", ":", msg
try:
f = open("../doc/libxslt-api.xml")
data = f.read()
(parser, target) = getparser()
parser.feed(data)
parser.close()
except IOError, msg:
print "../doc/libxslt-api.xml", ":", msg
n = len(functions.keys())
print "Found %d functions in libxslt-api.xml" % (n)
@@ -463,17 +463,17 @@ def buildStubs():
py_types['pythonObject'] = ('O', "pythonObject", "pythonObject",
"pythonObject", "libxml_")
try:
f = open("libxslt-python-api.xml")
data = f.read()
(parser, target) = getparser()
parser.feed(data)
parser.close()
f = open("libxslt-python-api.xml")
data = f.read()
(parser, target) = getparser()
parser.feed(data)
parser.close()
except IOError, msg:
print "libxslt-python-api.xml", ":", msg
print "libxslt-python-api.xml", ":", msg
print "Found %d functions in libxslt-python-api.xml" % (
len(functions.keys()) - n)
len(functions.keys()) - n)
nb_wrap = 0
failed = 0
skipped = 0
@@ -489,24 +489,24 @@ def buildStubs():
wrapper.write("#include \"libxslt_wrap.h\"\n")
wrapper.write("#include \"libxslt-py.h\"\n\n")
for function in functions.keys():
ret = print_function_wrapper(function, wrapper, export, include)
if ret < 0:
failed = failed + 1
del functions[function]
if ret == 0:
skipped = skipped + 1
del functions[function]
if ret == 1:
nb_wrap = nb_wrap + 1
ret = print_function_wrapper(function, wrapper, export, include)
if ret < 0:
failed = failed + 1
del functions[function]
if ret == 0:
skipped = skipped + 1
del functions[function]
if ret == 1:
nb_wrap = nb_wrap + 1
include.close()
export.close()
wrapper.close()
print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
failed, skipped);
failed, skipped)
print "Missing type converters:"
for type in unknown_types.keys():
print "%s:%d " % (type, len(unknown_types[type])),
print "%s:%d " % (type, len(unknown_types[type])),
print
#######################################################################
@@ -669,23 +669,23 @@ def writeDoc(name, args, indent, output):
if functions[name][0] == None or functions[name][0] == "":
return
val = functions[name][0]
val = string.replace(val, "NULL", "None");
val = string.replace(val, "NULL", "None")
output.write(indent)
output.write('"""')
while len(val) > 60:
if val[0] == " ":
val = val[1:]
continue
val = val[1:]
continue
str = val[0:60]
i = string.rfind(str, " ");
i = string.rfind(str, " ")
if i < 0:
i = 60
str = val[0:i]
val = val[i:]
output.write(str)
output.write('\n ');
output.write('\n ')
output.write(indent)
output.write(val);
output.write(val)
output.write('"""\n')
def buildWrappers():
@@ -709,8 +709,8 @@ def buildWrappers():
function_classes["None"] = []
for type in 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
# primary classes
@@ -718,56 +718,56 @@ def buildWrappers():
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:
ctypes.append(type)
ctypes_processed[type] = ()
classes_list.append(classe)
classes_processed[classe] = ()
for type in classes_type.keys():
tinfo = classes_type[type]
if tinfo[2] == classe:
ctypes.append(type)
ctypes_processed[type] = ()
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] = ()
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] = ()
for name in functions.keys():
found = 0;
(desc, ret, args, file) = functions[name]
for type in ctypes:
classe = classes_type[type][2]
found = 0
(desc, ret, args, file) = functions[name]
for type in ctypes:
classe = classes_type[type][2]
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)
function_classes[classe].append(info)
elif name[0:4] == "xslt" 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) >= 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:
continue
if name[0:8] == "xmlXPath":
continue
if name[0:6] == "xmlStr":
continue
if name[0:10] == "xmlCharStr":
continue
func = nameFixup(name, "None", file, file)
info = (0, func, name, ret, args, file)
function_classes['None'].append(info)
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)
function_classes[classe].append(info)
elif name[0:4] == "xslt" 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) >= 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:
continue
if name[0:8] == "xmlXPath":
continue
if name[0:6] == "xmlStr":
continue
if name[0:10] == "xmlCharStr":
continue
func = nameFixup(name, "None", file, file)
info = (0, func, name, ret, args, file)
function_classes['None'].append(info)
classes = open("libxsltclass.py", "w")
txt = open("libxsltclass.txt", "w")
@@ -775,185 +775,185 @@ def buildWrappers():
txt.write("#\n# Global functions of the module\n#\n\n")
if function_classes.has_key("None"):
flist = function_classes["None"]
flist.sort(functionCompare)
oldfile = ""
for info in flist:
(index, func, name, ret, args, file) = info
if file != oldfile:
classes.write("#\n# Functions from module %s\n#\n\n" % file)
txt.write("\n# functions from module %s\n" % file)
oldfile = file
classes.write("def %s(" % func)
txt.write("%s()\n" % func);
n = 0
for arg in args:
if n != 0:
classes.write(", ")
classes.write("%s" % arg[0])
n = n + 1
classes.write("):\n")
writeDoc(name, args, ' ', classes);
flist = function_classes["None"]
flist.sort(functionCompare)
oldfile = ""
for info in flist:
(index, func, name, ret, args, file) = info
if file != oldfile:
classes.write("#\n# Functions from module %s\n#\n\n" % file)
txt.write("\n# functions from module %s\n" % file)
oldfile = file
classes.write("def %s(" % func)
txt.write("%s()\n" % func)
n = 0
for arg in args:
if n != 0:
classes.write(", ")
classes.write("%s" % arg[0])
n = n + 1
classes.write("):\n")
writeDoc(name, args, ' ', classes)
for arg in args:
if classes_type.has_key(arg[1]):
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0], classes_type[arg[1]][0]))
elif libxml2_classes_type.has_key(arg[1]):
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0], libxml2_classes_type[arg[1]][0]))
if ret[0] != "void":
classes.write(" ret = ");
else:
classes.write(" ");
classes.write("libxsltmod.%s(" % name)
n = 0
for arg in args:
if n != 0:
classes.write(", ");
classes.write("%s" % arg[0])
if classes_type.has_key(arg[1]):
classes.write("__o");
if libxml2_classes_type.has_key(arg[1]):
classes.write("__o");
n = n + 1
classes.write(")\n");
if ret[0] != "void":
if classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n");
classes.write(" return ");
classes.write(classes_type[ret[0]][1] % ("ret"));
classes.write("\n");
elif libxml2_classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n");
classes.write(" return libxml2.");
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"));
classes.write("\n");
else:
classes.write(" return ret\n");
classes.write("\n");
for arg in args:
if classes_type.has_key(arg[1]):
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0], classes_type[arg[1]][0]))
elif libxml2_classes_type.has_key(arg[1]):
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0], libxml2_classes_type[arg[1]][0]))
if ret[0] != "void":
classes.write(" ret = ")
else:
classes.write(" ")
classes.write("libxsltmod.%s(" % name)
n = 0
for arg in args:
if n != 0:
classes.write(", ")
classes.write("%s" % arg[0])
if classes_type.has_key(arg[1]):
classes.write("__o")
if libxml2_classes_type.has_key(arg[1]):
classes.write("__o")
n = n + 1
classes.write(")\n")
if ret[0] != "void":
if classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n")
classes.write(" return ")
classes.write(classes_type[ret[0]][1] % ("ret"))
classes.write("\n")
elif libxml2_classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n")
classes.write(" return libxml2.")
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"))
classes.write("\n")
else:
classes.write(" return ret\n")
classes.write("\n")
txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
for classname in classes_list:
if classname == "None":
pass
else:
if classes_ancestor.has_key(classname):
txt.write("\n\nClass %s(%s)\n" % (classname,
classes_ancestor[classname]))
classes.write("class %s(%s):\n" % (classname,
classes_ancestor[classname]))
classes.write(" def __init__(self, _obj=None):\n")
classes.write(" self._o = None\n")
classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
classes_ancestor[classname]))
if classes_ancestor[classname] == "xmlCore" or \
classes_ancestor[classname] == "xmlNode":
classes.write(" def __repr__(self):\n")
format = "%s:%%s" % (classname)
classes.write(" return \"%s\" %% (self.name)\n\n" % (
format))
else:
txt.write("Class %s()\n" % (classname))
classes.write("class %s:\n" % (classname))
classes.write(" def __init__(self, _obj=None):\n")
classes.write(" if _obj != None:self._o = _obj;return\n")
classes.write(" self._o = None\n\n");
if classes_destructors.has_key(classname):
classes.write(" def __del__(self):\n")
if classes_destructors[classname] == "pass":
classes.write(" pass\n")
else:
classes.write(" if self._o != None:\n")
classes.write(" libxsltmod.%s(self._o)\n" %
classes_destructors[classname]);
classes.write(" self._o = None\n\n");
flist = function_classes[classname]
flist.sort(functionCompare)
oldfile = ""
for info in flist:
(index, func, name, ret, args, file) = info
if file != oldfile:
if file == "python_accessor":
classes.write(" # accessors for %s\n" % (classname))
txt.write(" # accessors\n")
else:
classes.write(" #\n")
classes.write(" # %s functions from module %s\n" % (
classname, file))
txt.write("\n # functions from module %s\n" % file)
classes.write(" #\n\n")
oldfile = file
classes.write(" def %s(self" % func)
txt.write(" %s()\n" % func);
n = 0
for arg in args:
if n != index:
classes.write(", %s" % arg[0])
n = n + 1
classes.write("):\n")
writeDoc(name, args, ' ', classes);
n = 0
for arg in args:
if classes_type.has_key(arg[1]):
if n != index:
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0], classes_type[arg[1]][0]))
elif libxml2_classes_type.has_key(arg[1]):
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0],
libxml2_classes_type[arg[1]][0]))
n = n + 1
if ret[0] != "void":
classes.write(" ret = ");
else:
classes.write(" ");
classes.write("libxsltmod.%s(" % name)
n = 0
for arg in args:
if n != 0:
classes.write(", ");
if n != index:
classes.write("%s" % arg[0])
if classes_type.has_key(arg[1]):
classes.write("__o");
elif libxml2_classes_type.has_key(arg[1]):
classes.write("__o");
else:
classes.write("self");
if classes_type.has_key(arg[1]):
classes.write(classes_type[arg[1]][0])
elif libxml2_classes_type.has_key(arg[1]):
classes.write(libxml2_classes_type[arg[1]][0])
n = n + 1
classes.write(")\n");
if ret[0] != "void":
if classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n");
classes.write(" return ");
classes.write(classes_type[ret[0]][1] % ("ret"));
classes.write("\n");
elif libxml2_classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n");
classes.write(" return libxml2.");
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"));
classes.write("\n");
elif converter_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n");
classes.write(" return ");
classes.write(converter_type[ret[0]] % ("ret"));
classes.write("\n");
else:
classes.write(" return ret\n");
classes.write("\n");
if classname == "None":
pass
else:
if classes_ancestor.has_key(classname):
txt.write("\n\nClass %s(%s)\n" % (classname,
classes_ancestor[classname]))
classes.write("class %s(%s):\n" % (classname,
classes_ancestor[classname]))
classes.write(" def __init__(self, _obj=None):\n")
classes.write(" self._o = None\n")
classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
classes_ancestor[classname]))
if classes_ancestor[classname] == "xmlCore" or \
classes_ancestor[classname] == "xmlNode":
classes.write(" def __repr__(self):\n")
format = "%s:%%s" % (classname)
classes.write(" return \"%s\" %% (self.name)\n\n" % (
format))
else:
txt.write("Class %s()\n" % (classname))
classes.write("class %s:\n" % (classname))
classes.write(" def __init__(self, _obj=None):\n")
classes.write(" if _obj != None:self._o = _obj;return\n")
classes.write(" self._o = None\n\n")
if classes_destructors.has_key(classname):
classes.write(" def __del__(self):\n")
if classes_destructors[classname] == "pass":
classes.write(" pass\n")
else:
classes.write(" if self._o != None:\n")
classes.write(" libxsltmod.%s(self._o)\n" %
classes_destructors[classname])
classes.write(" self._o = None\n\n")
flist = function_classes[classname]
flist.sort(functionCompare)
oldfile = ""
for info in flist:
(index, func, name, ret, args, file) = info
if file != oldfile:
if file == "python_accessor":
classes.write(" # accessors for %s\n" % (classname))
txt.write(" # accessors\n")
else:
classes.write(" #\n")
classes.write(" # %s functions from module %s\n" % (
classname, file))
txt.write("\n # functions from module %s\n" % file)
classes.write(" #\n\n")
oldfile = file
classes.write(" def %s(self" % func)
txt.write(" %s()\n" % func)
n = 0
for arg in args:
if n != index:
classes.write(", %s" % arg[0])
n = n + 1
classes.write("):\n")
writeDoc(name, args, ' ', classes)
n = 0
for arg in args:
if classes_type.has_key(arg[1]):
if n != index:
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0], classes_type[arg[1]][0]))
elif libxml2_classes_type.has_key(arg[1]):
classes.write(" if %s == None: %s__o = None\n" %
(arg[0], arg[0]))
classes.write(" else: %s__o = %s%s\n" %
(arg[0], arg[0],
libxml2_classes_type[arg[1]][0]))
n = n + 1
if ret[0] != "void":
classes.write(" ret = ")
else:
classes.write(" ")
classes.write("libxsltmod.%s(" % name)
n = 0
for arg in args:
if n != 0:
classes.write(", ")
if n != index:
classes.write("%s" % arg[0])
if classes_type.has_key(arg[1]):
classes.write("__o")
elif libxml2_classes_type.has_key(arg[1]):
classes.write("__o")
else:
classes.write("self")
if classes_type.has_key(arg[1]):
classes.write(classes_type[arg[1]][0])
elif libxml2_classes_type.has_key(arg[1]):
classes.write(libxml2_classes_type[arg[1]][0])
n = n + 1
classes.write(")\n")
if ret[0] != "void":
if classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n")
classes.write(" return ")
classes.write(classes_type[ret[0]][1] % ("ret"))
classes.write("\n")
elif libxml2_classes_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n")
classes.write(" return libxml2.")
classes.write(libxml2_classes_type[ret[0]][1] % ("ret"))
classes.write("\n")
elif converter_type.has_key(ret[0]):
classes.write(" if ret == None: return None\n")
classes.write(" return ")
classes.write(converter_type[ret[0]] % ("ret"))
classes.write("\n")
else:
classes.write(" return ret\n")
classes.write("\n")
#
# Generate enum constants