diff -r 9b450b19aa11 Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py Sat Jul 12 03:20:40 2014 +0200 +++ b/Lib/idlelib/IOBinding.py Sat Jul 12 14:19:37 2014 +0300 @@ -65,6 +65,8 @@ coding_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)', re.ASCII) blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII) +# characters above the range (U+0000-U+FFFF) +non_bmp_re = re.compile(r'[^\x00-\uffff]') def coding_spec(data): """Return the encoding declaration according to PEP 263. @@ -231,6 +233,7 @@ if firsteol: self.eol_convention = firsteol.group(0) chars = self.eol_re.sub(r"\n", chars) + chars = self._fix_non_bmp(chars) self.text.delete("1.0", "end") self.set_filename(None) self.text.insert("1.0", chars) @@ -313,6 +316,12 @@ pass return None, False # None on failure + def _fix_non_bmp(self, s): + if s and max(s) > '\uffff': + # Tk doesn't support non-BMP characters + s = non_bmp_re.sub(lambda m: '\\U%08x' % ord(m.group()), s) + return s + def maybesave(self): if self.get_saved(): return "yes"