GNOME Bugzilla – Bug 703979
in libxml2-2.9.1, python/drv_libxml2.py is incompatible with python3
Last modified: 2014-10-06 11:48:48 UTC
libxml2-2.9.1 is supposed to be compatible with python3, but: *** Error compiling '/var/tmp/portage/dev-libs/libxml2-2.9.1/image//usr/lib64/python3.2/site-packages/drv_libxml2.py'...
+ Trace 232221
__author__ = u"Stéphane Bidoul <sbi@skynet.be>"
*** Error compiling '/var/tmp/portage/dev-libs/libxml2-2.9.1/image//usr/lib64/python3.3/site-packages/drv_libxml2.py'... File "/usr/lib64/python3.3/site-packages/drv_libxml2.py", line 68 except ImportError, e: ^ SyntaxError: invalid syntax
Created attachment 248904 [details] [review] proposed patch
Looks fine, okay, pushed to git ! https://git.gnome.org/browse/libxml2/commit/?id=6c9c611beed57f001ca3ae6b964518d9c7336a69 thanks ! Daniel
What is minimal supported version of Python? Some other files use sys.exc_info instead of 'except ${exception_class} as ${exception_variable}:' to support Python <2.6, but commit mentioned in comment #2 adds syntax incompatible with Python <2.6. (Personally I do not need support for Python <2.6.) Since Python 2.2, types.StringType and types.UnicodeType are not needed, and 'StringTypes = (str, unicode)' could be used.
By the way, parentheses are not needed in 'StringTypes = (str)'.
StringTypes is used only in the following line: if type(source) in StringTypes: This line causes TypeError with Python 3. Solution with support for Python <2.2: - StringTypes = (str) + StringTypes = (str,) Solution without support for Python <2.2: - StringTypes = (str) + StringTypes = str ... - if type(source) in StringTypes: + if isinstance(source, StringTypes):
Ouch right, we need 2.6 support IMHO, I didn't realized that thi broke it. I have tried until not to allow 2.6 and later to be used. would you mind providing a fixup ? thanks ! Daniel
New syntax of 'except' statements was introduced in Python 2.6. That commit broke support for Python older than 2.6 (and did not really fix support for Python 3). I can create a patch. What minimal Python version should I assume?
Cool, ideally I would prefer to still be able to build on RHEL-5/CentOS-5 and they ship with python 2.4, so >= 2.4 would be ideal ! thanks ! Daniel
Created attachment 248922 [details] [review] Patch
(In reply to comment #5) I must apologize for the brain error. I had intended "StringTypes = (str,)"
No need to apologize :-) contributions gratefully received ! Latest patch pushed, hopefully this is okay now ! https://git.gnome.org/browse/libxml2/commit/?id=6dd7775f3506741093890d99f09c242e0b34b55f thanks ! Daniel
*** Bug 734005 has been marked as a duplicate of this bug. ***