diff Lib/idlelib/PyShell.py @ 29582:ee14e5b06ed1 legacy-trunk

Idlefork patch #682347: convert Unicode strings from readline to IOBinding.encoding. Also set sys.std{in,out,err}.encoding, for both the local and the subprocess case.
author Martin v. Löwis <martin@v.loewis.de>
date Sun, 22 Jun 2003 07:52:56 +0000
parents 51060b169b32
children 9035fe768689
line wrap: on
line diff
--- a/Lib/idlelib/PyShell.py	Sun Jun 22 01:42:20 2003 +0000
+++ b/Lib/idlelib/PyShell.py	Sun Jun 22 07:52:56 2003 +0000
@@ -741,9 +741,10 @@
         self.save_stdout = sys.stdout
         self.save_stderr = sys.stderr
         self.save_stdin = sys.stdin
-        self.stdout = PseudoFile(self, "stdout")
-        self.stderr = PseudoFile(self, "stderr")
-        self.console = PseudoFile(self, "console")
+        import IOBinding
+        self.stdout = PseudoFile(self, "stdout", IOBinding.encoding)
+        self.stderr = PseudoFile(self, "stderr", IOBinding.encoding)
+        self.console = PseudoFile(self, "console", IOBinding.encoding)
         if not use_subprocess:
             sys.stdout = self.stdout
             sys.stderr = self.stderr
@@ -886,6 +887,12 @@
         finally:
             self.reading = save
         line = self.text.get("iomark", "end-1c")
+        if isinstance(line, unicode):
+            import IOBinding
+            try:
+                line = line.encode(IOBinding.encoding)
+            except UnicodeError:
+                pass
         self.resetoutput()
         if self.canceled:
             self.canceled = 0
@@ -1090,10 +1097,11 @@
 
 class PseudoFile:
 
-    def __init__(self, shell, tags):
+    def __init__(self, shell, tags, encoding=None):
         self.shell = shell
         self.tags = tags
         self.softspace = 0
+        self.encoding = encoding
 
     def write(self, s):
         self.shell.write(s, self.tags)