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
curses.tigetstr() returns bytes, but curses.tparm() expects a string #54779
Comments
$ python3 --version
Python 3.1.3 $ python3 setup.py bdist upload --sign
[snip]
Traceback (most recent call last):
File "setup.py", line 71, in <module>
cmdclass = dict(build_py=build_py)
File "/usr/local/lib/python3.1/distutils/core.py", line 149, in setup
dist.run_commands()
File "/usr/local/lib/python3.1/distutils/dist.py", line 919, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python3.1/distutils/dist.py", line 938, in run_command
cmd_obj.run()
File "/usr/local/lib/python3.1/distutils/command/upload.py", line 66, in run
self.upload_file(command, pyversion, filename)
File "/usr/local/lib/python3.1/distutils/command/upload.py", line 155, in upload_file
body.write(value)
TypeError: 'str' does not support the buffer interface Without --sign it works just fine. |
Ugh. Please disregard the first message. What I wanted to write is: In Python 3.1.3, curses.tigetstr() returns bytes (which makes sense), but >>> from curses import *
>>> setupterm()
>>> tparm(tigetstr("cup"), 5, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not bytes |
This bug is still not fixed and basically makes the curses module unusable except for very narrow use cases. Unfortunately, my C-fu is very weak, otherwise I'd try to make a patch. |
See also bpo-12567. |
I'm not a curses expert, but after digging a while, I believe that I now understand what these functions are doing. tigetstr() returns a "format string" (bytes) and tparm() does substitutions and returns a command string (bytes) for the terminal. I don't believe that the first parameter to tparm() (the format string) is ever constructed by hand, because it's terminal specific. The value is obtained from the terminfo database by calling tigetstr() instead. Furthermore, tigetstr() returns binary data, for which bytes is the only sane representation, and therefore tparm() should expect bytes instead of str. Attached a patch that fixes this. |
New changeset e41663970ca5 by Victor Stinner in branch '3.2': New changeset ab11a6a73683 by Victor Stinner in branch 'default': |
"I don't believe that the first parameter to tparm() (the format string) is ever constructed by hand, because it's terminal specific. The value is obtained from the terminfo database by calling tigetstr() instead. Furthermore, tigetstr() returns binary data, for which bytes is the only sane representation, and therefore tparm() should expect bytes instead of str." Ok, it sounds to be fair. I wrote a patch based on yours (except that Python crashes with your patch :-)). |
It seems that putp() should also accept only bytes, because it's used to output terminal commands. It's currently expecting a str. |
New changeset 38f4a251608f by Victor Stinner in branch '3.2': New changeset 08f44eb760a6 by Victor Stinner in branch 'default': |
Ok, here is another fix for Python 3.2 and 3.3. I'm closing the issue again. |
The entry in Misc/NEWS mentions the change in curses.tigetstr(), but actually curses.tparm() has been changed. Please fix that entry to avoid confusion. |
New changeset 3a0a94797ac5 by Petri Lehtinen in branch '3.2': New changeset 626c6c7f3af6 by Petri Lehtinen in branch 'default': |
Woops, thanks for fixing the NEWS file :-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: