Accept binary streams in from_file input - #277
Open
rupayon123 wants to merge 1 commit into
Open
rupayon123 wants to merge 1 commit into
rupayon123 wants to merge 1 commit into
Conversation
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.
from_file()accepts file-like objects, but binary streams fail withAttributeError: bytes object has no attribute encodewhen preparing input for wkhtmltopdf. This affects BytesIO and files opened in binary mode.Encode text returned by read() as UTF-8 and pass binary data through unchanged. Document the distinction and preserve caller ownership of the stream. Binary input can then retain its declared HTML encoding instead of being decoded/re-encoded by the wrapper.
Three binary-stream regressions fail before the fix; four stream tests pass afterward on Python 3.11.15 and 3.12.13. They check in-memory UTF-8 bytes, a real binary temporary file containing Latin-1, a text-stream control, empty binary input, exact subprocess input, returned bytes, and open stream ownership.
The subprocess is mocked for these transport-boundary tests. wkhtmltopdf is not installed locally, so the renderer-dependent integration suite and actual PDF rendering were not run. No rendering or Windows-specific filename fix is claimed.
Prepared with AI assistance; the changed behavior and executed tests were checked before submission.