Skip to content

Unicode errors in status bar #505

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

Closed
thomasballinger opened this issue Mar 10, 2015 · 5 comments
Closed

Unicode errors in status bar #505

thomasballinger opened this issue Mar 10, 2015 · 5 comments

Comments

@thomasballinger
Copy link
Member

@Julian found unicode errors on master: https://bpaste.net/show/df5269cf4f95

It seems that passing a bytestring to paint_statusbar ends poorly, but not sure how this is occurring. It seems to have happened at startup in the above example.

(bpython)tom-mba:bpython tomb$ bpython
bpython version 0.15.dev85 on top of Python 2.7.9 /Users/tomb/.virtualenvs/bpython/bin/python2.7
>>> from bpython.curtsiesfrontend import replpainter
>>> from bpython.curtsies import repl
>>> import curtsies
>>> curtsies.__version__
'0.2.3'
>>> replpainter.paint_statusbar(1, 100, b'adsfasdf', repl.config)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/tomb/Dropbox/code/bpython/bpython/curtsiesfrontend/replpainter.py", line 215, in paint_statusbar
    return fsarray([func(msg.ljust(columns))[:columns]])
  File "/Users/tomb/.virtualenvs/bpython/lib/python2.7/site-packages/curtsies/formatstring.py", line 615, in fmtstr
    string = FmtStr.from_str(string)
  File "/Users/tomb/.virtualenvs/bpython/lib/python2.7/site-packages/curtsies/formatstring.py", line 169, in from_str
    return FmtStr(Chunk(s))
  File "/Users/tomb/.virtualenvs/bpython/lib/python2.7/site-packages/curtsies/formatstring.py", line 70, in __init__
    raise ValueError("unicode string required, got %r" % string)
ValueError: unicode string required, got 'adsfasdf                                                                                            '
>>>
@thomasballinger
Copy link
Member Author

This could be fixed without reproducing Julian's original problem by making the code above work.

@adamzap
Copy link

adamzap commented May 27, 2015

Is this as simple as converting msg to unicode here?

If so, I can submit a PR. I'm new to the codebase, so I'm not sure if it's a more complex issue.

@thomasballinger
Copy link
Member Author

While it would be nice to know what was causing this (how was paint_statusbar getting called with a bytestring?), yes that should fix the issue.

Unfortunately we've lost the original problem because I didn't paste it in here :( so we can't try to reproduce it. I'm reticent about making a change that purports to change an issue we can't reproduce. You might try putting an assertion there that the input is unicode and playing around with it to see if you can trigger it?

@thomasballinger
Copy link
Member Author

This might have been the original problem:

(bpython)tomb@tom-mba (literal-eval-with-names) bpython$ bpython
bpython version 0.15.dev196 on top of Python 2.7.10 /Users/tomb/.virtualenvs/bpython/bin/python2.7
>>> from ast import U
Traceback (most recent call last):
  File "/Users/tomb/.virtualenvs/bpython/bin/bpython", line 9, in <module>
    load_entry_point('bpython==0.15.dev196', 'console_scripts', 'bpython')()
  File "/Users/tomb/Dropbox/code/bpython/bpython/curtsies.py", line 88, in main
    interactive=(not exec_args))
  File "/Users/tomb/Dropbox/code/bpython/bpython/curtsies.py", line 189, in mainloop
    process_event(e)
  File "/Users/tomb/Dropbox/code/bpython/bpython/curtsies.py", line 157, in process_event
    array, cursor_pos = repl.paint()
  File "/Users/tomb/Dropbox/code/bpython/bpython/curtsiesfrontend/repl.py", line 1293, in paint
    arr[statusbar_row, :] = paint.paint_statusbar(1, width, self.status_bar.current_line, self.config
)
  File "/Users/tomb/Dropbox/code/bpython/bpython/curtsiesfrontend/replpainter.py", line 214, in paint
_statusbar
    return fsarray([func(msg.ljust(columns))[:columns]])
  File "/Users/tomb/.virtualenvs/bpython/lib/python2.7/site-packages/curtsies/formatstring.py", line
615, in fmtstr
    string = FmtStr.from_str(string)
  File "/Users/tomb/.virtualenvs/bpython/lib/python2.7/site-packages/curtsies/formatstring.py", line
169, in from_str
    return FmtStr(Chunk(s))
  File "/Users/tomb/.virtualenvs/bpython/lib/python2.7/site-packages/curtsies/formatstring.py", line
70, in __init__
    raise ValueError("unicode string required, got %r" % string)
ValueError: unicode string required, got '
                                          '

It's finicky to reproduce, but we can see the problem is getting a blank line that isn't unicode.

@thomasballinger
Copy link
Member Author

It looks like msg is at some point an empty bytestring instead of an empty unicode string

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

No branches or pull requests

2 participants