[Python-checkins] cpython (merge 3.2 -> default): Issue #4625: If IDLE cannot write to its recent file or breakpoint

ned.deily python-checkins at python.org
Thu Dec 15 00:18:30 CET 2011


http://hg.python.org/cpython/rev/ba832d42cd9e
changeset:   73969:ba832d42cd9e
parent:      73966:1eae8154c109
parent:      73968:26e3e542d20d
user:        Ned Deily <nad at acm.org>
date:        Wed Dec 14 15:03:31 2011 -0800
summary:
  Issue #4625: If IDLE cannot write to its recent file or breakpoint
files, display a message popup and continue rather than crash.
(original patch by Roger Serwy)

files:
  Lib/idlelib/EditorWindow.py |  15 ++++++++++-----
  Lib/idlelib/PyShell.py      |  24 ++++++++++++++++--------
  2 files changed, 26 insertions(+), 13 deletions(-)


diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -799,12 +799,17 @@
         rf_list = [path for path in rf_list if path not in bad_paths]
         ulchars = "1234567890ABCDEFGHIJK"
         rf_list = rf_list[0:len(ulchars)]
-        rf_file = open(self.recent_files_path, 'w',
-                        encoding='utf_8', errors='replace')
         try:
-            rf_file.writelines(rf_list)
-        finally:
-            rf_file.close()
+            with open(self.recent_files_path, 'w',
+                        encoding='utf_8', errors='replace') as rf_file:
+                rf_file.writelines(rf_list)
+        except IOError as err:
+            if not getattr(self.root, "recentfilelist_error_displayed", False):
+                self.root.recentfilelist_error_displayed = True
+                tkMessageBox.showerror(title='IDLE Error',
+                    message='Unable to update Recent Files list:\n%s'
+                        % str(err),
+                    parent=self.text)
         # for each edit window instance, construct the recent files menu
         for instance in self.top.instance_dict:
             menu = instance.recent_files_menu
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -206,14 +206,22 @@
                 lines = fp.readlines()
         except IOError:
             lines = []
-        with open(self.breakpointPath, "w") as new_file:
-            for line in lines:
-                if not line.startswith(filename + '='):
-                    new_file.write(line)
-            self.update_breakpoints()
-            breaks = self.breakpoints
-            if breaks:
-                new_file.write(filename + '=' + str(breaks) + '\n')
+        try:
+            with open(self.breakpointPath, "w") as new_file:
+                for line in lines:
+                    if not line.startswith(filename + '='):
+                        new_file.write(line)
+                self.update_breakpoints()
+                breaks = self.breakpoints
+                if breaks:
+                    new_file.write(filename + '=' + str(breaks) + '\n')
+        except IOError as err:
+            if not getattr(self.root, "breakpoint_error_displayed", False):
+                self.root.breakpoint_error_displayed = True
+                tkMessageBox.showerror(title='IDLE Error',
+                    message='Unable to update breakpoint list:\n%s'
+                        % str(err),
+                    parent=self.text)
 
     def restore_file_breaks(self):
         self.text.update()   # this enables setting "BREAK" tags to be visible

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list