Skip to content

Auto-generated config files cause problems with LC_ALL=C #735

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
BenWiederhake opened this issue Mar 4, 2018 · 2 comments
Closed

Auto-generated config files cause problems with LC_ALL=C #735

BenWiederhake opened this issue Mar 4, 2018 · 2 comments

Comments

@BenWiederhake
Copy link

BenWiederhake commented Mar 4, 2018

Expected behavior: The command LC_ALL=C bpython3 opens a new bpython session.

Actual behavior: The command LC_ALL=C bpython3 croaks immediately, with this message:

Traceback (most recent call last):
  File "/usr/bin/bpython3", line 11, in <module>
    load_entry_point('bpython==0.17.1', 'console_scripts', 'bpython')()
  File "/usr/lib/python3/dist-packages/bpython/curtsies.py", line 141, in main
    help=_("start by pasting lines of a file into session")),
  File "/usr/lib/python3/dist-packages/bpython/args.py", line 106, in parse
    loadini(config, options.config)
  File "/usr/lib/python3/dist-packages/bpython/config.py", line 140, in loadini
    if not config.read(config_path):
  File "/usr/lib/python3.6/configparser.py", line 697, in read
    self._read(fp, filename)
  File "/usr/lib/python3.6/configparser.py", line 1015, in _read
    for lineno, line in enumerate(fp, start=1):
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1597: ordinal not in range(128)

Sanity check: bpython3 (without any locale stuff) runs normally. LC_ALL=C bpython runs normally, probably because python2 doesn't differentiate between string types (bytestring vs. ASCII string).

Meaning of the error message: It very likely refers to the file ~/.config.bpython/config, which contains:

# The name of a helper executable that should perform pastebin upload on
# bpython’s behalf. If unset, bpython uploads pastes to bpaste.net. (default: )
#pastebin_helper = gist.py

I never touched bpython's config files, so the file must be autogenerated. Note the special character in bpython’s, which starts at byte 1597 in my copy of the file. This is a unicode character, specifically it's the three bytes e2 80 99. This is obviously not valid ASCII.

Manual workaround: use your favorite text editor to replace by '. This works for now.

Long-term workaround: The config parser should be changed to always assume UTF-8, if not indicated otherwise. Otherwise, it would be impossible for a user to specify paths and program names that contain non-ASCII characters. Also, it's a bit funny that the "parsing" of a comment can make bpython fail.

@sebastinas
Copy link
Contributor

This file is not auto-generated and requires explicit user action to be created (either via the configuration editing feature or by manually creating it). It seems you did before #497 was fixed.

bpython now exists with an error message with instructions for the user. However, I don't think its bpython's job to second guess the user's decision on the default encoding. With #497 fixed, bpython only every creates a config file purely consisting of ASCII characters. Everything else if up to the user.

@BenWiederhake
Copy link
Author

I guess that makes sense. Thanks for the explanation.

Does the exception also contain the byte offset? That would make it much easier to find the offending character. If it's not trivial, leave it like that, it's already a great help to know that it's "my" file that was faulty.

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

No branches or pull requests

2 participants