From b81e48507c7843551c9494dd9df1528bc09dbb08 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 14 Sep 2010 16:12:50 +0200 Subject: [PATCH] introduce py.builtin._sysex as alias for the special exceptions, fixes #115 --HG-- branch : trunk --- CHANGELOG | 1 + py/__init__.py | 1 + py/_builtin.py | 2 ++ py/_code/_assertionold.py | 2 +- py/_code/assertion.py | 2 +- py/_code/code.py | 2 +- py/_code/source.py | 2 +- py/_io/saferepr.py | 4 +--- py/_io/terminalwriter.py | 2 +- py/_test/collect.py | 2 +- 10 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 10ce4397f..bf20775f8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Changes between 1.3.3 and 1.3.4 - fix issue111: improve install documentation for windows - fix issue116: --doctestmodules works in the presence of __init__.py files as well - fix issue118: new --tb=native option for presenting cpython-standard exceptions +- fix issue115: introduce py.builtin._sysex for system level exceptions we should thread different Changes between 1.3.2 and 1.3.3 ================================================== diff --git a/py/__init__.py b/py/__init__.py index dceedad4b..c6e95d21d 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -111,6 +111,7 @@ py.apipkg.initpkg(__name__, dict( 'frozenset' : '._builtin:frozenset', 'BaseException' : '._builtin:BaseException', 'GeneratorExit' : '._builtin:GeneratorExit', + '_sysex' : '._builtin:_sysex', 'print_' : '._builtin:print_', '_reraise' : '._builtin:_reraise', '_tryimport' : '._builtin:_tryimport', diff --git a/py/_builtin.py b/py/_builtin.py index 8b7ca1421..a356db044 100644 --- a/py/_builtin.py +++ b/py/_builtin.py @@ -87,6 +87,8 @@ except NameError: pass GeneratorExit.__module__ = 'exceptions' +_sysex = (KeyboardInterrupt, SystemExit, MemoryError, GeneratorExit) + if sys.version_info >= (3, 0): exec ("print_ = print ; exec_=exec") import builtins diff --git a/py/_code/_assertionold.py b/py/_code/_assertionold.py index 6df1d55d3..4e81fb3ef 100644 --- a/py/_code/_assertionold.py +++ b/py/_code/_assertionold.py @@ -3,7 +3,7 @@ import sys, inspect from compiler import parse, ast, pycodegen from py._code.assertion import BuiltinAssertionError, _format_explanation -passthroughex = (KeyboardInterrupt, SystemExit, MemoryError) +passthroughex = py.builtin._sysex class Failure: def __init__(self, node): diff --git a/py/_code/assertion.py b/py/_code/assertion.py index 2a2da9cfb..efedec63d 100644 --- a/py/_code/assertion.py +++ b/py/_code/assertion.py @@ -44,7 +44,7 @@ class AssertionError(BuiltinAssertionError): if args: try: self.msg = str(args[0]) - except (KeyboardInterrupt, SystemExit): + except py.builtin._sysex: raise except: self.msg = "<[broken __repr__] %s at %0xd>" %( diff --git a/py/_code/code.py b/py/_code/code.py index 6558a8dcf..b40ef28c4 100644 --- a/py/_code/code.py +++ b/py/_code/code.py @@ -189,7 +189,7 @@ class TracebackEntry(object): """ try: return self.frame.eval("__tracebackhide__") - except (SystemExit, KeyboardInterrupt): + except py.builtin._sysex: raise except: return False diff --git a/py/_code/source.py b/py/_code/source.py index 52ab252a0..be2ca55d6 100644 --- a/py/_code/source.py +++ b/py/_code/source.py @@ -276,7 +276,7 @@ def getfslineno(obj): def findsource(obj): try: sourcelines, lineno = py.std.inspect.findsource(obj) - except (KeyboardInterrupt, SystemExit): + except py.builtin._sysex: raise except: return None, None diff --git a/py/_io/saferepr.py b/py/_io/saferepr.py index db52ca92b..afc968d3a 100644 --- a/py/_io/saferepr.py +++ b/py/_io/saferepr.py @@ -5,8 +5,6 @@ builtin_repr = repr reprlib = py.builtin._tryimport('repr', 'reprlib') -sysex = (KeyboardInterrupt, MemoryError, SystemExit) - class SafeRepr(reprlib.Repr): """ subclass of repr.Repr that limits the resulting size of repr() and includes information on exceptions raised during the call. @@ -21,7 +19,7 @@ class SafeRepr(reprlib.Repr): try: # Try the vanilla repr and make sure that the result is a string s = call(x, *args) - except sysex: + except py.builtin._sysex: raise except: cls, e, tb = sys.exc_info() diff --git a/py/_io/terminalwriter.py b/py/_io/terminalwriter.py index c140dbb64..982d5a661 100644 --- a/py/_io/terminalwriter.py +++ b/py/_io/terminalwriter.py @@ -26,7 +26,7 @@ def _getdimensions(): def get_terminal_width(): try: height, width = _getdimensions() - except (SystemExit, KeyboardInterrupt): + except py.builtin._sysex: raise except: # FALLBACK diff --git a/py/_test/collect.py b/py/_test/collect.py index 4e59eb59d..a18aaabdd 100644 --- a/py/_test/collect.py +++ b/py/_test/collect.py @@ -102,7 +102,7 @@ class Node(object): return getattr(self, attrname) try: res = function() - except (KeyboardInterrupt, SystemExit): + except py.builtin._sysex: raise except: failure = py.std.sys.exc_info()