-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-121639: Deduplicate reinitialization setup for ZipExtFile when seeking #121640
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
base: main
Are you sure you want to change the base?
Conversation
| raise RuntimeError("Bad password for file %r" % self._zinfo.orig_filename) | ||
| return h | ||
|
|
||
| def _init_read(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def _init_read(self): | |
| def _reset_read_state(self): |
| if h != check_byte: | ||
| raise RuntimeError("Bad password for file %r" % zipinfo.orig_filename) | ||
|
|
||
| self._init_read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"init" implies there is some one time setup/initialization going on to me. I'd suggest maybe _reset_read_state
| self._init_read() | |
| self._reset_read_state() |
| self._offset = 0 | ||
| self._decompressor = _get_decompressor(self._compress_type) | ||
| self._eof = False | ||
| self._init_read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self._init_read() | |
| self._reset_read_state() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, this is a really nice refactor! I have one suggestion on naming but seems good otherwise.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Fixes: gh-121639
Related to: #81719
Add
ZipExtFile._init_read()to perform initialization and any reinitialization if necessary. The name_init_read()was chosen to match the surrounding_init_decrypter()method but these might need to lose the leading_in a different PR if we're going to allow subclassingZipExtFile.Since we now check the decryption check byte in
_init_decrypter(), I think it would also make sense for_init_decrypter()to return the decrypter (or nothing) rather than the check byte but that would change the (_internal) api so I haven't added it here. Happy to update this PR with that change if it is acceptable.