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

cli fails to write to stdout #435

Closed
kemlath opened this issue Oct 5, 2022 · 5 comments · Fixed by #457
Closed

cli fails to write to stdout #435

kemlath opened this issue Oct 5, 2022 · 5 comments · Fixed by #457

Comments

@kemlath
Copy link

kemlath commented Oct 5, 2022

icalendar.version = '4.1.0'
python3.8 on ubuntu 20.04

Running "icalendar view file.ics" throws a TypeError: write() argument must be str, not bytes in

the problem is in main() in cli.py

subparser.add_argument( '-o', dest='output_handle', metavar='OUTPUT', type=argparse.FileType('w'), default=sys.stdout, help='output file (default=<stdout>)')

this, per default passes sys.stdout as output_handle in def view(input_handle, output_handle): which fails when bytes are written to it instead of a str during output_handle.write(_template.format(....).encode('utf-8')

As long as argparse.FileType does not properly recognize binary mode strings (e.g. 'wb') a possible fix would be to default to sys.stdout.buffer instead of sys.stdout

@niccokunzmann
Copy link
Member

@kemlath Thanks for reporting this! Since you know how to fix this, would you like to create a pull request?
Also, personally, I do like tests to make sure we do not break your change in the future. Is there a way we could test this? I guess so..

Does this only happen with a specific ICS file or with all of them? Can you attach file.ics?

@kemlath
Copy link
Author

kemlath commented Oct 11, 2022

I'll fork the repo and create a pull request.
There are a few more issues with the cli that came up since then, I'll fix em all and create a pull request.

Really the cli should fail all the time under python3 independent on what you write to sys.stdout as long as you encode it to bytes.

@kemlath
Copy link
Author

kemlath commented Oct 11, 2022

I just found out that the version of icalendar I got from pypi is version '4.1.0' whereas the current master branch is version 5.0x and has a rather different cli.py which no longer has the above described problem.

Sorry about the confusion

@niccokunzmann
Copy link
Member

This calls for creating a new release #429.

@jacadzaca jacadzaca linked a pull request Oct 20, 2022 that will close this issue
@niccokunzmann
Copy link
Member

The new version is released. v5.0.0

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 a pull request may close this issue.

3 participants