Repository navigation
fix: write StarDict metadata as bytes on Python 3 - #149
Merged
skywind3000 merged 1 commit intoNov 2, 2026
Merged
Conversation
Owner
|
thx |
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.
Problem
Fixes #91.
export_stardict()opens its.ifofile in binary mode but writes text strings to it. On Python 3 even a single ASCII entry raisesTypeError: a bytes-like object is required, not 'str', leaving an incomplete export.Change
Write the metadata with byte-string templates, preserving the existing binary file mode and LF output. Keep the book title encoded as UTF-8 and encode the generated date as ASCII. The word ordering and
.idx/.dictpaths are unchanged.Add two standard-library regression tests covering an empty dictionary and a multilingual export. They check the UTF-8 title, case-sensitive sorting tie-break, binary offsets/lengths, actual index size, and metadata contents. No test dependency or dictionary download is needed.
Verification
FAILED (errors=2), both at the first.ifo.write().Ran 2 tests/OKon Python 3.12.14, Python 3.14.7, and Linux Python 2.7.18 (python:2.7-slim).git diff --checkpasses.The reproducer and tests above were executed locally.