本文整理汇总了Python中pypy.interpreter.error.OperationError.match方法的典型用法代码示例。如果您正苦于以下问题:Python OperationError.match方法的具体用法?Python OperationError.match怎么用?Python OperationError.match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.interpreter.error.OperationError
的用法示例。
在下文中一共展示了OperationError.match方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: w_throw
# 需要导入模块: from pypy.interpreter.error import OperationError [as 别名]
# 或者: from pypy.interpreter.error.OperationError import match [as 别名]
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.set_traceback(tb)
# Dead greenlet: turn GreenletExit into a regular return
if self.isdead() and operror.match(space, self.costate.w_GreenletExit):
args_w = [operror.get_w_value(space)]
else:
syncstate.push_exception(operror)
args_w = None
return self.w_switch(args_w)
示例2: test_new_exception
# 需要导入模块: from pypy.interpreter.error import OperationError [as 别名]
# 或者: from pypy.interpreter.error.OperationError import match [as 别名]
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)