def next(self, w_iter): context = self.getexecutioncontext() try: it = self.unwrap(w_iter) except UnwrapException: pass else: if isinstance(it, _unroller): try: v, next_unroller = it.step() except IndexError: raise OperationError(self.w_StopIteration, self.w_None) else: context.replace_in_stack(it, next_unroller) return self.wrap(v) w_item = self.do_operation("next", w_iter) outcome, w_exc_cls, w_exc_value = context.guessexception( StopIteration, RuntimeError) if outcome is StopIteration: raise OperationError(self.w_StopIteration, w_exc_value) elif outcome is RuntimeError: raise flowcontext.ImplicitOperationError(self.w_RuntimeError, w_exc_value) else: return w_item
def handle_implicit_exceptions(self, exceptions): if not exceptions: return if not self.config.translation.builtins_can_raise_exceptions: # clean up 'exceptions' by removing the non-RPythonic exceptions # which might be listed for geninterp. exceptions = [ exc for exc in exceptions if exc is not TypeError and exc is not AttributeError ] if exceptions: # catch possible exceptions implicitly. If the OperationError # below is not caught in the same function, it will produce an # exception-raising return block in the flow graph. Note that # even if the interpreter re-raises the exception, it will not # be the same ImplicitOperationError instance internally. context = self.getexecutioncontext() outcome, w_exc_cls, w_exc_value = context.guessexception( *exceptions) if outcome is not None: # we assume that the caught exc_cls will be exactly the # one specified by 'outcome', and not a subclass of it, # unless 'outcome' is Exception. #if outcome is not Exception: #w_exc_cls = Constant(outcome) Now done by guessexception itself #pass raise flowcontext.ImplicitOperationError( w_exc_cls, w_exc_value)
def handle_implicit_exceptions(self, exceptions): if exceptions: # catch possible exceptions implicitly. If the OperationError # below is not caught in the same function, it will produce an # exception-raising return block in the flow graph. Note that # even if the interpreter re-raises the exception, it will not # be the same ImplicitOperationError instance internally. context = self.getexecutioncontext() outcome, w_exc_cls, w_exc_value = context.guessexception( *exceptions) if outcome is not None: # we assume that the caught exc_cls will be exactly the # one specified by 'outcome', and not a subclass of it, # unless 'outcome' is Exception. #if outcome is not Exception: #w_exc_cls = Constant(outcome) Now done by guessexception itself #pass raise flowcontext.ImplicitOperationError( w_exc_cls, w_exc_value)