• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python error.OperationError类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.interpreter.error.OperationError的典型用法代码示例。如果您正苦于以下问题:Python OperationError类的具体用法?Python OperationError怎么用?Python OperationError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了OperationError类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: RAISE_VARARGS

    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:
            tb = space.interpclass_w(w_traceback)
            if tb is None or not space.is_true(space.isinstance(tb, 
                space.gettypeobject(pytraceback.PyTraceback.typedef))):
                raise OperationError(space.w_TypeError,
                      space.wrap("raise: arg 3 must be a traceback or None"))
            operror.application_traceback = tb
            # re-raise, no new traceback obj will be attached
            f.last_exception = operror
            raise Reraise
开发者ID:antoine1fr,项目名称:pygirl,代码行数:30,代码来源:pyopcode.py


示例2: PyErr_NormalizeException

def PyErr_NormalizeException(space, exc_p, val_p, tb_p):
    """Under certain circumstances, the values returned by PyErr_Fetch() below
    can be "unnormalized", meaning that *exc is a class object but *val is
    not an instance of the  same class.  This function can be used to instantiate
    the class in that case.  If the values are already normalized, nothing happens.
    The delayed normalization is implemented to improve performance."""
    operr = OperationError(from_ref(space, exc_p[0]),
                           from_ref(space, val_p[0]))
    operr.normalize_exception(space)
    Py_DecRef(space, exc_p[0])
    Py_DecRef(space, val_p[0])
    exc_p[0] = make_ref(space, operr.w_type)
    val_p[0] = make_ref(space, operr.get_w_value(space))
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:pyerrors.py


示例3: throw

 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)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:13,代码来源:generator.py


示例4: descr_throw

 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)
开发者ID:bukzor,项目名称:pypy,代码行数:15,代码来源:interp_continuation.py


示例5: w_throw

    def w_throw(self, w_type, w_value=None, w_traceback=None):
        space = self.space

        operror = OperationError(w_type, w_value)
        operror.normalize_exception(space)

        if not space.is_w(w_traceback, space.w_None):
            from pypy.interpreter import pytraceback
            tb = space.interpclass_w(w_traceback)
            if tb is None or not space.is_true(space.isinstance(tb,
                space.gettypeobject(pytraceback.PyTraceback.typedef))):
                raise OperationError(space.w_TypeError,
                      space.wrap("throw: arg 3 must be a traceback or None"))
            operror.set_traceback(tb)

        self._kill(operror)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:16,代码来源:interp_coroutine.py


示例6: unpackiterable

 def unpackiterable(self, w_iterable, expected_length=None):
     if not isinstance(w_iterable, Variable):
         l = list(self.unwrap(w_iterable))
         if expected_length is not None and len(l) != expected_length:
             raise ValueError
         return [self.wrap(x) for x in l]
     if isinstance(w_iterable, Variable) and expected_length is None:
         raise UnwrapException, ("cannot unpack a Variable iterable" "without knowing its length")
     elif expected_length is not None:
         w_len = self.len(w_iterable)
         w_correct = self.eq(w_len, self.wrap(expected_length))
         if not self.is_true(w_correct):
             e = OperationError(self.w_ValueError, self.w_None)
             e.normalize_exception(self)
             raise e
         return [self.do_operation("getitem", w_iterable, self.wrap(i)) for i in range(expected_length)]
     return ObjSpace.unpackiterable(self, w_iterable, expected_length)
开发者ID:are-prabhu,项目名称:pypy,代码行数:17,代码来源:objspace.py


示例7: throw

    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)
开发者ID:enyst,项目名称:plexnet,代码行数:18,代码来源:generator.py


示例8: test_new_exception

def test_new_exception(space):
    w_error = new_exception_class(space, '_socket.error')
    assert w_error.getname(space) == 'error'
    assert space.str_w(space.repr(w_error)) == "<class '_socket.error'>"
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_Exception)

    # subclass of ValueError
    w_error = new_exception_class(space, 'error', space.w_ValueError)
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_ValueError)

    # subclass of (ValueError, TypeError)
    w_bases = space.newtuple([space.w_ValueError, space.w_TypeError])
    w_error = new_exception_class(space, 'error', w_bases)
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_ValueError)
    assert operr.match(space, space.w_TypeError)
开发者ID:charred,项目名称:pypy,代码行数:21,代码来源:test_error.py


示例9: w_throw

 def w_throw(self, w_type=None, w_value=None, w_traceback=None):
     space = self.space
     if space.is_w(w_type, space.w_None):
         w_type = self.costate.w_GreenletExit
     # Code copied from RAISE_VARARGS but slightly modified.  Not too nice.
     operror = OperationError(w_type, w_value)
     operror.normalize_exception(space)
     if not space.is_w(w_traceback, space.w_None):
         from pypy.interpreter import pytraceback
         tb = space.interpclass_w(w_traceback)
         if tb is None or not space.is_true(space.isinstance(tb, 
             space.gettypeobject(pytraceback.PyTraceback.typedef))):
             raise OperationError(space.w_TypeError,
                   space.wrap("throw: arg 3 must be a traceback or None"))
         operror.application_traceback = tb
     # Dead greenlet: turn GreenletExit into a regular return
     if self.isdead() and operror.match(space, self.costate.w_GreenletExit):
         args_w = [operror.w_value]
     else:
         syncstate.push_exception(operror)
         args_w = None
     return self.w_switch(args_w)
开发者ID:enyst,项目名称:plexnet,代码行数:22,代码来源:interp_greenlet.py


示例10: unpackiterable

    def unpackiterable(self, w_iterable, expected_length=None):
        if not isinstance(w_iterable, Variable):
            l = list(self.unwrap(w_iterable))
            if expected_length is not None and len(l) != expected_length:
                raise ValueError
            return [self.wrap(x) for x in l]
        if isinstance(w_iterable, Variable) and expected_length is None:
            raise UnwrapException, ("cannot unpack a Variable iterable"
                                    "without knowing its length")
##            # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
##            print ("*** cannot unpack a Variable iterable "
##                   "without knowing its length,")
##            print "    assuming a list or tuple with up to 7 items"
##            items = []
##            w_len = self.len(w_iterable)
##            i = 0
##            while True:
##                w_i = self.wrap(i)
##                w_cond = self.eq(w_len, w_i)
##                if self.is_true(w_cond):
##                    break  # done
##                if i == 7:
##                    # too many values
##                    raise OperationError(self.w_AssertionError, self.w_None)
##                w_item = self.do_operation('getitem', w_iterable, w_i)
##                items.append(w_item)
##                i += 1
##            return items
##            # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
        elif expected_length is not None:
            w_len = self.len(w_iterable)
            w_correct = self.eq(w_len, self.wrap(expected_length))
            if not self.is_true(w_correct):
                e = OperationError(self.w_ValueError, self.w_None)
                e.normalize_exception(self)
                raise e
            return [self.do_operation('getitem', w_iterable, self.wrap(i)) 
                        for i in range(expected_length)]
        return ObjSpace.unpackiterable(self, w_iterable, expected_length)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:39,代码来源:objspace.py


示例11: throw

    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)
开发者ID:Qointum,项目名称:pypy,代码行数:18,代码来源:generator.py


示例12: __init__

 def __init__(self):
     OperationError.__init__(self, "exception_class", "exception_value")
开发者ID:mozillazg,项目名称:pypy,代码行数:2,代码来源:test_executioncontext.py


示例13: test_errorstr

def test_errorstr(space):
    operr = OperationError(space.w_ValueError, space.wrap("message"))
    assert operr.errorstr(space) == "ValueError: message"
    assert operr.errorstr(space, use_repr=True) == "ValueError: 'message'"
开发者ID:charred,项目名称:pypy,代码行数:4,代码来源:test_error.py


示例14: normalize_exc

def normalize_exc(space, w_type, w_value=None, w_tb=None):
    operr = OperationError(w_type, w_value, w_tb)
    operr.normalize_exception(space)
    return operr.get_w_value(space)
开发者ID:Qointum,项目名称:pypy,代码行数:4,代码来源:interp_magic.py



注:本文中的pypy.interpreter.error.OperationError类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gateway.app2interp_temp函数代码示例发布时间:2022-05-27
下一篇:
Python error.wrap_windowserror函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap