def test_normalize_exc(self): from __pypy__ import normalize_exc e = normalize_exc(TypeError) assert isinstance(e, TypeError) e = normalize_exc(TypeError, 'foo') assert isinstance(e, TypeError) assert str(e) == 'foo' e = normalize_exc(TypeError('doh')) assert isinstance(e, TypeError) assert str(e) == 'doh' try: 1 / 0 except ZeroDivisionError as e: tb = e.__traceback__ e = normalize_exc(TypeError, None, tb) assert isinstance(e, TypeError) assert e.__traceback__ == tb
def _greenlet_throw(greenlet, exc, value, tb): _tls.current = greenlet try: raise __pypy__.normalize_exc(exc, value, tb) except GreenletExit as e: res = e finally: _continuation.permute(greenlet, greenlet.parent) return ((res, ), None)
def _greenlet_throw(greenlet, exc, value, tb): _tls.current = greenlet try: raise __pypy__.normalize_exc(exc, value, tb) except GreenletExit as e: res = e finally: _continuation.permute(greenlet, greenlet.parent) return ((res,), None)
def __switch(target, methodname, *baseargs): current = getcurrent() # while not (target.__main or _continulet.is_pending(target)): # inlined __nonzero__ ^^^ in case it's overridden if not target.__started: if methodname == 'switch': greenlet_func = _greenlet_start else: greenlet_func = _greenlet_throw _continulet.__init__(target, greenlet_func, *baseargs) methodname = 'switch' baseargs = () target.__started = True break # already done, go to the parent instead # (NB. infinite loop possible, but unlikely, unless you mess # up the 'parent' explicitly. Good enough, because a Ctrl-C # will show that the program is caught in this loop here.) target = target.parent # convert a "raise GreenletExit" into "return GreenletExit" if methodname == 'throw': try: raise __pypy__.normalize_exc(baseargs[0], baseargs[1]) except GreenletExit as e: methodname = 'switch' baseargs = (((e,), {}),) except: baseargs = sys.exc_info()[:2] + baseargs[2:] # try: unbound_method = getattr(_continulet, methodname) _tls.leaving = current args, kwds = unbound_method(current, *baseargs, to=target) _tls.current = current except: _tls.current = current if hasattr(_tls, 'trace'): _run_trace_callback('throw') _tls.leaving = None raise else: if hasattr(_tls, 'trace'): _run_trace_callback('switch') _tls.leaving = None # if kwds: if args: return args, kwds return kwds elif len(args) == 1: return args[0] else: return args
def _greenlet_throw(greenlet, exc, value, tb): try: _tls.current = greenlet try: if hasattr(_tls, 'trace'): _run_trace_callback('throw') raise __pypy__.normalize_exc(exc, value, tb) except GreenletExit as e: res = e finally: _continuation.permute(greenlet, greenlet.parent) return ((res,), None) finally: _tls.leaving = greenlet
def __switch(target, methodname, *baseargs): current = getcurrent() # while not (target.__main or _continulet.is_pending(target)): # inlined __nonzero__ ^^^ in case it's overridden if not target.__started: if methodname == 'switch': greenlet_func = _greenlet_start else: greenlet_func = _greenlet_throw _continulet.__init__(target, greenlet_func, *baseargs) methodname = 'switch' baseargs = () target.__started = True break # already done, go to the parent instead # (NB. infinite loop possible, but unlikely, unless you mess # up the 'parent' explicitly. Good enough, because a Ctrl-C # will show that the program is caught in this loop here.) target = target.parent # convert a "raise GreenletExit" into "return GreenletExit" if methodname == 'throw': try: raise __pypy__.normalize_exc(baseargs[0], baseargs[1]) except GreenletExit as e: methodname = 'switch' baseargs = (((e,), {}),) except: baseargs = sys.exc_info()[:2] + baseargs[2:] # try: unbound_method = getattr(_continulet, methodname) args, kwds = unbound_method(current, *baseargs, to=target) finally: _tls.current = current # if kwds: if args: return args, kwds return kwds elif len(args) == 1: return args[0] else: return args