diff options
author | Daniel Veillard <veillard@redhat.com> | 2013-03-27 22:40:54 +0800 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2013-03-30 22:33:06 +0800 |
commit | 3cb1ae26ec845beaea4c3a37eba7c874a7fa21a1 (patch) | |
tree | 78e26c07223c1e3d74af333f615e74bddf930f17 /python | |
parent | a5e513a55221fb85d0b474f6f79f26506e2e2c16 (diff) | |
download | android_external_libxml2-3cb1ae26ec845beaea4c3a37eba7c874a7fa21a1.tar.gz android_external_libxml2-3cb1ae26ec845beaea4c3a37eba7c874a7fa21a1.tar.bz2 android_external_libxml2-3cb1ae26ec845beaea4c3a37eba7c874a7fa21a1.zip |
First pass at starting porting to python3
Diffstat (limited to 'python')
-rwxr-xr-x | python/generator.py | 196 | ||||
-rw-r--r-- | python/libxml.py | 31 | ||||
-rwxr-xr-x | python/setup.py | 18 | ||||
-rwxr-xr-x | python/setup.py.in | 18 |
4 files changed, 141 insertions, 122 deletions
diff --git a/python/generator.py b/python/generator.py index 83d100cf..b864b16c 100755 --- a/python/generator.py +++ b/python/generator.py @@ -47,19 +47,19 @@ class docParser(xml.sax.handler.ContentHandler): 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 @@ -69,9 +69,9 @@ class docParser(xml.sax.handler.ContentHandler): self.function_descr = None self.function_return = None self.function_file = None - if attrs.has_key('name'): + if 'name' in attrs.keys(): self.function = attrs['name'] - if attrs.has_key('file'): + if 'file' in attrs.keys(): self.function_file = attrs['file'] elif tag == 'cond': self._data = [] @@ -82,29 +82,29 @@ class docParser(xml.sax.handler.ContentHandler): self.function_arg_name = None self.function_arg_type = None self.function_arg_info = None - if attrs.has_key('name'): + if 'name' in attrs.keys(): self.function_arg_name = attrs['name'] - if attrs.has_key('type'): + if 'type' in attrs.keys(): self.function_arg_type = attrs['type'] - if attrs.has_key('info'): + if 'info' in attrs.keys(): 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.keys(): self.function_return_type = attrs['type'] - if attrs.has_key('info'): + if 'info' in attrs.keys(): self.function_return_info = attrs['info'] - if attrs.has_key('field'): + if 'field' in attrs.keys(): self.function_return_field = attrs['field'] elif tag == 'enum': enum(attrs['type'],attrs['name'],attrs['value']) 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, @@ -139,7 +139,7 @@ def function(name, desc, ret, args, file, cond): functions[name] = (desc, ret, args, file, cond) def enum(type, name, value): - if not enums.has_key(type): + if type not in enums: enums[type] = {} enums[type][name] = value @@ -340,7 +340,7 @@ def skip_function(name): if name == "xmlValidateAttributeDecl": return 1 if name == "xmlPopInputCallbacks": - return 1 + return 1 return 0 @@ -353,10 +353,10 @@ def print_function_wrapper(name, output, export, include): try: (desc, ret, args, file, cond) = 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 @@ -376,7 +376,7 @@ def print_function_wrapper(name, output, export, include): 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) = py_types[arg[1]] if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0): f = 't#' @@ -398,9 +398,9 @@ def print_function_wrapper(name, output, export, include): 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: @@ -422,7 +422,7 @@ def print_function_wrapper(name, output, export, include): 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) = py_types[ret[0]] c_return = " %s c_retval;\n" % (ret[0]) if file == "python_accessor" and ret[2] != None: @@ -431,16 +431,16 @@ def print_function_wrapper(name, output, export, include): c_call = "\n c_retval = %s(%s);\n" % (name, c_call) ret_convert = " py_retval = libxml_%sWrap((%s) c_retval);\n" % (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) = py_return_types[ret[0]] c_return = " %s c_retval;\n" % (ret[0]) c_call = "\n c_retval = %s(%s);\n" % (name, c_call) ret_convert = " py_retval = libxml_%sWrap((%s) c_retval);\n" % (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: @@ -512,19 +512,19 @@ def buildStubs(): (parser, target) = getparser() parser.feed(data) parser.close() - except IOError, msg: + except IOError as msg: try: f = open(os.path.join(srcPref,"..","doc","libxml2-api.xml")) data = f.read() (parser, target) = getparser() parser.feed(data) parser.close() - except IOError, msg: - print file, ":", msg + except IOError as msg: + print(file, ":", msg) sys.exit(1) - n = len(functions.keys()) - print "Found %d functions in libxml2-api.xml" % (n) + n = len(list(functions.keys())) + print("Found %d functions in libxml2-api.xml" % (n)) py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject") try: @@ -533,12 +533,12 @@ def buildStubs(): (parser, target) = getparser() parser.feed(data) parser.close() - except IOError, msg: - print file, ":", msg + except IOError as msg: + print(file, ":", msg) - print "Found %d functions in libxml2-python-api.xml" % ( - len(functions.keys()) - n) + print("Found %d functions in libxml2-python-api.xml" % ( + len(list(functions.keys())) - n)) nb_wrap = 0 failed = 0 skipped = 0 @@ -569,12 +569,12 @@ def buildStubs(): 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 + 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]))) + print() ####################################################################### # @@ -699,40 +699,40 @@ def nameFixup(name, classe, type, file): 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:9] == "xmlURIGet" and file == "python_accessor": func = name[9:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:9] == "xmlURISet" and file == "python_accessor": func = name[6:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:11] == "xmlErrorGet" and file == "python_accessor": func = name[11:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:17] == "xmlXPathParserGet" 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:11] == "xmlXPathGet" and file == "python_accessor": func = name[11:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:11] == "xmlXPathSet" and file == "python_accessor": func = name[8:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:15] == "xmlOutputBuffer" and file != "python": func = name[15:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:20] == "xmlParserInputBuffer" and file != "python": func = name[20:] - func = string.lower(func[0:1]) + func[1:] + func = func[0:1].lower() + func[1:] elif name[0:9] == "xmlRegexp" and file == "xmlregexp": func = "regexp" + name[9:] elif name[0:6] == "xmlReg" and file == "xmlregexp": @@ -747,19 +747,19 @@ def nameFixup(name, classe, type, file): func = name[9:] elif name[0:11] == "xmlACatalog": func = name[11:] - 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: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:] else: func = name if func[0:5] == "xPath": @@ -797,11 +797,29 @@ def functionCompare(info1, info2): return 1 return 0 +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 writeDoc(name, args, indent, output): if functions[name][0] is 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: @@ -809,7 +827,7 @@ def writeDoc(name, args, indent, output): val = val[1:] continue str = val[0:60] - i = string.rfind(str, " ") + i = str.rfind(" ") if i < 0: i = 60 str = val[0:i] @@ -859,13 +877,13 @@ def buildWrappers(): ctypes.append(type) ctypes_processed[type] = () for type in sorted(classes_type.keys()): - if ctypes_processed.has_key(type): + 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] = () @@ -914,9 +932,9 @@ def buildWrappers(): txt.write(" Generated Classes for libxml2-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 = sorted(flist, key=cmp_to_key(functionCompare)) oldfile = "" for info in flist: (index, func, name, ret, args, file) = info @@ -936,7 +954,7 @@ def buildWrappers(): 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 is None: %s__o = None\n" % (arg[0], arg[0])) classes.write(" else: %s__o = %s%s\n" % @@ -951,26 +969,26 @@ def buildWrappers(): 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") n = n + 1 classes.write(")\n") if ret[0] != "void": - if classes_type.has_key(ret[0]): + if ret[0] in classes_type: # # Raise an exception # - if functions_noexcept.has_key(name): + if name in functions_noexcept: classes.write(" if ret is None:return None\n") - elif string.find(name, "URI") >= 0: + elif name.find("URI") >= 0: classes.write( " if ret is None:raise uriError('%s() failed')\n" % (name)) - elif string.find(name, "XPath") >= 0: + elif name.find("XPath") >= 0: classes.write( " if ret is None:raise xpathError('%s() failed')\n" % (name)) - elif string.find(name, "Parse") >= 0: + elif name.find("Parse") >= 0: classes.write( " if ret is None:raise parserError('%s() failed')\n" % (name)) @@ -990,7 +1008,7 @@ def buildWrappers(): 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, @@ -1003,7 +1021,7 @@ def buildWrappers(): classes.write(" raise TypeError, ") classes.write("'%s needs a PyCObject argument'\n" % \ classname) - if reference_keepers.has_key(classname): + if classname in reference_keepers: rlist = reference_keepers[classname] for ref in rlist: classes.write(" self.%s = None\n" % ref[1]) @@ -1020,14 +1038,14 @@ def buildWrappers(): txt.write("Class %s()\n" % (classname)) classes.write("class %s:\n" % (classname)) classes.write(" def __init__(self, _obj=None):\n") - if reference_keepers.has_key(classname): + if classname in reference_keepers: list = reference_keepers[classname] for ref in list: classes.write(" self.%s = None\n" % ref[1]) classes.write(" if _obj != None:self._o = _obj;return\n") classes.write(" self._o = None\n\n") destruct=None - if classes_destructors.has_key(classname): + if classname in classes_destructors: classes.write(" def __del__(self):\n") classes.write(" if self._o != None:\n") classes.write(" libxml2mod.%s(self._o)\n" % @@ -1035,7 +1053,7 @@ def buildWrappers(): classes.write(" self._o = None\n\n") destruct=classes_destructors[classname] flist = function_classes[classname] - flist.sort(functionCompare) + flist = sorted(flist, key=cmp_to_key(functionCompare)) oldfile = "" for info in flist: (index, func, name, ret, args, file) = info @@ -1067,7 +1085,7 @@ def buildWrappers(): 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 is None: %s__o = None\n" % (arg[0], arg[0])) @@ -1085,31 +1103,31 @@ def buildWrappers(): 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") else: classes.write("self") - if classes_type.has_key(arg[1]): + if arg[1] in classes_type: classes.write(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: # # Raise an exception # - if functions_noexcept.has_key(name): + if name in functions_noexcept: classes.write( " if ret is None:return None\n") - elif string.find(name, "URI") >= 0: + elif name.find("URI") >= 0: classes.write( " if ret is None:raise uriError('%s() failed')\n" % (name)) - elif string.find(name, "XPath") >= 0: + elif name.find("XPath") >= 0: classes.write( " if ret is None:raise xpathError('%s() failed')\n" % (name)) - elif string.find(name, "Parse") >= 0: + elif name.find("Parse") >= 0: classes.write( " if ret is None:raise parserError('%s() failed')\n" % (name)) @@ -1131,7 +1149,7 @@ def buildWrappers(): # See reference_keepers for the list # tclass = classes_type[ret[0]][2] - if reference_keepers.has_key(tclass): + if tclass in reference_keepers: list = reference_keepers[tclass] for pref in list: if pref[0] == classname: @@ -1141,22 +1159,22 @@ def buildWrappers(): # return the class # classes.write(" return __tmp\n") - elif converter_type.has_key(ret[0]): + elif ret[0] in converter_type: # # Raise an exception # - if functions_noexcept.has_key(name): + if name in functions_noexcept: classes.write( " if ret is None:return None") - elif string.find(name, "URI") >= 0: + elif name.find("URI") >= 0: classes.write( " if ret is None:raise uriError('%s() failed')\n" % (name)) - elif string.find(name, "XPath") >= 0: + elif name.find("XPath") >= 0: classes.write( " if ret is None:raise xpathError('%s() failed')\n" % (name)) - elif string.find(name, "Parse") >= 0: + elif name.find("Parse") >= 0: classes.write( " if ret is None:raise parserError('%s() failed')\n" % (name)) @@ -1177,7 +1195,7 @@ def buildWrappers(): for type,enum in enums.items(): classes.write("# %s\n" % type) items = enum.items() - items.sort(lambda i1,i2: cmp(long(i1[1]),long(i2[1]))) + items = sorted(items, key=(lambda i: int(i[1]))) for name,value in items: classes.write("%s = %s\n" % (name,value)) classes.write("\n") diff --git a/python/libxml.py b/python/libxml.py index 193f97a6..43ad49d0 100644 --- a/python/libxml.py +++ b/python/libxml.py @@ -11,7 +11,7 @@ class libxmlError(Exception): pass def pos_id(o): i = id(o) if (i < 0): - return (sys.maxint - i) + return (sys.maxsize - i) return i # @@ -79,7 +79,7 @@ class ioReadWrapper(ioWrapper): self._o = libxml2mod.xmlCreateInputBuffer(self, enc) def __del__(self): - print "__del__" + print("__del__") self.io_close() if self._o != None: libxml2mod.xmlFreeParserInputBuffer(self._o) @@ -95,10 +95,10 @@ class ioWriteWrapper(ioWrapper): def __init__(self, _obj, enc = ""): # print "ioWriteWrapper.__init__", _obj if type(_obj) == type(''): - print "write io from a string" + print("write io from a string") self.o = None elif type(_obj) == types.InstanceType: - print "write io from instance of %s" % (_obj.__class__) + print("write io from instance of %s" % (_obj.__class__)) ioWrapper.__init__(self, _obj) self._o = libxml2mod.xmlCreateOutputBuffer(self, enc) else: @@ -357,7 +357,7 @@ class xmlCore: else: return None return xmlDoc(_obj=ret) - raise AttributeError,attr + raise AttributeError(attr) else: parent = property(get_parent, None, None, "Parent node") children = property(get_children, None, None, "First child node") @@ -400,7 +400,7 @@ class xmlCore: prefixes=None, with_comments=0): if nodes: - nodes = map(lambda n: n._o, nodes) + nodes = [n._o for n in nodes] return libxml2mod.xmlC14NDocDumpMemory( self.get_doc()._o, nodes, @@ -414,7 +414,7 @@ class xmlCore: prefixes=None, with_comments=0): if nodes: - nodes = map(lambda n: n._o, nodes) + nodes = [n._o for n in nodes] return libxml2mod.xmlC14NDocSaveTo( self.get_doc()._o, nodes, @@ -502,7 +502,7 @@ class xmlCoreDepthFirstItertor: self.parents = [] def __iter__(self): return self - def next(self): + def __next__(self): while 1: if self.node: ret = self.node @@ -513,7 +513,7 @@ class xmlCoreDepthFirstItertor: parent = self.parents.pop() except IndexError: raise StopIteration - self.node = parent.next + self.node = parent.__next__ # # implements the breadth-first iterator for libxml2 DOM tree @@ -524,12 +524,12 @@ class xmlCoreBreadthFirstItertor: self.parents = [] def __iter__(self): return self - def next(self): + def __next__(self): while 1: if self.node: ret = self.node self.parents.append(self.node) - self.node = self.node.next + self.node = self.node.__next__ return ret try: parent = self.parents.pop() @@ -564,10 +564,10 @@ def nodeWrap(o): def xpathObjectRet(o): otype = type(o) if otype == type([]): - ret = map(xpathObjectRet, o) + ret = list(map(xpathObjectRet, o)) return ret elif otype == type(()): - ret = map(xpathObjectRet, o) + ret = list(map(xpathObjectRet, o)) return tuple(ret) elif otype == type('') or otype == type(0) or otype == type(0.0): return o @@ -603,7 +603,7 @@ def registerErrorHandler(f, ctx): """Register a Python written function to for error reporting. The function is called back as f(ctx, error). """ import sys - if not sys.modules.has_key('libxslt'): + if 'libxslt' not in sys.modules: # normal behaviour when libxslt is not imported ret = libxml2mod.xmlRegisterErrorHandler(f,ctx) else: @@ -682,8 +682,9 @@ class relaxNgValidCtxtCore: libxml2mod.xmlRelaxNGSetValidErrors(self._o, err_func, warn_func, arg) -def _xmlTextReaderErrorFunc((f,arg),msg,severity,locator): +def _xmlTextReaderErrorFunc(xxx_todo_changeme,msg,severity,locator): """Intermediate callback to wrap the locator""" + (f,arg) = xxx_todo_changeme return f(arg,msg,severity,xmlTextReaderLocator(locator)) class xmlTextReaderCore: diff --git a/python/setup.py b/python/setup.py index 7cb8bfce..1b7e27bc 100755 --- a/python/setup.py +++ b/python/setup.py @@ -32,7 +32,7 @@ except: if WITHDLLS: # libxml dlls (expected in ROOT/bin) dlls = [ 'iconv.dll','libxml2.dll','libxslt.dll','libexslt.dll' ] - dlls = map(lambda dll: os.path.join(ROOT,'bin',dll),dlls) + dlls = [os.path.join(ROOT,'bin',dll) for dll in dlls] # create __init__.py for the libxmlmods package if not os.path.exists("libxmlmods"): @@ -70,7 +70,7 @@ for dir in includes_dir: break; if xml_includes == "": - print "failed to find headers for libxml2: update includes_dir" + print("failed to find headers for libxml2: update includes_dir") sys.exit(1) iconv_includes="" @@ -80,7 +80,7 @@ for dir in includes_dir: break; if iconv_includes == "": - print "failed to find headers for libiconv: update includes_dir" + print("failed to find headers for libiconv: update includes_dir") sys.exit(1) # those are added in the linker search path for libraries @@ -103,8 +103,8 @@ if missing("libxml2-py.c") or missing("libxml2.py"): except: import generator except: - print "failed to find and generate stubs for libxml2, aborting ..." - print sys.exc_type, sys.exc_value + print("failed to find and generate stubs for libxml2, aborting ...") + print(sys.exc_info()[0], sys.exc_info()[1]) sys.exit(1) head = open("libxml.py", "r") @@ -124,13 +124,13 @@ if missing("libxml2-py.c") or missing("libxml2.py"): with_xslt=0 if missing("libxslt-py.c") or missing("libxslt.py"): if missing("xsltgenerator.py") or missing("libxslt-api.xml"): - print "libxslt stub generator not found, libxslt not built" + print("libxslt stub generator not found, libxslt not built") else: try: import xsltgenerator except: - print "failed to generate stubs for libxslt, aborting ..." - print sys.exc_type, sys.exc_value + print("failed to generate stubs for libxslt, aborting ...") + print(sys.exc_info()[0], sys.exc_info()[1]) else: head = open("libxsl.py", "r") generated = open("libxsltclass.py", "r") @@ -157,7 +157,7 @@ if with_xslt == 1: break; if xslt_includes == "": - print "failed to find headers for libxslt: update includes_dir" + print("failed to find headers for libxslt: update includes_dir") with_xslt = 0 diff --git a/python/setup.py.in b/python/setup.py.in index 7eaf5306..0e72338c 100755 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -32,7 +32,7 @@ except: if WITHDLLS: # libxml dlls (expected in ROOT/bin) dlls = [ 'iconv.dll','libxml2.dll','libxslt.dll','libexslt.dll' ] - dlls = map(lambda dll: os.path.join(ROOT,'bin',dll),dlls) + dlls = [os.path.join(ROOT,'bin',dll) for dll in dlls] # create __init__.py for the libxmlmods package if not os.path.exists("libxmlmods"): @@ -70,7 +70,7 @@ for dir in includes_dir: break; if xml_includes == "": - print "failed to find headers for libxml2: update includes_dir" + print("failed to find headers for libxml2: update includes_dir") sys.exit(1) iconv_includes="" @@ -80,7 +80,7 @@ for dir in includes_dir: break; if iconv_includes == "": - print "failed to find headers for libiconv: update includes_dir" + print("failed to find headers for libiconv: update includes_dir") sys.exit(1) # those are added in the linker search path for libraries @@ -103,8 +103,8 @@ if missing("libxml2-py.c") or missing("libxml2.py"): except: import generator except: - print "failed to find and generate stubs for libxml2, aborting ..." - print sys.exc_type, sys.exc_value + print("failed to find and generate stubs for libxml2, aborting ...") + print(sys.exc_info()[0], sys.exc_info()[1]) sys.exit(1) head = open("libxml.py", "r") @@ -124,13 +124,13 @@ if missing("libxml2-py.c") or missing("libxml2.py"): with_xslt=0 if missing("libxslt-py.c") or missing("libxslt.py"): if missing("xsltgenerator.py") or missing("libxslt-api.xml"): - print "libxslt stub generator not found, libxslt not built" + print("libxslt stub generator not found, libxslt not built") else: try: import xsltgenerator except: - print "failed to generate stubs for libxslt, aborting ..." - print sys.exc_type, sys.exc_value + print("failed to generate stubs for libxslt, aborting ...") + print(sys.exc_info()[0], sys.exc_info()[1]) else: head = open("libxsl.py", "r") generated = open("libxsltclass.py", "r") @@ -157,7 +157,7 @@ if with_xslt == 1: break; if xslt_includes == "": - print "failed to find headers for libxslt: update includes_dir" + print("failed to find headers for libxslt: update includes_dir") with_xslt = 0 |