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

curses.tigetstr() returns bytes, but curses.tparm() expects a string #54779

Closed
jwilk mannequin opened this issue Nov 28, 2010 · 13 comments
Closed

curses.tigetstr() returns bytes, but curses.tparm() expects a string #54779

jwilk mannequin opened this issue Nov 28, 2010 · 13 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jwilk
Copy link
Mannequin

jwilk mannequin commented Nov 28, 2010

BPO 10570
Nosy @vstinner, @jwilk, @akheron
Files
  • issue10570.patch
  • 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:

    assignee = None
    closed_at = <Date 2011-11-06.07:40:28.620>
    created_at = <Date 2010-11-28.23:38:53.587>
    labels = ['type-bug', 'library']
    title = 'curses.tigetstr() returns bytes, but curses.tparm() expects a string'
    updated_at = <Date 2011-11-06.13:55:42.627>
    user = 'https://github.com/jwilk'

    bugs.python.org fields:

    activity = <Date 2011-11-06.13:55:42.627>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-11-06.07:40:28.620>
    closer = 'Arfrever'
    components = ['Library (Lib)']
    creation = <Date 2010-11-28.23:38:53.587>
    creator = 'jwilk'
    dependencies = []
    files = ['23595']
    hgrepos = []
    issue_num = 10570
    keywords = ['patch', 'needs review']
    message_count = 13.0
    messages = ['122746', '122781', '141657', '141770', '146873', '146879', '146880', '146913', '146963', '146964', '147136', '147145', '147158']
    nosy_count = 7.0
    nosy_names = ['vstinner', 'nadeem.vawda', 'jwilk', 'Arfrever', 'klausman', 'python-dev', 'petri.lehtinen']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10570'
    versions = ['Python 3.2', 'Python 3.3']

    @jwilk
    Copy link
    Mannequin Author

    jwilk mannequin commented Nov 28, 2010

    $ 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.

    @jwilk jwilk mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 28, 2010
    @jwilk
    Copy link
    Mannequin Author

    jwilk mannequin commented Nov 29, 2010

    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
    curses.tparm() expects a Unicode string as first argument. As a consequence
    even the example given in the documentation doesn't work:

    >>> 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

    @klausman
    Copy link
    Mannequin

    klausman mannequin commented Aug 5, 2011

    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.

    @vstinner
    Copy link
    Member

    vstinner commented Aug 8, 2011

    See also bpo-12567.

    @akheron
    Copy link
    Member

    akheron commented Nov 2, 2011

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 2, 2011

    New changeset e41663970ca5 by Victor Stinner in branch '3.2':
    Issue bpo-10570: curses.tigetstr() is now expecting a byte string, instead of a
    http://hg.python.org/cpython/rev/e41663970ca5

    New changeset ab11a6a73683 by Victor Stinner in branch 'default':
    (Merge 3.2) Issue bpo-10570: curses.tigetstr() is now expecting a byte string,
    http://hg.python.org/cpython/rev/ab11a6a73683

    @vstinner
    Copy link
    Member

    vstinner commented Nov 2, 2011

    "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 :-)).

    @vstinner vstinner closed this as completed Nov 2, 2011
    @akheron
    Copy link
    Member

    akheron commented Nov 3, 2011

    It seems that putp() should also accept only bytes, because it's used to output terminal commands. It's currently expecting a str.

    @akheron akheron reopened this Nov 3, 2011
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 3, 2011

    New changeset 38f4a251608f by Victor Stinner in branch '3.2':
    Issue bpo-10570: curses.putp() is now expecting a byte string, instead of a
    http://hg.python.org/cpython/rev/38f4a251608f

    New changeset 08f44eb760a6 by Victor Stinner in branch 'default':
    (Merge 3.2) Issue bpo-10570: curses.putp() is now expecting a byte string, instead
    http://hg.python.org/cpython/rev/08f44eb760a6

    @vstinner
    Copy link
    Member

    vstinner commented Nov 3, 2011

    It seems that putp() should also accept only bytes,
    because it's used to output terminal commands.

    Ok, here is another fix for Python 3.2 and 3.3. I'm closing the issue again.

    @vstinner vstinner closed this as completed Nov 3, 2011
    @Arfrever
    Copy link
    Mannequin

    Arfrever mannequin commented Nov 6, 2011

    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.
    (curses.tigetstr() still expects a unicode string and returns a bytes string.)

    @Arfrever Arfrever mannequin reopened this Nov 6, 2011
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 6, 2011

    New changeset 3a0a94797ac5 by Petri Lehtinen in branch '3.2':
    curses.tparm() is expecting a byte string, not curses.tigetstr()
    http://hg.python.org/cpython/rev/3a0a94797ac5

    New changeset 626c6c7f3af6 by Petri Lehtinen in branch 'default':
    curses.tparm() is expecting a byte string, not curses.tigetstr()
    http://hg.python.org/cpython/rev/626c6c7f3af6

    @Arfrever Arfrever mannequin closed this as completed Nov 6, 2011
    @vstinner
    Copy link
    Member

    vstinner commented Nov 6, 2011

    The entry in Misc/NEWS mentions the change in curses.tigetstr(),
    but actually curses.tparm() has been changed

    Woops, thanks for fixing the NEWS file :-)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants