Show More
@@ -163,19 +163,19 b' class Config(dict):' | |||||
163 | def __getattr__(self, key): |
|
163 | def __getattr__(self, key): | |
164 | try: |
|
164 | try: | |
165 | return self.__getitem__(key) |
|
165 | return self.__getitem__(key) | |
166 |
except KeyError |
|
166 | except KeyError as e: | |
167 | raise AttributeError(e) |
|
167 | raise AttributeError(e) | |
168 |
|
168 | |||
169 | def __setattr__(self, key, value): |
|
169 | def __setattr__(self, key, value): | |
170 | try: |
|
170 | try: | |
171 | self.__setitem__(key, value) |
|
171 | self.__setitem__(key, value) | |
172 |
except KeyError |
|
172 | except KeyError as e: | |
173 | raise AttributeError(e) |
|
173 | raise AttributeError(e) | |
174 |
|
174 | |||
175 | def __delattr__(self, key): |
|
175 | def __delattr__(self, key): | |
176 | try: |
|
176 | try: | |
177 | dict.__delitem__(self, key) |
|
177 | dict.__delitem__(self, key) | |
178 |
except KeyError |
|
178 | except KeyError as e: | |
179 | raise AttributeError(e) |
|
179 | raise AttributeError(e) | |
180 |
|
180 | |||
181 |
|
181 |
@@ -151,7 +151,7 b' class AliasManager(Configurable):' | |||||
151 | """Define an alias, but don't raise on an AliasError.""" |
|
151 | """Define an alias, but don't raise on an AliasError.""" | |
152 | try: |
|
152 | try: | |
153 | self.define_alias(name, cmd) |
|
153 | self.define_alias(name, cmd) | |
154 |
except AliasError |
|
154 | except AliasError as e: | |
155 | error("Invalid alias: %s" % e) |
|
155 | error("Invalid alias: %s" % e) | |
156 |
|
156 | |||
157 | def define_alias(self, name, cmd): |
|
157 | def define_alias(self, name, cmd): |
@@ -2454,7 +2454,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2454 | with prepended_to_syspath(dname): |
|
2454 | with prepended_to_syspath(dname): | |
2455 | try: |
|
2455 | try: | |
2456 | py3compat.execfile(fname,*where) |
|
2456 | py3compat.execfile(fname,*where) | |
2457 |
except SystemExit |
|
2457 | except SystemExit as status: | |
2458 | # If the call was made with 0 or None exit status (sys.exit(0) |
|
2458 | # If the call was made with 0 or None exit status (sys.exit(0) | |
2459 | # or sys.exit() ), don't bother showing a traceback, as both of |
|
2459 | # or sys.exit() ), don't bother showing a traceback, as both of | |
2460 | # these are considered normal by the OS: |
|
2460 | # these are considered normal by the OS: |
@@ -584,7 +584,7 b' class Magics(object):' | |||||
584 | # Do regular option processing |
|
584 | # Do regular option processing | |
585 | try: |
|
585 | try: | |
586 | opts,args = getopt(argv, opt_str, long_opts) |
|
586 | opts,args = getopt(argv, opt_str, long_opts) | |
587 |
except GetoptError |
|
587 | except GetoptError as e: | |
588 | raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str, |
|
588 | raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str, | |
589 | " ".join(long_opts))) |
|
589 | " ".join(long_opts))) | |
590 | for o,a in opts: |
|
590 | for o,a in opts: |
@@ -513,7 +513,7 b' class CodeMagics(Magics):' | |||||
513 | if is_temp: |
|
513 | if is_temp: | |
514 | try: |
|
514 | try: | |
515 | return open(filename).read() |
|
515 | return open(filename).read() | |
516 |
except IOError |
|
516 | except IOError as msg: | |
517 | if msg.filename == filename: |
|
517 | if msg.filename == filename: | |
518 | warn('File not found. Did you forget to save?') |
|
518 | warn('File not found. Did you forget to save?') | |
519 | return |
|
519 | return |
@@ -113,7 +113,7 b' class NamespaceMagics(Magics):' | |||||
113 | if out == 'not found': |
|
113 | if out == 'not found': | |
114 | try: |
|
114 | try: | |
115 | filename = get_py_filename(parameter_s) |
|
115 | filename = get_py_filename(parameter_s) | |
116 |
except IOError |
|
116 | except IOError as msg: | |
117 | print msg |
|
117 | print msg | |
118 | return |
|
118 | return | |
119 | page.page(self.shell.inspector.format(open(filename).read())) |
|
119 | page.page(self.shell.inspector.format(open(filename).read())) |
@@ -221,7 +221,7 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||||
221 | pager.write(strng) |
|
221 | pager.write(strng) | |
222 | pager.close() |
|
222 | pager.close() | |
223 | retval = pager.close() # success returns None |
|
223 | retval = pager.close() # success returns None | |
224 |
except IOError |
|
224 | except IOError as msg: # broken pipe when user quits | |
225 | if msg.args == (32,'Broken pipe'): |
|
225 | if msg.args == (32,'Broken pipe'): | |
226 | retval = None |
|
226 | retval = None | |
227 | else: |
|
227 | else: |
@@ -201,7 +201,7 b' class TestMagicRunSimple(tt.TempFileMixin):' | |||||
201 | "for i in range(5):\n" |
|
201 | "for i in range(5):\n" | |
202 | " try:\n" |
|
202 | " try:\n" | |
203 | " ip.magic('run %s')\n" |
|
203 | " ip.magic('run %s')\n" | |
204 |
" except NameError |
|
204 | " except NameError as e:\n" | |
205 | " print i;break\n" % empty.fname) |
|
205 | " print i;break\n" % empty.fname) | |
206 | self.mktmp(py3compat.doctest_refactor_print(src)) |
|
206 | self.mktmp(py3compat.doctest_refactor_print(src)) | |
207 | _ip.magic('run %s' % self.fname) |
|
207 | _ip.magic('run %s' % self.fname) |
@@ -875,7 +875,7 b' class VerboseTB(TBTools):' | |||||
875 | except (IndexError, UnicodeDecodeError): |
|
875 | except (IndexError, UnicodeDecodeError): | |
876 | # signals exit of tokenizer |
|
876 | # signals exit of tokenizer | |
877 | pass |
|
877 | pass | |
878 |
except tokenize.TokenError |
|
878 | except tokenize.TokenError as msg: | |
879 | _m = ("An unexpected error occurred while tokenizing input\n" |
|
879 | _m = ("An unexpected error occurred while tokenizing input\n" | |
880 | "The following traceback may be corrupted or invalid\n" |
|
880 | "The following traceback may be corrupted or invalid\n" | |
881 | "The error message is: %s\n" % msg) |
|
881 | "The error message is: %s\n" % msg) |
@@ -217,7 +217,7 b' class _BrowserLevel(object):' | |||||
217 | break |
|
217 | break | |
218 | except (KeyboardInterrupt, SystemExit): |
|
218 | except (KeyboardInterrupt, SystemExit): | |
219 | raise |
|
219 | raise | |
220 |
except Exception |
|
220 | except Exception as exc: | |
221 | have += 1 |
|
221 | have += 1 | |
222 | self.items.append(_BrowserCachedItem(exc)) |
|
222 | self.items.append(_BrowserCachedItem(exc)) | |
223 | self.exhausted = True |
|
223 | self.exhausted = True | |
@@ -260,7 +260,7 b' class _BrowserLevel(object):' | |||||
260 | value = attr.value(item) |
|
260 | value = attr.value(item) | |
261 | except (KeyboardInterrupt, SystemExit): |
|
261 | except (KeyboardInterrupt, SystemExit): | |
262 | raise |
|
262 | raise | |
263 |
except Exception |
|
263 | except Exception as exc: | |
264 | value = exc |
|
264 | value = exc | |
265 | # only store attribute if it exists (or we got an exception) |
|
265 | # only store attribute if it exists (or we got an exception) | |
266 | if value is not ipipe.noitem: |
|
266 | if value is not ipipe.noitem: | |
@@ -652,7 +652,7 b' class _CommandFind(_CommandInput):' | |||||
652 | break # found something |
|
652 | break # found something | |
653 | except (KeyboardInterrupt, SystemExit): |
|
653 | except (KeyboardInterrupt, SystemExit): | |
654 | raise |
|
654 | raise | |
655 |
except Exception |
|
655 | except Exception as exc: | |
656 | browser.report(exc) |
|
656 | browser.report(exc) | |
657 | curses.beep() |
|
657 | curses.beep() | |
658 | break # break on error |
|
658 | break # break on error | |
@@ -677,7 +677,7 b' class _CommandFindBackwards(_CommandInput):' | |||||
677 | break # found something |
|
677 | break # found something | |
678 | except (KeyboardInterrupt, SystemExit): |
|
678 | except (KeyboardInterrupt, SystemExit): | |
679 | raise |
|
679 | raise | |
680 |
except Exception |
|
680 | except Exception as exc: | |
681 | browser.report(exc) |
|
681 | browser.report(exc) | |
682 | curses.beep() |
|
682 | curses.beep() | |
683 | break # break on error |
|
683 | break # break on error | |
@@ -946,7 +946,7 b' class ibrowse(ipipe.Display):' | |||||
946 | ) |
|
946 | ) | |
947 | except (KeyboardInterrupt, SystemExit): |
|
947 | except (KeyboardInterrupt, SystemExit): | |
948 | raise |
|
948 | raise | |
949 |
except Exception |
|
949 | except Exception as exc: | |
950 | if not self.levels: |
|
950 | if not self.levels: | |
951 | raise |
|
951 | raise | |
952 | self._calcheaderlines(oldlevels) |
|
952 | self._calcheaderlines(oldlevels) | |
@@ -1311,7 +1311,7 b' class ibrowse(ipipe.Display):' | |||||
1311 | item = attr.value(item) |
|
1311 | item = attr.value(item) | |
1312 | except (KeyboardInterrupt, SystemExit): |
|
1312 | except (KeyboardInterrupt, SystemExit): | |
1313 | raise |
|
1313 | raise | |
1314 |
except Exception |
|
1314 | except Exception as exc: | |
1315 | self.report(exc) |
|
1315 | self.report(exc) | |
1316 | else: |
|
1316 | else: | |
1317 | self.report("entering detail view for attribute %s..." % attr.name()) |
|
1317 | self.report("entering detail view for attribute %s..." % attr.name()) | |
@@ -1638,7 +1638,7 b' class ibrowse(ipipe.Display):' | |||||
1638 | value = attr.value(item) |
|
1638 | value = attr.value(item) | |
1639 | except (SystemExit, KeyboardInterrupt): |
|
1639 | except (SystemExit, KeyboardInterrupt): | |
1640 | raise |
|
1640 | raise | |
1641 |
except Exception |
|
1641 | except Exception as exc: | |
1642 | value = exc |
|
1642 | value = exc | |
1643 | if value is not ipipe.noitem: |
|
1643 | if value is not ipipe.noitem: | |
1644 | attrstyle = ipipe.xrepr(value, "footer") |
|
1644 | attrstyle = ipipe.xrepr(value, "footer") |
@@ -154,7 +154,7 b' class IGridRenderer(wx.grid.PyGridCellRenderer):' | |||||
154 | try: |
|
154 | try: | |
155 | value = self.table._displayattrs[col].value(self.table.items[row]) |
|
155 | value = self.table._displayattrs[col].value(self.table.items[row]) | |
156 | (align, width, text) = ipipe.xformat(value, "cell", self.maxchars) |
|
156 | (align, width, text) = ipipe.xformat(value, "cell", self.maxchars) | |
157 |
except Exception |
|
157 | except Exception as exc: | |
158 | (align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) |
|
158 | (align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) | |
159 | return (align, text) |
|
159 | return (align, text) | |
160 |
|
160 | |||
@@ -292,7 +292,7 b' class IGridTable(wx.grid.PyGridTableBase):' | |||||
292 | break |
|
292 | break | |
293 | except (KeyboardInterrupt, SystemExit): |
|
293 | except (KeyboardInterrupt, SystemExit): | |
294 | raise |
|
294 | raise | |
295 |
except Exception |
|
295 | except Exception as exc: | |
296 | have += 1 |
|
296 | have += 1 | |
297 | self._append(exc) |
|
297 | self._append(exc) | |
298 | self.iterator = None |
|
298 | self.iterator = None | |
@@ -413,7 +413,7 b' class IGridGrid(wx.grid.Grid):' | |||||
413 | return None |
|
413 | return None | |
414 | try: |
|
414 | try: | |
415 | self.table.items = ipipe.deque(sorted(self.table.items, key=realkey, reverse=reverse)) |
|
415 | self.table.items = ipipe.deque(sorted(self.table.items, key=realkey, reverse=reverse)) | |
416 |
except TypeError |
|
416 | except TypeError as exc: | |
417 | self.error_output("Exception encountered: %s" % exc) |
|
417 | self.error_output("Exception encountered: %s" % exc) | |
418 | return |
|
418 | return | |
419 | # Find out where the object under the cursor went |
|
419 | # Find out where the object under the cursor went | |
@@ -478,7 +478,7 b' class IGridGrid(wx.grid.Grid):' | |||||
478 | (align, width, text) = ipipe.xformat(value, "cell", self.maxchars) |
|
478 | (align, width, text) = ipipe.xformat(value, "cell", self.maxchars) | |
479 | except IndexError: |
|
479 | except IndexError: | |
480 | raise IndexError |
|
480 | raise IndexError | |
481 |
except Exception |
|
481 | except Exception as exc: | |
482 | (align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) |
|
482 | (align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) | |
483 | return text |
|
483 | return text | |
484 |
|
484 | |||
@@ -505,7 +505,7 b' class IGridGrid(wx.grid.Grid):' | |||||
505 | break |
|
505 | break | |
506 | except (KeyboardInterrupt, SystemExit): |
|
506 | except (KeyboardInterrupt, SystemExit): | |
507 | raise |
|
507 | raise | |
508 |
except Exception |
|
508 | except Exception as exc: | |
509 | frame.SetStatusText(str(exc)) |
|
509 | frame.SetStatusText(str(exc)) | |
510 | wx.Bell() |
|
510 | wx.Bell() | |
511 | break # break on error |
|
511 | break # break on error | |
@@ -529,7 +529,7 b' class IGridGrid(wx.grid.Grid):' | |||||
529 | break |
|
529 | break | |
530 | except (KeyboardInterrupt, SystemExit): |
|
530 | except (KeyboardInterrupt, SystemExit): | |
531 | raise |
|
531 | raise | |
532 |
except Exception |
|
532 | except Exception as exc: | |
533 | frame.SetStatusText(str(exc)) |
|
533 | frame.SetStatusText(str(exc)) | |
534 | wx.Bell() |
|
534 | wx.Bell() | |
535 | break # break on error |
|
535 | break # break on error | |
@@ -739,7 +739,7 b' class IGridGrid(wx.grid.Grid):' | |||||
739 | for i in xrange(count-1, current, -1): # some tabs don't close if we don't close in *reverse* order |
|
739 | for i in xrange(count-1, current, -1): # some tabs don't close if we don't close in *reverse* order | |
740 | nb.DeletePage(i) |
|
740 | nb.DeletePage(i) | |
741 | frame._add_notebook(value) |
|
741 | frame._add_notebook(value) | |
742 |
except TypeError |
|
742 | except TypeError as exc: | |
743 | if exc.__class__.__module__ == "exceptions": |
|
743 | if exc.__class__.__module__ == "exceptions": | |
744 | msg = "%s: %s" % (exc.__class__.__name__, exc) |
|
744 | msg = "%s: %s" % (exc.__class__.__name__, exc) | |
745 | else: |
|
745 | else: | |
@@ -750,7 +750,7 b' class IGridGrid(wx.grid.Grid):' | |||||
750 | try: |
|
750 | try: | |
751 | attr = self.table._displayattrs[col] |
|
751 | attr = self.table._displayattrs[col] | |
752 | value = attr.value(self.table.items[row]) |
|
752 | value = attr.value(self.table.items[row]) | |
753 |
except Exception |
|
753 | except Exception as exc: | |
754 | self.error_output(str(exc)) |
|
754 | self.error_output(str(exc)) | |
755 | else: |
|
755 | else: | |
756 | self._doenter(value) |
|
756 | self._doenter(value) | |
@@ -762,7 +762,7 b' class IGridGrid(wx.grid.Grid):' | |||||
762 | def enter(self, row): |
|
762 | def enter(self, row): | |
763 | try: |
|
763 | try: | |
764 | value = self.table.items[row] |
|
764 | value = self.table.items[row] | |
765 |
except Exception |
|
765 | except Exception as exc: | |
766 | self.error_output(str(exc)) |
|
766 | self.error_output(str(exc)) | |
767 | else: |
|
767 | else: | |
768 | self._doenter(value) |
|
768 | self._doenter(value) | |
@@ -774,7 +774,7 b' class IGridGrid(wx.grid.Grid):' | |||||
774 | try: |
|
774 | try: | |
775 | attr = self.table._displayattrs[col] |
|
775 | attr = self.table._displayattrs[col] | |
776 | item = self.table.items[row] |
|
776 | item = self.table.items[row] | |
777 |
except Exception |
|
777 | except Exception as exc: | |
778 | self.error_output(str(exc)) |
|
778 | self.error_output(str(exc)) | |
779 | else: |
|
779 | else: | |
780 | attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")] |
|
780 | attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")] | |
@@ -784,7 +784,7 b' class IGridGrid(wx.grid.Grid):' | |||||
784 | try: |
|
784 | try: | |
785 | attr = self.table._displayattrs[col] |
|
785 | attr = self.table._displayattrs[col] | |
786 | item = attr.value(self.table.items[row]) |
|
786 | item = attr.value(self.table.items[row]) | |
787 |
except Exception |
|
787 | except Exception as exc: | |
788 | self.error_output(str(exc)) |
|
788 | self.error_output(str(exc)) | |
789 | else: |
|
789 | else: | |
790 | attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")] |
|
790 | attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")] | |
@@ -819,7 +819,7 b' class IGridGrid(wx.grid.Grid):' | |||||
819 | """ |
|
819 | """ | |
820 | try: |
|
820 | try: | |
821 | value = self.table.items[row] |
|
821 | value = self.table.items[row] | |
822 |
except Exception |
|
822 | except Exception as exc: | |
823 | self.error_output(str(exc)) |
|
823 | self.error_output(str(exc)) | |
824 | else: |
|
824 | else: | |
825 | self.quit(value) |
|
825 | self.quit(value) | |
@@ -827,7 +827,7 b' class IGridGrid(wx.grid.Grid):' | |||||
827 | def pickinput(self, row): |
|
827 | def pickinput(self, row): | |
828 | try: |
|
828 | try: | |
829 | value = self.table.items[row] |
|
829 | value = self.table.items[row] | |
830 |
except Exception |
|
830 | except Exception as exc: | |
831 | self.error_output(str(exc)) |
|
831 | self.error_output(str(exc)) | |
832 | else: |
|
832 | else: | |
833 | api = ipapi.get() |
|
833 | api = ipapi.get() | |
@@ -838,7 +838,7 b' class IGridGrid(wx.grid.Grid):' | |||||
838 | try: |
|
838 | try: | |
839 | attr = self.table._displayattrs[col] |
|
839 | attr = self.table._displayattrs[col] | |
840 | value = attr.value(self.table.items[row]) |
|
840 | value = attr.value(self.table.items[row]) | |
841 |
except Exception |
|
841 | except Exception as exc: | |
842 | self.error_output(str(exc)) |
|
842 | self.error_output(str(exc)) | |
843 | else: |
|
843 | else: | |
844 | api = ipapi.get() |
|
844 | api = ipapi.get() | |
@@ -851,7 +851,7 b' class IGridGrid(wx.grid.Grid):' | |||||
851 | """ |
|
851 | """ | |
852 | try: |
|
852 | try: | |
853 | value = [self.table.items[row] for row in rows] |
|
853 | value = [self.table.items[row] for row in rows] | |
854 |
except Exception |
|
854 | except Exception as exc: | |
855 | self.error_output(str(exc)) |
|
855 | self.error_output(str(exc)) | |
856 | else: |
|
856 | else: | |
857 | self.quit(value) |
|
857 | self.quit(value) | |
@@ -870,7 +870,7 b' class IGridGrid(wx.grid.Grid):' | |||||
870 | raise |
|
870 | raise | |
871 | except Exception: |
|
871 | except Exception: | |
872 | raise #pass |
|
872 | raise #pass | |
873 |
except Exception |
|
873 | except Exception as exc: | |
874 | self.error_output(str(exc)) |
|
874 | self.error_output(str(exc)) | |
875 | else: |
|
875 | else: | |
876 | self.quit(values) |
|
876 | self.quit(values) | |
@@ -879,7 +879,7 b' class IGridGrid(wx.grid.Grid):' | |||||
879 | try: |
|
879 | try: | |
880 | attr = self.table._displayattrs[col] |
|
880 | attr = self.table._displayattrs[col] | |
881 | value = attr.value(self.table.items[row]) |
|
881 | value = attr.value(self.table.items[row]) | |
882 |
except Exception |
|
882 | except Exception as exc: | |
883 | self.error_output(str(exc)) |
|
883 | self.error_output(str(exc)) | |
884 | else: |
|
884 | else: | |
885 | self.quit(value) |
|
885 | self.quit(value) | |
@@ -959,7 +959,7 b' class IGridFrame(wx.Frame):' | |||||
959 | if dlg.ShowModal() == wx.ID_OK: |
|
959 | if dlg.ShowModal() == wx.ID_OK: | |
960 | try: |
|
960 | try: | |
961 | milliseconds = int(dlg.GetValue()) |
|
961 | milliseconds = int(dlg.GetValue()) | |
962 |
except ValueError |
|
962 | except ValueError as exc: | |
963 | self.SetStatusText(str(exc)) |
|
963 | self.SetStatusText(str(exc)) | |
964 | else: |
|
964 | else: | |
965 | table.timer.Start(milliseconds=milliseconds, oneShot=False) |
|
965 | table.timer.Start(milliseconds=milliseconds, oneShot=False) |
@@ -1796,7 +1796,7 b' class ifilter(Pipe):' | |||||
1796 | ok += 1 |
|
1796 | ok += 1 | |
1797 | except (KeyboardInterrupt, SystemExit): |
|
1797 | except (KeyboardInterrupt, SystemExit): | |
1798 | raise |
|
1798 | raise | |
1799 |
except Exception |
|
1799 | except Exception as exc: | |
1800 | if self.errors == "drop": |
|
1800 | if self.errors == "drop": | |
1801 | pass # Ignore errors |
|
1801 | pass # Ignore errors | |
1802 | elif self.errors == "keep": |
|
1802 | elif self.errors == "keep": | |
@@ -1869,7 +1869,7 b' class ieval(Pipe):' | |||||
1869 | yield do(item) |
|
1869 | yield do(item) | |
1870 | except (KeyboardInterrupt, SystemExit): |
|
1870 | except (KeyboardInterrupt, SystemExit): | |
1871 | raise |
|
1871 | raise | |
1872 |
except Exception |
|
1872 | except Exception as exc: | |
1873 | if self.errors == "drop": |
|
1873 | if self.errors == "drop": | |
1874 | pass # Ignore errors |
|
1874 | pass # Ignore errors | |
1875 | elif self.errors == "keep": |
|
1875 | elif self.errors == "keep": | |
@@ -2040,7 +2040,7 b' class iless(Display):' | |||||
2040 | pager.write("\n") |
|
2040 | pager.write("\n") | |
2041 | finally: |
|
2041 | finally: | |
2042 | pager.close() |
|
2042 | pager.close() | |
2043 |
except Exception |
|
2043 | except Exception as exc: | |
2044 | print "%s: %s" % (exc.__class__.__name__, str(exc)) |
|
2044 | print "%s: %s" % (exc.__class__.__name__, str(exc)) | |
2045 |
|
2045 | |||
2046 |
|
2046 | |||
@@ -2187,7 +2187,7 b' class idump(Display):' | |||||
2187 | value = attr.value(item) |
|
2187 | value = attr.value(item) | |
2188 | except (KeyboardInterrupt, SystemExit): |
|
2188 | except (KeyboardInterrupt, SystemExit): | |
2189 | raise |
|
2189 | raise | |
2190 |
except Exception |
|
2190 | except Exception as exc: | |
2191 | value = exc |
|
2191 | value = exc | |
2192 | (align, width, text) = xformat(value, "cell", self.maxattrlength) |
|
2192 | (align, width, text) = xformat(value, "cell", self.maxattrlength) | |
2193 | colwidths[attr] = max(colwidths[attr], width) |
|
2193 | colwidths[attr] = max(colwidths[attr], width) |
@@ -246,7 +246,7 b' class FrontEndBase(object):' | |||||
246 |
|
246 | |||
247 | try: |
|
247 | try: | |
248 | result = self.shell.execute(block) |
|
248 | result = self.shell.execute(block) | |
249 |
except Exception |
|
249 | except Exception as e: | |
250 | e = self._add_block_id_for_failure(e, blockID=blockID) |
|
250 | e = self._add_block_id_for_failure(e, blockID=blockID) | |
251 | e = self.update_cell_prompt(e, blockID=blockID) |
|
251 | e = self.update_cell_prompt(e, blockID=blockID) | |
252 | e = self.render_error(e) |
|
252 | e = self.render_error(e) |
@@ -161,7 +161,7 b' class LineFrontEndBase(FrontEndBase):' | |||||
161 | is_complete = codeop.compile_command(clean_string, |
|
161 | is_complete = codeop.compile_command(clean_string, | |
162 | "<string>", "exec") |
|
162 | "<string>", "exec") | |
163 | self.release_output() |
|
163 | self.release_output() | |
164 |
except Exception |
|
164 | except Exception as e: | |
165 | # XXX: Hack: return True so that the |
|
165 | # XXX: Hack: return True so that the | |
166 | # code gets executed and the error captured. |
|
166 | # code gets executed and the error captured. | |
167 | is_complete = True |
|
167 | is_complete = True |
@@ -5,7 +5,7 b' ipython.' | |||||
5 |
|
5 | |||
6 | try: |
|
6 | try: | |
7 | import wx |
|
7 | import wx | |
8 |
except ImportError |
|
8 | except ImportError as e: | |
9 | e.args[0] = """%s |
|
9 | e.args[0] = """%s | |
10 | ________________________________________________________________________________ |
|
10 | ________________________________________________________________________________ | |
11 | You need wxPython to run this application. |
|
11 | You need wxPython to run this application. |
@@ -8,7 +8,7 b' try:' | |||||
8 | import numpy.testing as npt |
|
8 | import numpy.testing as npt | |
9 |
|
9 | |||
10 | from IPython.extensions import octavemagic |
|
10 | from IPython.extensions import octavemagic | |
11 |
except Exception |
|
11 | except Exception as e: | |
12 | __test__ = False |
|
12 | __test__ = False | |
13 |
|
13 | |||
14 | global octave |
|
14 | global octave |
@@ -79,7 +79,7 b' try:' | |||||
79 | import errno |
|
79 | import errno | |
80 | import traceback |
|
80 | import traceback | |
81 | import signal |
|
81 | import signal | |
82 |
except ImportError |
|
82 | except ImportError as e: | |
83 | raise ImportError (str(e) + """ |
|
83 | raise ImportError (str(e) + """ | |
84 |
|
84 | |||
85 | A critical module was not found. Probably this operating system does not |
|
85 | A critical module was not found. Probably this operating system does not | |
@@ -265,10 +265,10 b' def run (command, timeout=-1, withexitstatus=False, events=None, extra_args=None' | |||||
265 | else: |
|
265 | else: | |
266 | raise TypeError ('The callback must be a string or function type.') |
|
266 | raise TypeError ('The callback must be a string or function type.') | |
267 | event_count = event_count + 1 |
|
267 | event_count = event_count + 1 | |
268 |
except TIMEOUT |
|
268 | except TIMEOUT as e: | |
269 | child_result_list.append(child.before) |
|
269 | child_result_list.append(child.before) | |
270 | break |
|
270 | break | |
271 |
except EOF |
|
271 | except EOF as e: | |
272 | child_result_list.append(child.before) |
|
272 | child_result_list.append(child.before) | |
273 | break |
|
273 | break | |
274 | child_result = child._empty_buffer.join(child_result_list) |
|
274 | child_result = child._empty_buffer.join(child_result_list) | |
@@ -552,7 +552,7 b' class spawnb(object):' | |||||
552 | if self.use_native_pty_fork: |
|
552 | if self.use_native_pty_fork: | |
553 | try: |
|
553 | try: | |
554 | self.pid, self.child_fd = pty.fork() |
|
554 | self.pid, self.child_fd = pty.fork() | |
555 |
except OSError |
|
555 | except OSError as e: | |
556 | raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e)) |
|
556 | raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e)) | |
557 | else: # Use internal __fork_pty |
|
557 | else: # Use internal __fork_pty | |
558 | self.pid, self.child_fd = self.__fork_pty() |
|
558 | self.pid, self.child_fd = self.__fork_pty() | |
@@ -857,7 +857,7 b' class spawnb(object):' | |||||
857 | if self.child_fd in r: |
|
857 | if self.child_fd in r: | |
858 | try: |
|
858 | try: | |
859 | s = os.read(self.child_fd, size) |
|
859 | s = os.read(self.child_fd, size) | |
860 |
except OSError |
|
860 | except OSError as e: # Linux does this | |
861 | self.flag_eof = True |
|
861 | self.flag_eof = True | |
862 | raise EOF ('End Of File (EOF) in read_nonblocking(). Exception style platform.') |
|
862 | raise EOF ('End Of File (EOF) in read_nonblocking(). Exception style platform.') | |
863 | if s == b'': # BSD style |
|
863 | if s == b'': # BSD style | |
@@ -1106,7 +1106,7 b' class spawnb(object):' | |||||
1106 | else: |
|
1106 | else: | |
1107 | return False |
|
1107 | return False | |
1108 | return False |
|
1108 | return False | |
1109 |
except OSError |
|
1109 | except OSError as e: | |
1110 | # I think there are kernel timing issues that sometimes cause |
|
1110 | # I think there are kernel timing issues that sometimes cause | |
1111 | # this to happen. I think isalive() reports True, but the |
|
1111 | # this to happen. I think isalive() reports True, but the | |
1112 | # process is dead to the kernel. |
|
1112 | # process is dead to the kernel. | |
@@ -1177,7 +1177,7 b' class spawnb(object):' | |||||
1177 | if pid == 0: |
|
1177 | if pid == 0: | |
1178 | try: |
|
1178 | try: | |
1179 | pid, status = os.waitpid(self.pid, waitpid_options) ### os.WNOHANG) # Solaris! |
|
1179 | pid, status = os.waitpid(self.pid, waitpid_options) ### os.WNOHANG) # Solaris! | |
1180 |
except OSError |
|
1180 | except OSError as e: # This should never happen... | |
1181 | if e[0] == errno.ECHILD: |
|
1181 | if e[0] == errno.ECHILD: | |
1182 | raise ExceptionPexpect ('isalive() encountered condition that should never happen. There was no child process. Did someone else call waitpid() on our process?') |
|
1182 | raise ExceptionPexpect ('isalive() encountered condition that should never happen. There was no child process. Did someone else call waitpid() on our process?') | |
1183 | else: |
|
1183 | else: | |
@@ -1424,7 +1424,7 b' class spawnb(object):' | |||||
1424 | incoming = incoming + c |
|
1424 | incoming = incoming + c | |
1425 | if timeout is not None: |
|
1425 | if timeout is not None: | |
1426 | timeout = end_time - time.time() |
|
1426 | timeout = end_time - time.time() | |
1427 |
except EOF |
|
1427 | except EOF as e: | |
1428 | self.buffer = self._empty_buffer |
|
1428 | self.buffer = self._empty_buffer | |
1429 | self.before = incoming |
|
1429 | self.before = incoming | |
1430 | self.after = EOF |
|
1430 | self.after = EOF | |
@@ -1437,7 +1437,7 b' class spawnb(object):' | |||||
1437 | self.match = None |
|
1437 | self.match = None | |
1438 | self.match_index = None |
|
1438 | self.match_index = None | |
1439 | raise EOF (str(e) + '\n' + str(self)) |
|
1439 | raise EOF (str(e) + '\n' + str(self)) | |
1440 |
except TIMEOUT |
|
1440 | except TIMEOUT as e: | |
1441 | self.buffer = incoming |
|
1441 | self.buffer = incoming | |
1442 | self.before = incoming |
|
1442 | self.before = incoming | |
1443 | self.after = TIMEOUT |
|
1443 | self.after = TIMEOUT |
@@ -45,7 +45,7 b' class Handler (SocketServer.BaseRequestHandler):' | |||||
45 | chan = self.ssh_transport.open_channel('direct-tcpip', |
|
45 | chan = self.ssh_transport.open_channel('direct-tcpip', | |
46 | (self.chain_host, self.chain_port), |
|
46 | (self.chain_host, self.chain_port), | |
47 | self.request.getpeername()) |
|
47 | self.request.getpeername()) | |
48 |
except Exception |
|
48 | except Exception as e: | |
49 | logger.debug('Incoming request to %s:%d failed: %s' % (self.chain_host, |
|
49 | logger.debug('Incoming request to %s:%d failed: %s' % (self.chain_host, | |
50 | self.chain_port, |
|
50 | self.chain_port, | |
51 | repr(e))) |
|
51 | repr(e))) |
@@ -447,7 +447,7 b' class NotebookApp(BaseIPythonApplication):' | |||||
447 | for port in random_ports(self.port, self.port_retries+1): |
|
447 | for port in random_ports(self.port, self.port_retries+1): | |
448 | try: |
|
448 | try: | |
449 | self.http_server.listen(port, self.ip) |
|
449 | self.http_server.listen(port, self.ip) | |
450 |
except socket.error |
|
450 | except socket.error as e: | |
451 | if e.errno != errno.EADDRINUSE: |
|
451 | if e.errno != errno.EADDRINUSE: | |
452 | raise |
|
452 | raise | |
453 | self.log.info('The port %i is already in use, trying another random port.' % port) |
|
453 | self.log.info('The port %i is already in use, trying another random port.' % port) |
@@ -111,7 +111,7 b' class HtmlExporter(object):' | |||||
111 | # Perform the export! |
|
111 | # Perform the export! | |
112 | try: |
|
112 | try: | |
113 | return exporter(html, self.filename, self.image_tag) |
|
113 | return exporter(html, self.filename, self.image_tag) | |
114 |
except Exception |
|
114 | except Exception as e: | |
115 | msg = "Error exporting HTML to %s\n" % self.filename + str(e) |
|
115 | msg = "Error exporting HTML to %s\n" % self.filename + str(e) | |
116 | reply = QtGui.QMessageBox.warning(parent, 'Error', msg, |
|
116 | reply = QtGui.QMessageBox.warning(parent, 'Error', msg, | |
117 | QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok) |
|
117 | QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok) |
@@ -551,7 +551,7 b' def _dict_pprinter_factory(start, end, basetype=None):' | |||||
551 | keys = obj.keys() |
|
551 | keys = obj.keys() | |
552 | try: |
|
552 | try: | |
553 | keys.sort() |
|
553 | keys.sort() | |
554 |
except Exception |
|
554 | except Exception as e: | |
555 | # Sometimes the keys don't sort. |
|
555 | # Sometimes the keys don't sort. | |
556 | pass |
|
556 | pass | |
557 | for idx, key in enumerate(keys): |
|
557 | for idx, key in enumerate(keys): |
@@ -151,7 +151,7 b' class AsyncResult(object):' | |||||
151 | else: |
|
151 | else: | |
152 | results = error.collect_exceptions(results, self._fname) |
|
152 | results = error.collect_exceptions(results, self._fname) | |
153 | self._result = self._reconstruct_result(results) |
|
153 | self._result = self._reconstruct_result(results) | |
154 |
except Exception |
|
154 | except Exception as e: | |
155 | self._exception = e |
|
155 | self._exception = e | |
156 | self._success = False |
|
156 | self._success = False | |
157 | else: |
|
157 | else: | |
@@ -675,7 +675,7 b' class AsyncHubResult(AsyncResult):' | |||||
675 | else: |
|
675 | else: | |
676 | results = error.collect_exceptions(results, self._fname) |
|
676 | results = error.collect_exceptions(results, self._fname) | |
677 | self._result = self._reconstruct_result(results) |
|
677 | self._result = self._reconstruct_result(results) | |
678 |
except Exception |
|
678 | except Exception as e: | |
679 | self._exception = e |
|
679 | self._exception = e | |
680 | self._success = False |
|
680 | self._success = False | |
681 | else: |
|
681 | else: | |
@@ -683,4 +683,4 b' class AsyncHubResult(AsyncResult):' | |||||
683 | finally: |
|
683 | finally: | |
684 | self._metadata = map(self._client.metadata.get, self.msg_ids) |
|
684 | self._metadata = map(self._client.metadata.get, self.msg_ids) | |
685 |
|
685 | |||
686 | __all__ = ['AsyncResult', 'AsyncMapResult', 'AsyncHubResult'] No newline at end of file |
|
686 | __all__ = ['AsyncResult', 'AsyncMapResult', 'AsyncHubResult'] |
@@ -107,7 +107,7 b' def teardown():' | |||||
107 | if p.poll() is None: |
|
107 | if p.poll() is None: | |
108 | try: |
|
108 | try: | |
109 | p.stop() |
|
109 | p.stop() | |
110 |
except Exception |
|
110 | except Exception as e: | |
111 | print e |
|
111 | print e | |
112 | pass |
|
112 | pass | |
113 | if p.poll() is None: |
|
113 | if p.poll() is None: |
@@ -78,7 +78,7 b' def line_edit_f(self, cmd ):' | |||||
78 | for l in curdata: |
|
78 | for l in curdata: | |
79 | try: |
|
79 | try: | |
80 | l2 = eval(cmd) |
|
80 | l2 = eval(cmd) | |
81 |
except Exception |
|
81 | except Exception as e: | |
82 | print "Dropping exception",e,"on line:",l |
|
82 | print "Dropping exception",e,"on line:",l | |
83 | continue |
|
83 | continue | |
84 | newlines.append(l2) |
|
84 | newlines.append(l2) | |
@@ -95,4 +95,4 b' def line_edit_complete_f(self,event):' | |||||
95 |
|
95 | |||
96 | ip.set_hook('complete_command', line_edit_complete_f , str_key = '%led') |
|
96 | ip.set_hook('complete_command', line_edit_complete_f , str_key = '%led') | |
97 |
|
97 | |||
98 | ip.define_magic('led', line_edit_f) No newline at end of file |
|
98 | ip.define_magic('led', line_edit_f) |
@@ -308,7 +308,7 b' class DocTestCase(doctests.DocTestCase):' | |||||
308 | # and letting any other error propagate. |
|
308 | # and letting any other error propagate. | |
309 | try: |
|
309 | try: | |
310 | super(DocTestCase, self).tearDown() |
|
310 | super(DocTestCase, self).tearDown() | |
311 |
except AttributeError |
|
311 | except AttributeError as exc: | |
312 | if exc.args[0] != self._result_var: |
|
312 | if exc.args[0] != self._result_var: | |
313 | raise |
|
313 | raise | |
314 |
|
314 |
@@ -282,7 +282,7 b' If no filename is given, or if filename is -, read standard input."""' | |||||
282 | else: |
|
282 | else: | |
283 | try: |
|
283 | try: | |
284 | stream = open(fname) |
|
284 | stream = open(fname) | |
285 |
except IOError |
|
285 | except IOError as msg: | |
286 | print >> sys.stderr, msg |
|
286 | print >> sys.stderr, msg | |
287 | sys.exit(1) |
|
287 | sys.exit(1) | |
288 |
|
288 | |||
@@ -294,7 +294,7 b' If no filename is given, or if filename is -, read standard input."""' | |||||
294 | try: |
|
294 | try: | |
295 | # write colorized version to stdout |
|
295 | # write colorized version to stdout | |
296 | parser.format(stream.read(),scheme=opts.scheme_name) |
|
296 | parser.format(stream.read(),scheme=opts.scheme_name) | |
297 |
except IOError |
|
297 | except IOError as msg: | |
298 | # if user reads through a pager and quits, don't print traceback |
|
298 | # if user reads through a pager and quits, don't print traceback | |
299 | if msg.args != (32,'Broken pipe'): |
|
299 | if msg.args != (32,'Broken pipe'): | |
300 | raise |
|
300 | raise |
@@ -34,7 +34,7 b' def read_no_interrupt(p):' | |||||
34 |
|
34 | |||
35 | try: |
|
35 | try: | |
36 | return p.read() |
|
36 | return p.read() | |
37 |
except IOError |
|
37 | except IOError as err: | |
38 | if err.errno != errno.EINTR: |
|
38 | if err.errno != errno.EINTR: | |
39 | raise |
|
39 | raise | |
40 |
|
40 |
@@ -19,7 +19,7 b' def daemonize():' | |||||
19 | for i in range(3): |
|
19 | for i in range(3): | |
20 | try: |
|
20 | try: | |
21 | os.dup2(null, i) |
|
21 | os.dup2(null, i) | |
22 |
except OSError |
|
22 | except OSError as e: | |
23 | if e.errno != errno.EBADF: |
|
23 | if e.errno != errno.EBADF: | |
24 | raise |
|
24 | raise | |
25 | os.close(null) |
|
25 | os.close(null) |
@@ -121,7 +121,7 b' class Struct(dict):' | |||||
121 | ) |
|
121 | ) | |
122 | try: |
|
122 | try: | |
123 | self.__setitem__(key, value) |
|
123 | self.__setitem__(key, value) | |
124 |
except KeyError |
|
124 | except KeyError as e: | |
125 | raise AttributeError(e) |
|
125 | raise AttributeError(e) | |
126 |
|
126 | |||
127 | def __getattr__(self, key): |
|
127 | def __getattr__(self, key): |
@@ -85,7 +85,7 b' class PickleShareDB(collections.MutableMapping):' | |||||
85 | pickled = pickle.dump(value,fil.open('wb'), protocol=2) |
|
85 | pickled = pickle.dump(value,fil.open('wb'), protocol=2) | |
86 | try: |
|
86 | try: | |
87 | self.cache[fil] = (value,fil.mtime) |
|
87 | self.cache[fil] = (value,fil.mtime) | |
88 |
except OSError |
|
88 | except OSError as e: | |
89 | if e.errno != 2: |
|
89 | if e.errno != 2: | |
90 | raise |
|
90 | raise | |
91 |
|
91 |
@@ -897,7 +897,7 b' class KernelManager(HasTraits):' | |||||
897 | # Attempt to kill the kernel. |
|
897 | # Attempt to kill the kernel. | |
898 | try: |
|
898 | try: | |
899 | self.kernel.kill() |
|
899 | self.kernel.kill() | |
900 |
except OSError |
|
900 | except OSError as e: | |
901 | # In Windows, we will get an Access Denied error if the process |
|
901 | # In Windows, we will get an Access Denied error if the process | |
902 | # has already terminated. Ignore it. |
|
902 | # has already terminated. Ignore it. | |
903 | if sys.platform == 'win32': |
|
903 | if sys.platform == 'win32': |
@@ -29,7 +29,7 b' class ParentPollerUnix(Thread):' | |||||
29 | if os.getppid() == 1: |
|
29 | if os.getppid() == 1: | |
30 | os._exit(1) |
|
30 | os._exit(1) | |
31 | time.sleep(1.0) |
|
31 | time.sleep(1.0) | |
32 |
except OSError |
|
32 | except OSError as e: | |
33 | if e.errno == EINTR: |
|
33 | if e.errno == EINTR: | |
34 | continue |
|
34 | continue | |
35 | raise |
|
35 | raise |
General Comments 0
You need to be logged in to leave comments.
Login now