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.
This commit is contained in:
Martin v. Löwis 2003-06-22 07:52:56 +00:00
parent faa697a5c9
commit bcc651a1f9
2 changed files with 15 additions and 4 deletions

View File

@ -741,9 +741,10 @@ class PyShell(OutputWindow):
self.save_stdout = sys.stdout self.save_stdout = sys.stdout
self.save_stderr = sys.stderr self.save_stderr = sys.stderr
self.save_stdin = sys.stdin self.save_stdin = sys.stdin
self.stdout = PseudoFile(self, "stdout") import IOBinding
self.stderr = PseudoFile(self, "stderr") self.stdout = PseudoFile(self, "stdout", IOBinding.encoding)
self.console = PseudoFile(self, "console") self.stderr = PseudoFile(self, "stderr", IOBinding.encoding)
self.console = PseudoFile(self, "console", IOBinding.encoding)
if not use_subprocess: if not use_subprocess:
sys.stdout = self.stdout sys.stdout = self.stdout
sys.stderr = self.stderr sys.stderr = self.stderr
@ -886,6 +887,12 @@ class PyShell(OutputWindow):
finally: finally:
self.reading = save self.reading = save
line = self.text.get("iomark", "end-1c") line = self.text.get("iomark", "end-1c")
if isinstance(line, unicode):
import IOBinding
try:
line = line.encode(IOBinding.encoding)
except UnicodeError:
pass
self.resetoutput() self.resetoutput()
if self.canceled: if self.canceled:
self.canceled = 0 self.canceled = 0
@ -1090,10 +1097,11 @@ class PyShell(OutputWindow):
class PseudoFile: class PseudoFile:
def __init__(self, shell, tags): def __init__(self, shell, tags, encoding=None):
self.shell = shell self.shell = shell
self.tags = tags self.tags = tags
self.softspace = 0 self.softspace = 0
self.encoding = encoding
def write(self, s): def write(self, s):
self.shell.write(s, self.tags) self.shell.write(s, self.tags)

View File

@ -210,6 +210,9 @@ class MyHandler(rpc.RPCHandler):
sys.stdin = self.console = self.get_remote_proxy("stdin") sys.stdin = self.console = self.get_remote_proxy("stdin")
sys.stdout = self.get_remote_proxy("stdout") sys.stdout = self.get_remote_proxy("stdout")
sys.stderr = self.get_remote_proxy("stderr") sys.stderr = self.get_remote_proxy("stderr")
import IOBinding
sys.stdin.encoding = sys.stdout.encoding = \
sys.stderr.encoding = IOBinding.encoding
self.interp = self.get_remote_proxy("interp") self.interp = self.get_remote_proxy("interp")
rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05) rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)