diff options
Diffstat (limited to 'Lib/idlelib/PyShell.py')
| -rw-r--r-- | Lib/idlelib/PyShell.py | 31 | 
1 files changed, 28 insertions, 3 deletions
| diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 951fde217d..0ee70d9f86 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -44,16 +44,34 @@ try:  except ImportError:      SIGTERM = 15 -# Change warnings module to write to sys.__stderr__ +# Override warnings module to write to warning_stream.  Initialize to send IDLE +# internal warnings to the console.  ScriptBinding.check_syntax() will +# temporarily redirect the stream to the shell window to display warnings when +# checking user's code. +global warning_stream +warning_stream = sys.__stderr__  try:      import warnings  except ImportError:      pass  else:      def idle_showwarning(message, category, filename, lineno): -        file = sys.__stderr__ -        file.write(warnings.formatwarning(message, category, filename, lineno)) +        file = warning_stream +        try: +            file.write(warnings.formatwarning(message, category, filename, lineno)) +        except IOError: +            pass  ## file (probably __stderr__) is invalid, warning dropped.      warnings.showwarning = idle_showwarning +    def idle_formatwarning(message, category, filename, lineno): +        """Format warnings the IDLE way""" +        s = "\nWarning (from warnings module):\n" +        s += '  File \"%s\", line %s\n' % (filename, lineno) +        line = linecache.getline(filename, lineno).strip() +        if line: +            s += "    %s\n" % line +        s += "%s: %s\n>>> " % (category.__name__, message) +        return s +    warnings.formatwarning = idle_formatwarning  def extended_linecache_checkcache(orig_checkcache=linecache.checkcache):      """Extend linecache.checkcache to preserve the <pyshell#...> entries @@ -815,6 +833,13 @@ class PyShell(OutputWindow):      endoffile = False      closing = False +    def set_warning_stream(self, stream): +	global warning_stream +	warning_stream = stream + +    def get_warning_stream(self): +        return warning_stream +      def toggle_debugger(self, event=None):          if self.executing:              tkMessageBox.showerror("Don't debug now", | 
