Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard Input / output does not work on LinuxMint 21.1 (Ubuntu 22.04) #55

Closed
RakonT opened this issue May 19, 2023 · 9 comments
Closed
Assignees
Labels

Comments

@RakonT
Copy link

RakonT commented May 19, 2023

Test case via command line:
echo "print('Hello World')" | cheetah-compile3 -

Error:

Traceback (most recent call last):
  File "/usr/bin/cheetah-compile3", line 3, in <module>
    _cheetah_compile()
  File "/usr/lib/python3/dist-packages/Cheetah/CheetahWrapper.py", line 662, in _cheetah_compile
    CheetahWrapper().main()
  File "/usr/lib/python3/dist-packages/Cheetah/CheetahWrapper.py", line 147, in main
    meth()
  File "/usr/lib/python3/dist-packages/Cheetah/CheetahWrapper.py", line 258, in compile
    self._compileOrFill()
  File "/usr/lib/python3/dist-packages/Cheetah/CheetahWrapper.py", line 344, in _compileOrFill
    self._compileOrFillStdin()
  File "/usr/lib/python3/dist-packages/Cheetah/CheetahWrapper.py", line 590, in _compileOrFillStdin
    sys.stdout.write(output)
TypeError: write() argument must be str, not bytes

Cause:

  • Trying to print unicode string (binary) with sys.sdtout.write()
  • This this is binary, sys.stdout.buffer.write() is needed

Solution:

  • Change source as follows:
  • File: /usr/lib/python3/dist-packages/Cheetah/CheetahWrapper.py
  • Line 582 to 590
        if self.isCompile:
            pysrc = TemplateClass.compile(file=sys.stdin, compilerSettings=compilerSettings, returnAClass=False)
            sys.stdout.buffer.write(pysrc)
        else:
            output = str(TemplateClass(file=sys.stdin, compilerSettings=compilerSettings)) 
            sys.stdout.write(output)
@phdru phdru self-assigned this May 20, 2023
@phdru phdru added the bug label May 20, 2023
@phdru
Copy link
Member

phdru commented May 20, 2023

Thanks! Care to send a pull request?

@RakonT
Copy link
Author

RakonT commented Jun 7, 2023

Thanks! Care to send a pull request?

If you still need help, I can give it a try. Never did a pull request before...

@phdru
Copy link
Member

phdru commented Jun 7, 2023

@RakonT Sure, go on! From June 11 to 19 I'll be on vacation, disconnected. Will be back June 20 and look at your effort.

@RakonT
Copy link
Author

RakonT commented Jun 8, 2023

Ok. I will give it a go. Enjoy your vacation!

RakonT pushed a commit to RakonT/cheetah3 that referenced this issue Jun 13, 2023
@RakonT
Copy link
Author

RakonT commented Jun 13, 2023

@phdru I may the changes to be as consistent as possible with existing code and backwards compatible for python2. I was unable to run regression tests but did test the code manually in my own environment. Hopefully, this acceptable. Thanks.
Pull request here: #56

@phdru
Copy link
Member

phdru commented Jul 3, 2023

Thanks! I'm working on running tests at GH Actions with Python and PyPy installed from conda-forge. I'll return to test the PR.

@phdru
Copy link
Member

phdru commented Jul 17, 2023

To make you informed: I'm close but not finished yet: https://github.com/CheetahTemplate3/cheetah3/actions/runs/5576456787

@phdru
Copy link
Member

phdru commented Jul 19, 2023

Merged. Thank you very much!

@phdru phdru closed this as completed in a0792ee Jul 19, 2023
phdru added a commit that referenced this issue Aug 8, 2023
fixed #55 printing to stdout with encoded output
@phdru
Copy link
Member

phdru commented Aug 9, 2023

I release version 3.3.2 with your fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants