New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python3 compatibility #25
Closed
Closed
Conversation
This file contains 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
python 2.6 does not have memoryview, so lets define it as buffer
this patch 1.) removes the iteritems/itervalues, which were dropped in py3 items/values are used instead 2.) add an extra list() in a cases the list-based access is needed (included appending, indexing and so) 3.) changes a sorting idiom in few places instead of foo = dict.keys() foo.sort() for i in foo: there is a recommended for i in sorted(dict.keys()): 4.) in one occassion it removes a if dict.has_key() by simpler dict.get(key, default)
changes 'except FooError, fe' to 'except FooError as fe' available in python 2.6
exec is no longer a statement
the introspection names changed a lot in python3, so lets have two implementations used by respective runtime
used just on one place, seems to be enough to simply remove it
don't use method removed from python3
more idiomatic code - changes * type(foo) == bar to isinstance(foo, bar) * changes the uneeded .sort calls by sorted()
Use relative imports when using module's own modules - this makes a clear distinction between already developed copy and installed package.
Some modules (httplib, StringIO, ...) were renamed in python3. This patch try to import the proper symbols from python3 and then fallback to python2 in a case ImportError will appear. There is one exception, python 2.7 got the io module with StringIO, but it allow unicode arguments only. Therefor the old module is poked before new one.
The octal literals got a new syntax 0755 -> 0o755
The most visible change in python3 - removal of print statement and all the crufty print >> sys.stderr, foo, The from __future__ import print_function makes it available in python 2.6
support for old style exceptions has been removed from python3
raw_input has been removed and equals to input in py3. Unfortunatelly no __future__ statement exists for that. Ensure all modules uses osc.core.raw_input except osc.cmdln, where there is NameError way implemented.
reintroduce unicode function - despite the fact I am pretty sure the usage is plain wrong, because code says - return a unicode string from utf-8 encoded one, which is probably not what was intended. I bet something like encode the input as utf-8 was wanted.
fixes all renames in urllib, urllib2, urlparse modules in python3
There are many places can't be covered by 2to3, especially the str/unicode -> str/bytes change done in python3. This is a big patch incorporating all changes made in order to make python3 suite.py run without any single failure. It * adapt the introspect_handler_3 for case there are no __defaults__ * adds the ET_ENCODING variable for ET.fromstring ("unicode" in py3, "utf-8" in py2) * (re)adds various builtins to both python versions - memoryview to python 2.6 - bytes compatible with py3 to 2.6 and 2.7 and it changes few parts of tests/common.py in order to be compatible with python3 * new urlcompare method compares all components or url + parsed query string in a dictionary, so the ordering, neither quoting does not matter * bytes builtin has been added to 2.x and used in assertEqualMultiline
the sys reload trick does not work in python 3 and it is not needed, so let's remove that
Okay, as discussed via mail I merged this now. I try to build new packages in OBS:Server:Unstable to see if we have regressions. Thanks a lot for this! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This series of patches makes osc python3 compatible. In order to maintain backward compatibility, code run fine on 2.6, 2.7 and 3.3 without any change. The python2.6 suite.py, python2.7 suite.py and python3.3 suite.py worked well.