Use either brotli or brotlicffi.#1618
Merged
Merged
Conversation
…d for PyPy and others)
j178
reviewed
Apr 30, 2021
Comment on lines
107
to
112
| if hasattr(self.decompressor, "decompress"): | ||
| self._decompress = self.decompressor.decompress | ||
| # The 'brotlicffi' package. | ||
| self._decompress = self.decompressor.decompress # pragma: nocover | ||
| else: | ||
| # The 'brotli' package. | ||
| self._decompress = self.decompressor.process # pragma: nocover |
Contributor
There was a problem hiding this comment.
I thinkbrotlicffi also has a process alias for decompress:
How about just use self.decompressor.process?
Contributor
Author
There was a problem hiding this comment.
True. Tho I double checked and the brotlipy package doesn't, so what we want to do here depends on if we want to take care around the possibility that on some systems the older brotlipy package might have been installed. (Or not.)
- If we do care about that awkward case, then we should just update the comment strings here.
- If we don't case about that case, then we should just always use
Decompressor().process().
Perhaps we could check which of brotli vs brotlipy is installed the _compat.py module, and raise an error if brotlipy is installed and is shadowing the brotli namespace.
For example:
if hasattr(brotli.Decompressor, 'decompress'):
raise RuntimeError(
"The brotlipy library appears to be installed, and is shadowing the 'brotli' namespace. "
"Uninstall brotlipy and use brotlicffi instead."
)
j178
approved these changes
Apr 30, 2021
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.
See #1605 (comment)
brotlipackage is recommended for CPython.brotlicffipackage is recommended for PyPy.Note the following:
Decompressor.decompressifbrotlicffiis installed, butDecompressor.processifbrotliis installed.Decompressor.finish()ifbrotlicffiis installed.brotli.errorinstead ofbrotli.Errorbecause it is supported as a synonym in both packages.Also worth calling out the the older
brotlipypackage might be installed on the system. In which case it will shadow thebrotlipackage namespace. Ug.