Skip to content
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

Support Python 3 in addition to Python 2. #7

Closed
wants to merge 1 commit into from

Conversation

mahiuchun
Copy link

b'\xaa'[0] gives different results in Python 2 and 3. So at_offset_is() is added to work around this issue. Other changes work in both Python 2 and 3.

idx = 0
names = ARCHIVE_ORDERS[VERSION]
for start, end in itertools.izip(gzip_starts,
for start, end in zip(gzip_starts,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix up alignment on next line.

Also add a commit description which explains the at_is_offset thing (you put it in the PR, but that's a GH thing, not a git thing).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I force pushed a new commit.

- Use print() function; add corresponding future import for Python 2.
- Open binary files in binary mode.
- Add `b` prefix to strings containing binary data. It makes the strings `bytes` in Python 3 while leave the strings unchanged in Python 2.
- Due to the type difference mentioned above, slicing is used in place of subscription to make the code portable between Python 2 and 3. A helper function at_offset_is() is added to keep code short.
- xrange() -> range(),  itertools.izip() -> zip(), .iteritems() -> .items(); the left hand side only exists in Python 2.
- Remove unused `urllib` import.
@imirkin
Copy link
Owner

imirkin commented Apr 30, 2020

Sorry, I completely forgot -- The new official location for this script is:

https://github.com/envytools/firmware

Could you resubmit against that?

@mahiuchun mahiuchun closed this Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants