Last active
August 29, 2015 14:14
-
-
Save novocaine/ae657bdbf0f25b81e52b to your computer and use it in GitHub Desktop.
patch libxslt 1.1.28 bindings to python 3 and fix on windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ur libxslt-1.1.28.old/libxslt/xsltlocale.h libxslt-1.1.28/libxslt/xsltlocale.h | |
--- libxslt-1.1.28.old/libxslt/xsltlocale.h 2012-09-04 16:26:24.000000000 +0100 | |
+++ libxslt-1.1.28/libxslt/xsltlocale.h 2015-01-22 15:57:16.524757800 +0000 | |
@@ -12,6 +12,7 @@ | |
#define __XML_XSLTLOCALE_H__ | |
#include <libxml/xmlstring.h> | |
+#include "xsltexports.h" | |
#ifdef XSLT_LOCALE_XLOCALE | |
@@ -49,10 +50,10 @@ | |
#endif | |
-xsltLocale xsltNewLocale(const xmlChar *langName); | |
-void xsltFreeLocale(xsltLocale locale); | |
-xsltLocaleChar *xsltStrxfrm(xsltLocale locale, const xmlChar *string); | |
-int xsltLocaleStrcmp(xsltLocale locale, const xsltLocaleChar *str1, const xsltLocaleChar *str2); | |
-void xsltFreeLocales(void); | |
+XSLTPUBFUN xsltLocale XSLTCALL xsltNewLocale(const xmlChar *langName); | |
+XSLTPUBFUN void XSLTCALL xsltFreeLocale(xsltLocale locale); | |
+XSLTPUBFUN xsltLocaleChar* XSLTCALL xsltStrxfrm(xsltLocale locale, const xmlChar *string); | |
+XSLTPUBFUN int XSLTCALL xsltLocaleStrcmp(xsltLocale locale, const xsltLocaleChar *str1, const xsltLocaleChar *str2); | |
+XSLTPUBFUN void XSLTCALL xsltFreeLocales(void); | |
#endif /* __XML_XSLTLOCALE_H__ */ | |
Only in libxslt-1.1.28/python: .libxslt.c.swp | |
diff -ur libxslt-1.1.28.old/python/generator.py libxslt-1.1.28/python/generator.py | |
--- libxslt-1.1.28.old/python/generator.py 2012-09-04 16:26:24.000000000 +0100 | |
+++ libxslt-1.1.28/python/generator.py 2015-01-21 15:02:29.482788300 +0000 | |
@@ -39,19 +39,19 @@ | |
def close(self): | |
if debug: | |
- print "close" | |
+ print("close") | |
def getmethodname(self): | |
return self._methodname | |
def data(self, text): | |
if debug: | |
- print "data %s" % text | |
+ print("data %s" % text) | |
self._data.append(text) | |
def start(self, tag, attrs): | |
if debug: | |
- print "start %s, %s" % (tag, attrs) | |
+ print("start %s, %s" % (tag, attrs)) | |
if tag == 'function': | |
self._data = [] | |
self.in_function = 1 | |
@@ -60,9 +60,9 @@ | |
self.function_descr = None | |
self.function_return = None | |
self.function_file = None | |
- if attrs.has_key('name'): | |
+ if 'name' in attrs: | |
self.function = attrs['name'] | |
- if attrs.has_key('file'): | |
+ if 'file' in attrs: | |
self.function_file = attrs['file'] | |
elif tag == 'info': | |
self._data = [] | |
@@ -71,22 +71,22 @@ | |
self.function_arg_name = None | |
self.function_arg_type = None | |
self.function_arg_info = None | |
- if attrs.has_key('name'): | |
+ if 'name' in attrs: | |
self.function_arg_name = attrs['name'] | |
- if attrs.has_key('type'): | |
+ if 'type' in attrs: | |
self.function_arg_type = attrs['type'] | |
- if attrs.has_key('info'): | |
+ if 'info' in attrs: | |
self.function_arg_info = attrs['info'] | |
elif tag == 'return': | |
if self.in_function == 1: | |
self.function_return_type = None | |
self.function_return_info = None | |
self.function_return_field = None | |
- if attrs.has_key('type'): | |
+ if 'type' in attrs: | |
self.function_return_type = attrs['type'] | |
- if attrs.has_key('info'): | |
+ if 'info' in attrs: | |
self.function_return_info = attrs['info'] | |
- if attrs.has_key('field'): | |
+ if 'field' in attrs: | |
self.function_return_field = attrs['field'] | |
elif tag == 'enum': | |
enum(attrs['type'],attrs['name'],attrs['value']) | |
@@ -95,7 +95,7 @@ | |
def end(self, tag): | |
if debug: | |
- print "end %s" % tag | |
+ print("end %s" % tag) | |
if tag == 'function': | |
if self.function != None: | |
function(self.function, self.function_descr, | |
@@ -124,7 +124,7 @@ | |
functions[name] = (desc, ret, args, file) | |
def enum(type, name, value): | |
- if not enums.has_key(type): | |
+ if type not in enums: | |
enums[type] = {} | |
enums[type][name] = value | |
@@ -264,10 +264,10 @@ | |
try: | |
(desc, ret, args, file) = functions[name] | |
except: | |
- print "failed to get function %s infos" | |
+ print("failed to get function %s infos") | |
return | |
- if skipped_modules.has_key(file): | |
+ if file in skipped_modules: | |
return 0 | |
if skip_function(name) == 1: | |
return 0 | |
@@ -283,7 +283,7 @@ | |
if arg[1][0:6] == "const ": | |
arg[1] = arg[1][6:] | |
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]] | |
if f != None: | |
format = format + f | |
@@ -299,9 +299,9 @@ | |
c_call = c_call + ", " | |
c_call = c_call + "%s" % (arg[0]) | |
else: | |
- if skipped_types.has_key(arg[1]): | |
+ if arg[1] in skipped_types: | |
return 0 | |
- if unknown_types.has_key(arg[1]): | |
+ if arg[1] in unknown_types: | |
lst = unknown_types[arg[1]] | |
lst.append(name) | |
else: | |
@@ -323,7 +323,7 @@ | |
else: | |
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]): | |
+ elif ret[0] in py_types: | |
(f, t, n, c, p) = py_types[ret[0]] | |
c_return = " %s c_retval;\n" % (ret[0]) | |
if file == "python_accessor" and ret[2] != None: | |
@@ -332,7 +332,7 @@ | |
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]): | |
+ elif ret[0] in py_return_types: | |
(f, t, n, c, p) = py_return_types[ret[0]] | |
c_return = " %s c_retval;\n" % (ret[0]) | |
if file == "python_accessor" and ret[2] != None: | |
@@ -342,9 +342,9 @@ | |
ret_convert = " py_retval = %s%sWrap((%s) c_retval);\n" % (p,n,c) | |
ret_convert = ret_convert + " return(py_retval);\n" | |
else: | |
- if skipped_types.has_key(ret[0]): | |
+ if ret[0] in skipped_types: | |
return 0 | |
- if unknown_types.has_key(ret[0]): | |
+ if ret[0] in unknown_types: | |
lst = unknown_types[ret[0]] | |
lst.append(name) | |
else: | |
@@ -398,18 +398,18 @@ | |
(parser, target) = getparser() | |
parser.feed(data) | |
parser.close() | |
- except IOError, msg: | |
+ except IOError as msg: | |
try: | |
f = open("%s/../doc/libxslt-api.xml" % srcdir) | |
data = f.read() | |
(parser, target) = getparser() | |
parser.feed(data) | |
parser.close() | |
- except IOError, msg: | |
- print "../doc/libxslt-api.xml", ":", msg | |
+ except IOError as msg: | |
+ print("../doc/libxslt-api.xml", ":", msg) | |
- n = len(functions.keys()) | |
- print "Found %d functions in libxslt-api.xml" % (n) | |
+ n = len(list(functions.keys())) | |
+ print("Found %d functions in libxslt-api.xml" % (n)) | |
py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", | |
"pythonObject", "libxml_") | |
@@ -419,12 +419,12 @@ | |
(parser, target) = getparser() | |
parser.feed(data) | |
parser.close() | |
- except IOError, msg: | |
- print "libxslt-python-api.xml", ":", msg | |
+ except IOError as msg: | |
+ print("libxslt-python-api.xml", ":", msg) | |
- print "Found %d functions in libxslt-python-api.xml" % ( | |
- len(functions.keys()) - n) | |
+ print("Found %d functions in libxslt-python-api.xml" % ( | |
+ len(list(functions.keys())) - n)) | |
nb_wrap = 0 | |
failed = 0 | |
skipped = 0 | |
@@ -439,7 +439,7 @@ | |
wrapper.write("#include <libxslt/xsltconfig.h>\n") | |
wrapper.write("#include \"libxslt_wrap.h\"\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) | |
if ret < 0: | |
failed = failed + 1 | |
@@ -453,12 +453,12 @@ | |
export.close() | |
wrapper.close() | |
- print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap, | |
- failed, skipped) | |
- print "Missing type converters:" | |
- for type in unknown_types.keys(): | |
- print "%s:%d " % (type, len(unknown_types[type])), | |
+ print("Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap, | |
+ failed, skipped)) | |
+ print("Missing type converters:") | |
+ for type in list(unknown_types.keys()): | |
+ print("%s:%d " % (type, len(unknown_types[type])), end=' ') | |
+ print() | |
####################################################################### | |
# | |
@@ -533,55 +533,55 @@ | |
l = len(classe) | |
if name[0:l] == listname: | |
func = name[l:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:12] == "xmlParserGet" and file == "python_accessor": | |
func = name[12:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:12] == "xmlParserSet" and file == "python_accessor": | |
func = name[12:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:10] == "xmlNodeGet" and file == "python_accessor": | |
func = name[10:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:18] == "xsltXPathParserGet" and file == "python_accessor": | |
func = name[18:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:12] == "xsltXPathGet" and file == "python_accessor": | |
func = name[12:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:16] == "xsltTransformGet" and file == "python_accessor": | |
func = name[16:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:16] == "xsltTransformSet" and file == "python_accessor": | |
func = name[13:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:17] == "xsltStylesheetGet" and file == "python_accessor": | |
func = name[17:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:17] == "xsltStylesheetSet" and file == "python_accessor": | |
func = name[14:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:l] == classe: | |
func = name[l:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:7] == "libxml_": | |
func = name[7:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:8] == "libxslt_": | |
func = name[8:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:6] == "xmlGet": | |
func = name[6:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:3] == "xml": | |
func = name[3:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:7] == "xsltGet": | |
func = name[7:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
elif name[0:4] == "xslt": | |
func = name[4:] | |
- func = string.lower(func[0:1]) + func[1:] | |
+ func = func[0:1].lower() + func[1:] | |
else: | |
func = name | |
if func[0:5] == "xPath": | |
@@ -598,6 +598,25 @@ | |
func = "UTF8" + func[4:] | |
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): | |
(index1, func1, name1, ret1, args1, file1) = info1 | |
(index2, func2, name2, ret2, args2, file2) = info2 | |
@@ -620,7 +639,7 @@ | |
if functions[name][0] == None or functions[name][0] == "": | |
return | |
val = functions[name][0] | |
- val = string.replace(val, "NULL", "None") | |
+ val = val.replace("NULL", "None") | |
output.write(indent) | |
output.write('"""') | |
while len(val) > 60: | |
@@ -628,7 +647,7 @@ | |
val = val[1:] | |
continue | |
str = val[0:60] | |
- i = string.rfind(str, " ") | |
+ i = str.rfind(" ") | |
if i < 0: | |
i = 60 | |
str = val[0:i] | |
@@ -659,7 +678,7 @@ | |
global classes_destructors | |
function_classes["None"] = [] | |
- for type in classes_type.keys(): | |
+ for type in list(classes_type.keys()): | |
function_classes[classes_type[type][2]] = [] | |
# | |
@@ -671,23 +690,23 @@ | |
for classe in primary_classes: | |
classes_list.append(classe) | |
classes_processed[classe] = () | |
- for type in classes_type.keys(): | |
+ for type in list(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): | |
+ for type in list(classes_type.keys()): | |
+ if type in ctypes_processed: | |
continue | |
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_processed[tinfo[2]] = () | |
ctypes.append(type) | |
ctypes_processed[type] = () | |
- for name in functions.keys(): | |
+ for name in list(functions.keys()): | |
found = 0 | |
(desc, ret, args, file) = functions[name] | |
for type in ctypes: | |
@@ -725,9 +744,9 @@ | |
txt.write(" Generated Classes for libxslt-python\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.sort(functionCompare) | |
+ flist.sort(key=cmp_to_key(functionCompare)) | |
oldfile = "" | |
for info in flist: | |
(index, func, name, ret, args, file) = info | |
@@ -747,12 +766,12 @@ | |
writeDoc(name, args, ' ', classes) | |
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" % | |
(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]): | |
+ elif arg[1] in libxml2_classes_type: | |
classes.write(" if %s == None: %s__o = None\n" % | |
(arg[0], arg[0])) | |
classes.write(" else: %s__o = %s%s\n" % | |
@@ -767,19 +786,19 @@ | |
if n != 0: | |
classes.write(", ") | |
classes.write("%s" % arg[0]) | |
- if classes_type.has_key(arg[1]): | |
+ if arg[1] in classes_type: | |
classes.write("__o") | |
- if libxml2_classes_type.has_key(arg[1]): | |
+ if arg[1] in libxml2_classes_type: | |
classes.write("__o") | |
n = n + 1 | |
classes.write(")\n") | |
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(" return ") | |
classes.write(classes_type[ret[0]][1] % ("ret")) | |
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(" return libxml2.") | |
classes.write(libxml2_classes_type[ret[0]][1] % ("ret")) | |
@@ -793,7 +812,7 @@ | |
if classname == "None": | |
pass | |
else: | |
- if classes_ancestor.has_key(classname): | |
+ if classname in classes_ancestor: | |
txt.write("\n\nClass %s(%s)\n" % (classname, | |
classes_ancestor[classname])) | |
classes.write("class %s(%s):\n" % (classname, | |
@@ -814,7 +833,7 @@ | |
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): | |
+ if classname in classes_destructors: | |
classes.write(" def __del__(self):\n") | |
if classes_destructors[classname] == "pass": | |
classes.write(" pass\n") | |
@@ -824,7 +843,7 @@ | |
classes_destructors[classname]) | |
classes.write(" self._o = None\n\n") | |
flist = function_classes[classname] | |
- flist.sort(functionCompare) | |
+ flist.sort(key=cmp_to_key(functionCompare)) | |
oldfile = "" | |
for info in flist: | |
(index, func, name, ret, args, file) = info | |
@@ -850,13 +869,13 @@ | |
writeDoc(name, args, ' ', classes) | |
n = 0 | |
for arg in args: | |
- if classes_type.has_key(arg[1]): | |
+ if arg[1] in classes_type: | |
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]): | |
+ elif arg[1] in libxml2_classes_type: | |
classes.write(" if %s == None: %s__o = None\n" % | |
(arg[0], arg[0])) | |
classes.write(" else: %s__o = %s%s\n" % | |
@@ -874,30 +893,30 @@ | |
classes.write(", ") | |
if n != index: | |
classes.write("%s" % arg[0]) | |
- if classes_type.has_key(arg[1]): | |
+ if arg[1] in classes_type: | |
classes.write("__o") | |
- elif libxml2_classes_type.has_key(arg[1]): | |
+ elif arg[1] in libxml2_classes_type: | |
classes.write("__o") | |
else: | |
classes.write("self") | |
- if classes_type.has_key(arg[1]): | |
+ if arg[1] in classes_type: | |
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]) | |
n = n + 1 | |
classes.write(")\n") | |
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(" return ") | |
classes.write(classes_type[ret[0]][1] % ("ret")) | |
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(" return libxml2.") | |
classes.write(libxml2_classes_type[ret[0]][1] % ("ret")) | |
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(" return ") | |
classes.write(converter_type[ret[0]] % ("ret")) | |
@@ -909,10 +928,10 @@ | |
# | |
# Generate enum constants | |
# | |
- for type,enum in enums.items(): | |
+ for type,enum in list(enums.items()): | |
classes.write("# %s\n" % type) | |
- items = enum.items() | |
- items.sort(lambda i1,i2: cmp(long(i1[1]),long(i2[1]))) | |
+ items = list(enum.items()) | |
+ items.sort(key=lambda x: x[1]) | |
for name,value in items: | |
classes.write("%s = %s\n" % (name,value)) | |
classes.write("\n"); | |
diff -ur libxslt-1.1.28.old/python/libxslt.c libxslt-1.1.28/python/libxslt.c | |
--- libxslt-1.1.28.old/python/libxslt.c 2012-09-12 07:58:38.000000000 +0100 | |
+++ libxslt-1.1.28/python/libxslt.c 2015-01-23 15:18:53.495495400 +0000 | |
@@ -55,8 +55,13 @@ | |
Py_INCREF(Py_None); | |
return(Py_None); | |
} | |
+#if PY_MAJOR_VERSION >= 3 | |
+ ret = PyCapsule_New((void *) style, | |
+ (char *)"xsltStylesheetPtr", NULL); | |
+#else | |
ret = PyCObject_FromVoidPtrAndDesc((void *) style, | |
(char *)"xsltStylesheetPtr", NULL); | |
+#endif | |
return(ret); | |
} | |
@@ -72,8 +77,13 @@ | |
Py_INCREF(Py_None); | |
return(Py_None); | |
} | |
+#if PY_MAJOR_VERSION >= 3 | |
+ ret = PyCapsule_New((void *) ctxt, | |
+ (char *)"xsltTransformContextPtr", NULL); | |
+#else | |
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, | |
(char *)"xsltTransformContextPtr", NULL); | |
+#endif | |
return(ret); | |
} | |
@@ -88,8 +98,13 @@ | |
Py_INCREF(Py_None); | |
return(Py_None); | |
} | |
+#if PY_MAJOR_VERSION >= 3 | |
+ ret = PyCapsule_New((void *) ctxt, | |
+ (char *)"xsltElemPreCompPtr", NULL); | |
+#else | |
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, | |
(char *)"xsltElemPreCompPtr", NULL); | |
+#endif | |
return(ret); | |
} | |
@@ -107,7 +122,7 @@ | |
tctxt = (xsltTransformContextPtr) PytransformCtxt_Get(py_tctxt); | |
hash_code = (long) tctxt; | |
- ret = PyInt_FromLong(hash_code); | |
+ ret = PyLong_FromLong(hash_code); | |
return ret; | |
} | |
@@ -144,7 +159,7 @@ | |
style = (xsltStylesheetPtr) Pystylesheet_Get(py_style); | |
hash_code = (long) style; | |
- ret = PyInt_FromLong(hash_code); | |
+ ret = PyLong_FromLong(hash_code); | |
return ret; | |
} | |
@@ -598,7 +613,7 @@ | |
pythonDocLoaderObject = loader; | |
xsltSetLoaderFunc(pythonDocLoaderFuncWrapper); | |
- py_retval = PyInt_FromLong(0); | |
+ py_retval = PyLong_FromLong(0); | |
return(py_retval); | |
} | |
@@ -690,14 +705,22 @@ | |
while (PyDict_Next(pyobj_params, &ppos, &name, &value)) { | |
const char *tmp; | |
int size; | |
- | |
+#if PY_MAJOR_VERSION >= 3 | |
+ tmp = PyUnicode_AsUTF8AndSize(name, &size); | |
+#else | |
tmp = PyString_AS_STRING(name); | |
size = PyString_GET_SIZE(name); | |
+#endif | |
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)) { | |
tmp = PyString_AS_STRING(value); | |
size = PyString_GET_SIZE(value); | |
- params[(j * 2) + 1] = (char *) | |
+#endif | |
+ params[(j * 2) + 1] = (char *) | |
xmlCharStrndup(tmp, size); | |
} else { | |
params[(j * 2) + 1] = NULL; | |
@@ -766,13 +789,21 @@ | |
while (PyDict_Next(pyobj_params, &ppos, &name, &value)) { | |
const char *tmp; | |
int size; | |
- | |
+#if PY_MAJOR_VERSION >= 3 | |
+ tmp = PyUnicode_AsUTF8AndSize(name, &size); | |
+#else | |
tmp = PyString_AS_STRING(name); | |
size = PyString_GET_SIZE(name); | |
+#endif | |
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)) { | |
tmp = PyString_AS_STRING(value); | |
size = PyString_GET_SIZE(value); | |
+#endif | |
params[(j * 2) + 1] = (char *) | |
xmlCharStrndup(tmp, size); | |
} else { | |
@@ -837,11 +868,19 @@ | |
if(size) | |
{ | |
buffer[size] = '\0'; | |
+#if PY_MAJOR_VERSION >= 3 | |
+ py_retval = PyUnicode_DecodeUTF8((char *) buffer, size, NULL); | |
+#else | |
py_retval = PyString_FromString((char *) buffer); | |
+#endif | |
xmlFree(buffer); | |
} | |
else | |
+#if PY_MAJOR_VERSION >= 3 | |
+ py_retval = PyUnicode_DecodeUTF8("", 0, NULL); | |
+#else | |
py_retval = PyString_FromString(""); | |
+#endif | |
return(py_retval); | |
FAIL: | |
return(0); | |
@@ -1175,10 +1214,37 @@ | |
}; | |
#ifdef MERGED_MODULES | |
+#if PY_MAJOR_VERSION >= 3 | |
+extern void PyInit_libxml2mod(void); | |
+#else | |
extern void initlibxml2mod(void); | |
#endif | |
+#endif | |
+/* | |
+ * for Python 3 this function must start with PyInit, for Python 2 it must | |
+ * start with init. | |
+ * | |
+ * https://www.python.org/dev/peps/pep-3121/ | |
+ */ | |
+ | |
+#if PY_MAJOR_VERSION >= 3 | |
+static struct PyModuleDef moduledef = { | |
+ PyModuleDef_HEAD_INIT, | |
+ "libxsltmod", | |
+ NULL, | |
+ -1, | |
+ libxsltMethods, | |
+ NULL, | |
+ NULL, | |
+ NULL, | |
+ NULL | |
+}; | |
+ | |
+PyObject* PyInit_libxsltmod(void) { | |
+#else | |
void initlibxsltmod(void) { | |
+#endif | |
static int initialized = 0; | |
PyObject *m; | |
@@ -1188,7 +1254,15 @@ | |
if (initialized != 0) | |
return; | |
+#if PY_MAJOR_VERSION >= 3 | |
+ m = PyModule_Create(&moduledef); | |
+ if (!m) { | |
+ return NULL; | |
+ } | |
+#else | |
m = Py_InitModule((char *)"libxsltmod", libxsltMethods); | |
+#endif | |
+ | |
initialized = 1; | |
/* | |
* Specific XSLT initializations | |
@@ -1201,6 +1275,10 @@ | |
* Register the EXSLT extensions and the test module | |
*/ | |
exsltRegisterAll(); | |
+ | |
+#if PY_MAJOR_VERSION >= 3 | |
+ return m; | |
+#endif | |
} | |
diff -ur libxslt-1.1.28.old/python/types.c libxslt-1.1.28/python/types.c | |
--- libxslt-1.1.28.old/python/types.c 2012-09-12 07:58:16.000000000 +0100 | |
+++ libxslt-1.1.28/python/types.c 2015-01-22 17:16:31.723918700 +0000 | |
@@ -166,9 +166,23 @@ | |
return (Py_None); | |
} | |
/* TODO: look at deallocation */ | |
+#if PY_MAJOR_VERSION >= 3 | |
+ /* | |
+ * Note - PyCapsule object layout is the same as PyCObject (i.e. the | |
+ * obj pointer is immediately after the python obj part), so | |
+ * the unchecked casting when these are unpacked will continue | |
+ * to work without modification (see libxml2-py.c). | |
+ * | |
+ * TODO: maybe we should start doing checks on unwrap using the | |
+ * PyCapsule API? | |
+ */ | |
+ ret = PyCapsule_New((void *) doc, (char *) "xmlDocPtr", | |
+ NULL); | |
+#else | |
ret = | |
PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr", | |
NULL); | |
+#endif | |
return (ret); | |
} | |
@@ -184,9 +198,14 @@ | |
Py_INCREF(Py_None); | |
return (Py_None); | |
} | |
+#if PY_MAJOR_VERSION >= 3 | |
+ ret = PyCapsule_New((void *) node, (char *) "xmlNodePtr", | |
+ NULL); | |
+#else | |
ret = | |
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr", | |
NULL); | |
+#endif | |
return (ret); | |
} | |
@@ -202,9 +221,14 @@ | |
Py_INCREF(Py_None); | |
return (Py_None); | |
} | |
+#if PY_MAJOR_VERSION >= 3 | |
+ ret = PyCapsule_New((void *) uri, (char *) "xmlURIPtr", | |
+ NULL); | |
+#else | |
ret = | |
PyCObject_FromVoidPtrAndDesc((void *) uri, (char *) "xmlURIPtr", | |
NULL); | |
+#endif | |
return (ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment