From: Martin v. Löwis Date: Wed, 25 Jul 2012 09:32:26 +0000 (+0200) Subject: Issue #7163: Propagate return value of sys.stdout.write. X-Git-Tag: v3.3.0b2~109^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=30d5e6c13fc988af2a6c0f8f0cdf43092c241e8f;p=thirdparty%2FPython%2Fcpython.git Issue #7163: Propagate return value of sys.stdout.write. Patch by Roger Serwy. --- diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index ed9e105949fa..3a641a019eb9 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -1,6 +1,8 @@ What's New in IDLE 3.2.4? ========================= +- Issue #7163: Propagate return value of sys.stdout.write. + - Issue #15318: Prevent writing to sys.stdin. - Issue #13532, #15319: Check that arguments to sys.stdout.write are strings. diff --git a/Lib/idlelib/OutputWindow.py b/Lib/idlelib/OutputWindow.py index 565cc9b772d8..cba901399766 100644 --- a/Lib/idlelib/OutputWindow.py +++ b/Lib/idlelib/OutputWindow.py @@ -40,6 +40,7 @@ class OutputWindow(EditorWindow): self.text.insert(mark, s, tags) self.text.see(mark) self.text.update() + return len(s) def writelines(self, lines): for line in lines: diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 83d40dff0bd2..0eae7c5cee38 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -760,7 +760,7 @@ class ModifiedInterpreter(InteractiveInterpreter): def write(self, s): "Override base class method" - self.tkconsole.stderr.write(s) + return self.tkconsole.stderr.write(s) def display_port_binding_error(self): tkMessageBox.showerror( @@ -1229,7 +1229,7 @@ class PyShell(OutputWindow): def write(self, s, tags=()): try: self.text.mark_gravity("iomark", "right") - OutputWindow.write(self, s, tags, "iomark") + count = OutputWindow.write(self, s, tags, "iomark") self.text.mark_gravity("iomark", "left") except: raise ###pass # ### 11Aug07 KBK if we are expecting exceptions @@ -1238,6 +1238,7 @@ class PyShell(OutputWindow): self.canceled = 0 if not use_subprocess: raise KeyboardInterrupt + return count class PseudoFile(object): @@ -1249,7 +1250,7 @@ class PseudoFile(object): def write(self, s): if not isinstance(s, str): raise TypeError('must be str, not ' + type(s).__name__) - self.shell.write(s, self.tags) + return self.shell.write(s, self.tags) def writelines(self, lines): for line in lines: