Skip to content

Accept binary streams in from_file input - #277

Open
rupayon123 wants to merge 1 commit into
JazzCore:masterfrom
rupayon123:contribution/binary-output-validation-20260921
Open

rupayon123 wants to merge 1 commit into
JazzCore:masterfrom
rupayon123:contribution/binary-output-validation-20260921

Conversation

@rupayon123

Copy link
Copy Markdown

from_file() accepts file-like objects, but binary streams fail with AttributeError: bytes object has no attribute encode when 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.

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.

1 participant