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
IDLE: checksyntax() doesn't support Unicode? #48258
Comments
IDLE checksyntax() function doesn't support Unicode. Example with $ ./python Tools/scripts/idle
Exception in Tkinter callback
Traceback (most recent call last):
File "/home/haypo/prog/py3k/Lib/tkinter/__init__.py", line 1405, in
__call__
return self.func(*args)
File "/home/haypo/prog/py3k/Lib/idlelib/ScriptBinding.py", line 124,
in run_module_event
code = self.checksyntax(filename)
File "/home/haypo/prog/py3k/Lib/idlelib/ScriptBinding.py", line 86,
in checksyntax
source = f.read()
File "/home/haypo/prog/py3k/Lib/io.py", line 1719, in read
decoder.decode(self.buffer.read(), final=True))
File "/home/haypo/prog/py3k/Lib/io.py", line 1294, in decode
output = self.decoder.decode(input, final=final)
File "/home/haypo/prog/py3k/Lib/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
87: ordinal not in range(128) To open an ASCII terminal on Linux, you can for example use xterm with |
Hum, the problem is that IDLE asks io.open() to detect the charset I wrote a patch to detect the encoding. Python code (detect_encoding() |
Ah! tokenize has already a method detect_encoding(). My new patch uses |
Notice that there is also IOBinding.coding_spec. Not sure whether this |
loewis wrote:
Oh! IOBinding reimplement many features now available in Python like So IDLE reimplemented coding detection twice: once in IOBinding and I changed IDLE behaviour: IOBinding._decode() used the locale encoding def detect_encoding(filename, default=None):
with open(filename, 'rb') as f:
encoding, line = tokenize.detect_encoding(f.readline)
if (not line) and default:
return default
return encoding
...
encoding = detect_encoding(filename, locale_encoding) Please review and test my patch (which becomes longer and longer) :-) |
It did not *re*implement. The implementation in IOBinding predates all |
@loewis: Ok, I didn't know. I think that it's better to reuse existing I also compared the implementations of encoding detection, and the I saw an interesting test in IDLE code: it checks the charset. So I |
I can't reproduce the problem. It works fine for me, displaying the box |
@loewis: I guess that your locale is still UTF-8. On Linux (Ubuntu Gutsy) using "env -i DISPLAY=$DISPLAY HOME=$HOME $ locale
LANG=
LC_ALL=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
...
$ python3.0
>>> from idlelib.IOBinding import encoding
>>> encoding
'ansi_x3.4-1968'
>>> import locale
>>> locale.getdefaultlocale()
(None, None)
>>> locale.nl_langinfo(locale.CODESET)
'ANSI_X3.4-1968' In this environment, IDLE is unable to detect IDLE uses open(filename, 'r'): it doesn't specify the charset. In this To sum IDLE: if your locale is UTF-8, you will be able to open an |
To refute this claim, I reported that locale.getpreferredencoding When opening iso.py, I get a pop window titled "Decoding error", So I still can't reproduce the problem. I don't understand why you say that IDLE uses open(filename, 'r'). # open the file in binary mode so that we can handle
# end-of-line convention ourselves.
f = open(filename,'rb') |
IDLE opens the script many than once. There are two cases: (1) uses IOBinding and fails to open ISO-8859-1 file with UTF-8 (2) uses ScriptBinding and fails to open UTF-8 file with ASCII locale. About the initial problem (idle-3.0rc1-quits-when-run.py), yes, I |
This patch has two problems:
|
This is still a problem on my WinXP 3.0rc3 with |
Here is a new patch that fixes this issue, and the duplicate issues It doesn't try to eliminate code duplication, but fixes coding_spec by |
I vote for fixing this too. This might be simplified/another example of # -- coding: utf-8 -- in IDLE prints this:
>>>
ěščřžýáĂĂ© When running this script under python command line from another editor, |
Committed as r68730 and r68731. |
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: