Conversation
…nd import commands calls (both renamed in Python 3 to urllib.parse and subprocess respectively, neither of which is actually referenced in this file), switch has_key() to the in operator, parenthesize the three print statements, rewrite the except KeyError, e: clause to the modern except KeyError as e: form, and narrow the bare except: on the error_codez lookup to except KeyError: so a non-dict return value or AttributeError surfaces instead of being silently masked. This is the same Python 2 → 3 migration that earlier sessions applied to armory_service.py, pending.py, msc_apps.py, and rpcclient.py in the api package, and lets the WSGI entry point (msc_apps.py, which imports this module transitively) start under Python 3
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
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.
Summary
api/pushtx.pystill uses five Python 2 idioms that prevent the file from being imported on Python 3 (and therefore prevent the entire WSGI app from starting, since msc_apps.py imports this module transitively):import urlparse—urlparsewas renamed tourllib.parsein Python 3. The import is unused in this file (the onlyurlparse.call in the wholeapi/package is in msc_apps.py, which still has its own copy of the same broken import) so it can simply be removed.import commands—commandswas removed in Python 3 in favor ofsubprocess. The import is only there for the (commented-out)commands.getoutput(...)call, so it can also be removed.response_dict.has_key(field)—has_keywas removed from dict in Python 2.3. Usefield in response_dict.printstatements without parentheses —printis a function in Python 3.except KeyError, e:— the comma form was removed in Python 3; the parser tries to evaluateeas an expression and raises SyntaxError.except:on the error_codez lookup — narrows toexcept KeyError:so a non-dict return value or AttributeError surfaces instead of being silently masked.This is the same Python 2 → 3 migration that earlier sessions applied to armory_service.py, pending.py, msc_apps.py, and rpcclient.py in the api package. msc_apps.py was fixed for the SyntaxError but only the offending lines were addressed; pushtx.py was not touched, and the WSGI process still refused to start because msc_apps.py imports the whole api/ package on startup.
Testing
python3 -c 'import ast; ast.parse(open("api/pushtx.py").read())reports no SyntaxError. The file now parses under Python 3 and no longer referencesurlparse,commands,has_key, or the Python 2 except clause form.