diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-03-14 20:22:12 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-03-14 20:22:12 (GMT) |
commit | 05bab93339308d330d6bd718575212ae2b3dc46d (patch) | |
tree | bb17df498b687ce4b5fafaa7f4629a5cfba84851 /Lib/idlelib/PyShell.py | |
parent | c5ceb0aaafa3064c8f301ebbedf44f421d3f3eba (diff) | |
download | cpython-05bab93339308d330d6bd718575212ae2b3dc46d.zip cpython-05bab93339308d330d6bd718575212ae2b3dc46d.tar.gz cpython-05bab93339308d330d6bd718575212ae2b3dc46d.tar.bz2 |
Issue #14200: Idle shell crash on printing non-BMP unicode character.
UnicodeEncodeError is raised for strings contains non-BMP characters.
For eval results unicode escaping is used, print() calls display
exception with traceback as usual.
Diffstat (limited to 'Lib/idlelib/PyShell.py')
-rw-r--r-- | Lib/idlelib/PyShell.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index f884b28..6b75a8d 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -1221,6 +1221,16 @@ class PyShell(OutputWindow): self.set_line_and_column() def write(self, s, tags=()): + if isinstance(s, str) and len(s) and max(s) > '\uffff': + # Tk doesn't support outputting non-BMP characters + # Let's assume what printed string is not very long, + # find first non-BMP character and construct informative + # UnicodeEncodeError exception. + for start, char in enumerate(s): + if char > '\uffff': + break + raise UnicodeEncodeError("UCS-2", char, start, start+1, + 'Non-BMP character not supported in Tk') try: self.text.mark_gravity("iomark", "right") OutputWindow.write(self, s, tags, "iomark") |