diff -r cf70f030a744 Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/idlelib/EditorWindow.py Mon Jun 23 22:02:58 2014 +0300 @@ -394,6 +394,12 @@ # byte-to-byte conversion return filename.decode('iso8859-1') + try: + unicode + except NameError: # no unicode support + def _filename_to_unicode(self, filename): + return filename + def new_callback(self, event): dirname, basename = self.io.defaultfilename() self.flist.new(dirname) diff -r cf70f030a744 Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/idlelib/IOBinding.py Mon Jun 23 22:02:58 2014 +0300 @@ -20,6 +20,14 @@ from idlelib.configHandler import idleConf try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + +try: from codecs import BOM_UTF8 except ImportError: # only available since Python 2.3 @@ -34,7 +42,10 @@ pass # Encoding for file names -filesystemencoding = sys.getfilesystemencoding() +try: + filesystemencoding = sys.getfilesystemencoding() +except AttributeError: # no unicode support + filesystemencoding = None encoding = "ascii" if sys.platform == 'win32': @@ -66,7 +77,7 @@ # situation occurs on Mac OS X encoding = 'ascii' codecs.lookup(encoding) - except (ValueError, LookupError): + except (ValueError, LookupError, AttributeError): pass encoding = encoding.lower() @@ -260,7 +271,7 @@ firsteol = self.eol_re.search(chars) if firsteol: self.eol_convention = firsteol.group(0) - if isinstance(self.eol_convention, unicode): + if isinstance(self.eol_convention, _unicode): # Make sure it is an ASCII string self.eol_convention = self.eol_convention.encode("ascii") chars = self.eol_re.sub(r"\n", chars) @@ -320,6 +331,12 @@ pass return chars + try: + unicode + except NameError: + def decode(self, chars): + return chars + def maybesave(self): if self.get_saved(): return "yes" @@ -535,7 +552,7 @@ self.opendialog = tkFileDialog.Open(master=self.text, filetypes=self.filetypes) filename = self.opendialog.show(initialdir=dir, initialfile=base) - if isinstance(filename, unicode): + if isinstance(filename, _unicode): filename = filename.encode(filesystemencoding) return filename @@ -557,7 +574,7 @@ self.savedialog = tkFileDialog.SaveAs(master=self.text, filetypes=self.filetypes) filename = self.savedialog.show(initialdir=dir, initialfile=base) - if isinstance(filename, unicode): + if isinstance(filename, _unicode): filename = filename.encode(filesystemencoding) return filename diff -r cf70f030a744 Lib/idlelib/OutputWindow.py --- a/Lib/idlelib/OutputWindow.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/idlelib/OutputWindow.py Mon Jun 23 22:02:58 2014 +0300 @@ -40,7 +40,7 @@ if isinstance(s, str): try: s = unicode(s, IOBinding.encoding) - except UnicodeError: + except UnicodeError, NameError: # some other encoding; let Tcl deal with it pass self.text.insert(mark, s, tags) diff -r cf70f030a744 Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/idlelib/PyShell.py Mon Jun 23 22:02:58 2014 +0300 @@ -37,6 +37,14 @@ from idlelib import RemoteDebugger from idlelib import macosxSupport +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + IDENTCHARS = string.ascii_letters + string.digits + "_" HOST = '127.0.0.1' # python execution server on localhost loopback PORT = 0 # someday pass in host, port for remote debug capability @@ -1074,7 +1082,7 @@ line = self.text.get("iomark", "end-1c") if len(line) == 0: # may be EOF if we quit our mainloop with Ctrl-C line = "\n" - if isinstance(line, unicode): + if isinstance(line, _unicode): from idlelib import IOBinding try: line = line.encode(IOBinding.encoding) @@ -1310,7 +1318,12 @@ return 'disabled' return super(PyShell, self).rmenu_check_paste() -class PseudoFile(io.TextIOBase): +try: + _TextIOBase = io.TextIOBase +except AttributeError: + _TextIOBase = io.RawIOBase + +class PseudoFile(_TextIOBase): def __init__(self, shell, tags, encoding=None): self.shell = shell @@ -1338,9 +1351,9 @@ def write(self, s): if self.closed: raise ValueError("write to closed file") - if type(s) not in (unicode, str, bytearray): + if type(s) not in (_unicode, str, bytearray): # See issue #19481 - if isinstance(s, unicode): + if isinstance(s, _unicode): s = unicode.__getslice__(s, None, None) elif isinstance(s, str): s = str.__str__(s)