mako.cmd.cmdline() reads template as binary but writes as text resulting in garbled newlines on Windows
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
Research direction
Start by reproducing the Windows script in the issue, then inspect cmd.py's cmdline() and util.py's read_file() to compare their file modes and newline handling. Done means rendering the shown template produces normal single line endings in rendered_file rather than doubled carriage returns.
Written by the indexing model from the issue text.
Description
The issue here can be demonstrated by running the following script on Windows:
import mako.cmd
import sys
with open("template_file", "w") as f:
print("Line 1", file=f)
print("Line 2", file=f)
print("Line 3", file=f)
sys.argv.append("--output-file")
sys.argv.append("rendered_file")
sys.argv.append("template_file")
assert sys.argv[1:] == ["--output-file", "rendered_file", "template_file"]
# pass sys.argv off to mako
mako.cmd.cmdline()
# awkward \r\r\n EOL sequences is what is written to disk
with open("rendered_file", "rb") as f:
rendered = f.read()
assert rendered == b'Line 1\r\r\nLine 2\r\r\nLine 3\r\r\n'
# If you were to open/read in text mode it shows up as two newlines
with open("rendered_file", "rt") as f:
rendered = f.read()
assert rendered == 'Line 1\n\nLine 2\n\nLine 3\n\n'
It's odd that read_file() in util.py opens / reads in binary mode but then cmdline() in cmd.py opens / writes in text mode. The whole point of using text mode should be to convert EOLs on Windows, but it does not do this correctly.
- Dominant language
- Python
- Stars
- 459
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sqlalchemy/mako
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
sqlalchemy/mako#432 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
sqlalchemy/mako#417 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
sqlalchemy/mako#392 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
sqlalchemy/mako#382 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
sqlalchemy/mako#344 · 2 comments ·
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100