Пример #1
0
    def throw(self, w_type, w_val, w_tb):
        from pypy.interpreter.pytraceback import check_traceback

        space = self.space
        if w_val is None:
            w_val = space.w_None

        msg = "throw() third argument must be a traceback object"
        if space.is_none(w_tb):
            tb = None
        else:
            tb = check_traceback(space, w_tb, msg)

        operr = OperationError(w_type, w_val, tb)
        operr.normalize_exception(space)

        # note: w_yielded_from is always None if 'self.running'
        if (self.w_yielded_from is not None
                and operr.match(space, space.w_GeneratorExit)):
            try:
                self._gen_close_iter(space)
            except OperationError as e:
                return self.send_error(e)

        if tb is None:
            tb = space.getattr(operr.get_w_value(space),
                               space.newtext('__traceback__'))
            if not space.is_w(tb, space.w_None):
                operr.set_traceback(tb)
        return self.send_error(operr)
Пример #2
0
def PyErr_SetExcInfo(space, w_type, w_value, w_traceback):
    """---Cython extension---

    Set the exception info, as known from ``sys.exc_info()``.  This refers
    to an exception that was already caught, not to an exception that was
    freshly raised.  This function steals the references of the arguments.
    To clear the exception state, pass *NULL* for all three arguments.
    For general rules about the three arguments, see :c:func:`PyErr_Restore`.
 
    .. note::
 
       This function is not normally used by code that wants to handle
       exceptions.  Rather, it can be used when code needs to save and
       restore the exception state temporarily.  Use
       :c:func:`PyErr_GetExcInfo` to read the exception state.
    """
    if w_value is None or space.is_w(w_value, space.w_None):
        operror = None
    else:
        tb = None
        if w_traceback is not None:
            try:
                tb = pytraceback.check_traceback(space, w_traceback, '?')
            except OperationError:    # catch and ignore bogus objects
                pass
        operror = OperationError(w_type, w_value, tb)
    #
    ec = space.getexecutioncontext()
    ec.set_sys_exc_info(operror)
    Py_DecRef(space, w_type)
    Py_DecRef(space, w_value)
    Py_DecRef(space, w_traceback)
Пример #3
0
    def RAISE_VARARGS(f, nbargs, *ignored):
        space = f.space
        if nbargs == 0:
            operror = space.getexecutioncontext().sys_exc_info()
            if operror is None:
                raise OperationError(space.w_TypeError,
                    space.wrap("raise: no active exception to re-raise"))
            # re-raise, no new traceback obj will be attached
            f.last_exception = operror
            raise Reraise

        w_value = w_traceback = space.w_None
        if nbargs >= 3: w_traceback = f.popvalue()
        if nbargs >= 2: w_value     = f.popvalue()
        if 1:           w_type      = f.popvalue()
        operror = OperationError(w_type, w_value)
        operror.normalize_exception(space)
        if not space.full_exceptions or space.is_w(w_traceback, space.w_None):
            # common case
            raise operror
        else:
            from pypy.interpreter.pytraceback import check_traceback
            msg = "raise: arg 3 must be a traceback or None"
            tb = check_traceback(space, w_traceback, msg)
            operror.application_traceback = tb
            # special 3-arguments raise, no new traceback obj will be attached
            raise RaiseWithExplicitTraceback(operror)
Пример #4
0
def PyErr_SetExcInfo(space, py_type, py_value, py_traceback):
    """---Cython extension---

    Set the exception info, as known from ``sys.exc_info()``.  This refers
    to an exception that was already caught, not to an exception that was
    freshly raised.  This function steals the references of the arguments.
    To clear the exception state, pass *NULL* for all three arguments.
    For general rules about the three arguments, see :c:func:`PyErr_Restore`.

    .. note::

       This function is not normally used by code that wants to handle
       exceptions.  Rather, it can be used when code needs to save and
       restore the exception state temporarily.  Use
       :c:func:`PyErr_GetExcInfo` to read the exception state.
    """
    w_type = get_w_obj_and_decref(space, py_type)
    w_value = get_w_obj_and_decref(space, py_value)
    w_traceback = get_w_obj_and_decref(space, py_traceback)
    if w_value is None or space.is_w(w_value, space.w_None):
        operror = None
    else:
        tb = None
        if w_traceback is not None:
            try:
                tb = pytraceback.check_traceback(space, w_traceback, '?')
            except OperationError:    # catch and ignore bogus objects
                pass
        operror = OperationError(w_type, w_value, tb)
    #
    ec = space.getexecutioncontext()
    ec.set_sys_exc_info(operror)
Пример #5
0
 def throw(self, w_type, w_val, w_tb):
     from pypy.interpreter.pytraceback import check_traceback
     space = self.space
     
     msg = "throw() third argument must be a traceback object"
     if space.is_w(w_tb, space.w_None):
         tb = None
     else:
         tb = check_traceback(space, w_tb, msg)
    
     operr = OperationError(w_type, w_val, tb)
     operr.normalize_exception(space)
     return self.send_ex(space.w_None, operr)
Пример #6
0
    def throw(self, w_type, w_val, w_tb):
        from pypy.interpreter.pytraceback import check_traceback
        space = self.space

        msg = "throw() third argument must be a traceback object"
        if space.is_none(w_tb):
            tb = None
        else:
            tb = check_traceback(space, w_tb, msg)

        operr = OperationError(w_type, w_val, tb)
        operr.normalize_exception(space)
        return self.send_ex(space.w_None, operr)
Пример #7
0
 def descr_throw(self, w_type, w_val=None, w_tb=None, w_to=None):
     from pypy.interpreter.pytraceback import check_traceback
     space = self.space
     #
     msg = "throw() third argument must be a traceback object"
     if space.is_none(w_tb):
         tb = None
     else:
         tb = check_traceback(space, w_tb, msg)
     #
     operr = OperationError(w_type, w_val, tb)
     operr.normalize_exception(space)
     global_state.w_value = None
     global_state.propagate_exception = operr
     return self.switch(w_to)
Пример #8
0
 def descr_throw(self, w_type, w_val=None, w_tb=None, w_to=None):
     from pypy.interpreter.pytraceback import check_traceback
     space = self.space
     #
     msg = "throw() third argument must be a traceback object"
     if space.is_none(w_tb):
         tb = None
     else:
         tb = check_traceback(space, w_tb, msg)
     #
     operr = OperationError(w_type, w_val, tb)
     operr.normalize_exception(space)
     global_state.w_value = None
     global_state.propagate_exception = operr
     return self.switch(w_to)
Пример #9
0
    def set_sys_exc_info3(self, w_type, w_value, w_traceback):
        from pypy.interpreter import pytraceback

        space = self.space
        if space.is_none(w_value):
            operror = None
        else:
            tb = None
            if not space.is_none(w_traceback):
                try:
                    tb = pytraceback.check_traceback(space, w_traceback, '?')
                except OperationError:  # catch and ignore bogus objects
                    pass
            operror = OperationError(w_type, w_value, tb)
        self.set_sys_exc_info(operror)
Пример #10
0
    def throw(self, w_type, w_val, w_tb):
        from pypy.interpreter.pytraceback import check_traceback
        space = self.space

        msg = "throw() third argument must be a traceback object"
        if space.is_w(w_tb, space.w_None):
            tb = None
        else:
            tb = check_traceback(space, w_tb, msg)

        operr = OperationError(w_type, w_val, tb)
        operr.normalize_exception(space)

        ec = space.getexecutioncontext()
        next_instr = self.frame.handle_operation_error(ec, operr)
        self.frame.last_instr = intmask(next_instr - 1)

        return self.send_ex(space.w_None, True)
Пример #11
0
    def throw(self, w_type, w_val, w_tb):
        from pypy.interpreter.pytraceback import check_traceback
        space = self.space

        msg = "throw() third argument must be a traceback object"
        if space.is_none(w_tb):
            tb = None
        else:
            tb = check_traceback(space, w_tb, msg)

        operr = OperationError(w_type, w_val, tb)
        operr.normalize_exception(space)
        if tb is None:
            tb = space.getattr(operr.get_w_value(space),
                               space.wrap('__traceback__'))
            if not space.is_w(tb, space.w_None):
                operr.set_traceback(tb)
        return self.send_ex(space.w_None, operr)
Пример #12
0
    def throw(self, w_type, w_val, w_tb):
        from pypy.interpreter.pytraceback import check_traceback
        space = self.space
        
        msg = "throw() third argument must be a traceback object"
        if space.is_w(w_tb, space.w_None):
            tb = None
        else:
            tb = check_traceback(space, w_tb, msg)
       
        operr = OperationError(w_type, w_val, tb)
        operr.normalize_exception(space)
        
        ec = space.getexecutioncontext()
        next_instr = self.frame.handle_operation_error(ec, operr)
        self.frame.last_instr = intmask(next_instr - 1)

        return self.send_ex(space.w_None, True)
Пример #13
0
 def descr_settraceback(self, space, w_newtraceback):
     msg = '__traceback__ must be a traceback or None'
     if not space.is_w(w_newtraceback, space.w_None):
         w_newtraceback = check_traceback(space, w_newtraceback, msg)
     self.w_traceback = w_newtraceback
Пример #14
0
 def descr_settraceback(self, space, w_newtraceback):
     msg = '__traceback__ must be a traceback or None'
     if not space.is_w(w_newtraceback, space.w_None):
         w_newtraceback = check_traceback(space, w_newtraceback, msg)
     self.w_traceback = w_newtraceback