本文整理汇总了Python中pypy.interpreter.gateway.interp2app_temp函数的典型用法代码示例。如果您正苦于以下问题:Python interp2app_temp函数的具体用法?Python interp2app_temp怎么用?Python interp2app_temp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了interp2app_temp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_interp2app_unwrap_spec_typechecks
def test_interp2app_unwrap_spec_typechecks(self):
space = self.space
w = space.wrap
def g3_id(space, x):
return space.wrap(x)
app_g3_i = gateway.interp2app_temp(g3_id,
unwrap_spec=[gateway.ObjSpace,
int])
w_app_g3_i = space.wrap(app_g3_i)
assert space.eq_w(space.call_function(w_app_g3_i,w(1)),w(1))
assert space.eq_w(space.call_function(w_app_g3_i,w(1L)),w(1))
raises(gateway.OperationError,space.call_function,w_app_g3_i,w(sys.maxint*2))
raises(gateway.OperationError,space.call_function,w_app_g3_i,w(None))
raises(gateway.OperationError,space.call_function,w_app_g3_i,w("foo"))
raises(gateway.OperationError,space.call_function,w_app_g3_i,w(1.0))
app_g3_s = gateway.interp2app_temp(g3_id,
unwrap_spec=[gateway.ObjSpace,
str])
w_app_g3_s = space.wrap(app_g3_s)
assert space.eq_w(space.call_function(w_app_g3_s,w("foo")),w("foo"))
raises(gateway.OperationError,space.call_function,w_app_g3_s,w(None))
raises(gateway.OperationError,space.call_function,w_app_g3_s,w(1))
raises(gateway.OperationError,space.call_function,w_app_g3_s,w(1.0))
app_g3_f = gateway.interp2app_temp(g3_id,
unwrap_spec=[gateway.ObjSpace,
float])
w_app_g3_f = space.wrap(app_g3_f)
assert space.eq_w(space.call_function(w_app_g3_f,w(1.0)),w(1.0))
assert space.eq_w(space.call_function(w_app_g3_f,w(1)),w(1.0))
assert space.eq_w(space.call_function(w_app_g3_f,w(1L)),w(1.0))
raises(gateway.OperationError,space.call_function,w_app_g3_f,w(None))
raises(gateway.OperationError,space.call_function,w_app_g3_f,w("foo"))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:34,代码来源:test_gateway.py
示例2: test_interp2app_doc
def test_interp2app_doc(self):
space = self.space
def f(space, w_x):
"""foo"""
w_f = space.wrap(gateway.interp2app_temp(f))
assert space.unwrap(space.getattr(w_f, space.wrap('__doc__'))) == 'foo'
#
def g(space, w_x):
never_called
w_g = space.wrap(gateway.interp2app_temp(g, doc='bar'))
assert space.unwrap(space.getattr(w_g, space.wrap('__doc__'))) == 'bar'
开发者ID:Darriall,项目名称:pypy,代码行数:11,代码来源:test_gateway.py
示例3: test_unwrap_spec_default_applevel_bug2
def test_unwrap_spec_default_applevel_bug2(self):
space = self.space
def g(space, w_x, w_y=None, __args__=None):
return w_x
w_g = space.wrap(gateway.interp2app_temp(g))
w_42 = space.call_function(w_g, space.wrap(42))
assert space.int_w(w_42) == 42
py.test.raises(gateway.OperationError, space.call_function, w_g)
#
def g(space, w_x, w_y=None, args_w=None):
return w_x
w_g = space.wrap(gateway.interp2app_temp(g))
w_42 = space.call_function(w_g, space.wrap(42))
assert space.int_w(w_42) == 42
py.test.raises(gateway.OperationError, space.call_function, w_g)
开发者ID:Darriall,项目名称:pypy,代码行数:15,代码来源:test_gateway.py
示例4: setup_class
def setup_class(cls):
space = gettestobjspace(usemodules=("thread", "time"))
cls.space = space
if option.runappdirect:
def plain_waitfor(condition, delay=1):
adaptivedelay = 0.04
limit = time.time() + NORMAL_TIMEOUT * delay
while time.time() <= limit:
time.sleep(adaptivedelay)
gc.collect()
if condition():
return
adaptivedelay *= 1.05
print "*** timed out ***"
cls.w_waitfor = plain_waitfor
else:
cls.w_waitfor = space.wrap(interp2app_temp(waitfor))
cls.w_busywait = space.appexec(
[],
"""():
import time
return time.sleep
""",
)
开发者ID:alkorzt,项目名称:pypy,代码行数:27,代码来源:support.py
示例5: test_interp2app_fastcall_method_with_space
def test_interp2app_fastcall_method_with_space(self):
class W_X(W_Root):
def descr_f(self, space, w_x):
return w_x
app_f = gateway.interp2app_temp(W_X.descr_f, unwrap_spec=['self',
gateway.ObjSpace, gateway.W_Root])
w_app_f = self.space.wrap(app_f)
assert isinstance(w_app_f.code, gateway.BuiltinCode2)
called = []
fastcall_2 = w_app_f.code.fastcall_2
def witness_fastcall_2(space, w_func, w_a, w_b):
called.append(w_func)
return fastcall_2(space, w_func, w_a, w_b)
w_app_f.code.fastcall_2 = witness_fastcall_2
space = self.space
w_res = space.call_function(w_app_f, W_X(), space.wrap(3))
assert space.is_true(w_res)
assert called == [w_app_f]
开发者ID:Darriall,项目名称:pypy,代码行数:25,代码来源:test_gateway.py
示例6: test_interp2app_fastcall
def test_interp2app_fastcall(self):
space = self.space
w = space.wrap
w_3 = w(3)
def f(space):
return w_3
app_f = gateway.interp2app_temp(f, unwrap_spec=[gateway.ObjSpace])
w_app_f = w(app_f)
# sanity
assert isinstance(w_app_f.code, gateway.BuiltinCode0)
called = []
fastcall_0 = w_app_f.code.fastcall_0
def witness_fastcall_0(space, w_func):
called.append(w_func)
return fastcall_0(space, w_func)
w_app_f.code.fastcall_0 = witness_fastcall_0
w_3 = space.newint(3)
w_res = space.call_function(w_app_f)
assert w_res is w_3
assert called == [w_app_f]
called = []
w_res = space.appexec([w_app_f], """(f):
return f()
""")
assert w_res is w_3
assert called == [w_app_f]
开发者ID:enyst,项目名称:plexnet,代码行数:35,代码来源:test_gateway.py
示例7: test_interp2app_fastcall_method
def test_interp2app_fastcall_method(self):
space = self.space
w = space.wrap
w_3 = w(3)
def f(space, w_self, w_x):
return w_x
app_f = gateway.interp2app_temp(f, unwrap_spec=[gateway.ObjSpace,
gateway.W_Root,
gateway.W_Root])
w_app_f = w(app_f)
# sanity
assert isinstance(w_app_f.code, gateway.BuiltinCode2)
called = []
fastcall_2 = w_app_f.code.fastcall_2
def witness_fastcall_2(space, w_func, w_a, w_b):
called.append(w_func)
return fastcall_2(space, w_func, w_a, w_b)
w_app_f.code.fastcall_2 = witness_fastcall_2
w_res = space.appexec([w_app_f, w_3], """(f, x):
class A(object):
m = f # not a builtin function, so works as method
y = A().m(x)
b = A().m
z = b(x)
return y is x and z is x
""")
assert space.is_true(w_res)
assert called == [w_app_f, w_app_f]
开发者ID:enyst,项目名称:plexnet,代码行数:34,代码来源:test_gateway.py
示例8: test_plain
def test_plain(self):
space = self.space
def g(space, w_a, w_x):
return space.newtuple([space.wrap('g'), w_a, w_x])
w_g = space.wrap(gateway.interp2app_temp(g,
unwrap_spec=[gateway.ObjSpace,
gateway.W_Root,
gateway.W_Root]))
args = argument.Arguments(space, [space.wrap(-1), space.wrap(0)])
w_res = space.call_args(w_g, args)
assert space.is_true(space.eq(w_res, space.wrap(('g', -1, 0))))
w_self = space.wrap('self')
args0 = argument.Arguments(space, [space.wrap(0)])
args = args0.prepend(w_self)
w_res = space.call_args(w_g, args)
assert space.is_true(space.eq(w_res, space.wrap(('g', 'self', 0))))
args3 = argument.Arguments(space, [space.wrap(3)])
w_res = space.call_obj_args(w_g, w_self, args3)
assert space.is_true(space.eq(w_res, space.wrap(('g', 'self', 3))))
开发者ID:enyst,项目名称:plexnet,代码行数:27,代码来源:test_gateway.py
示例9: test_unwrap_spec_default_applevel_bogus
def test_unwrap_spec_default_applevel_bogus(self):
space = self.space
@gateway.unwrap_spec(w_x=WrappedDefault(42), y=int)
def g(space, w_x, y):
never_called
py.test.raises(AssertionError, space.wrap, gateway.interp2app_temp(g))
开发者ID:Qointum,项目名称:pypy,代码行数:8,代码来源:test_gateway.py
示例10: test_func_defaults
def test_func_defaults(self):
from pypy.interpreter import gateway
def g(w_a=None):
pass
app_g = gateway.interp2app_temp(g)
space = self.space
w_g = space.wrap(app_g)
w_defs = space.getattr(w_g, space.wrap("func_defaults"))
assert space.is_w(w_defs, space.w_None)
开发者ID:Darriall,项目名称:pypy,代码行数:9,代码来源:test_function.py
示例11: test_unwrap_spec_decorator
def test_unwrap_spec_decorator(self):
space = self.space
@gateway.unwrap_spec(gateway.ObjSpace, gateway.W_Root, int)
def g(space, w_thing, i):
return space.newtuple([w_thing, space.wrap(i)])
w_g = space.wrap(gateway.interp2app_temp(g))
args = argument.Arguments(space, [space.wrap(-1), space.wrap(0)])
w_res = space.call_args(w_g, args)
assert space.eq_w(w_res, space.wrap((-1, 0)))
开发者ID:Darriall,项目名称:pypy,代码行数:9,代码来源:test_gateway.py
示例12: test_interp2app_unwrap_spec_fsencode
def test_interp2app_unwrap_spec_fsencode(self):
space = self.space
w = space.wrap
def f(filename):
return space.wrapbytes(filename)
app_f = gateway.interp2app_temp(f, unwrap_spec=["fsencode"])
w_app_f = space.wrap(app_f)
assert space.eq_w(space.call_function(w_app_f, w(u"\udc80")), space.wrapbytes("\x80"))
开发者ID:Qointum,项目名称:pypy,代码行数:10,代码来源:test_gateway.py
示例13: test_unwrap_spec_default_bytes
def test_unwrap_spec_default_bytes(self):
space = self.space
@gateway.unwrap_spec(s="bufferstr")
def g(space, s=""):
return space.wrap(type(s) is str)
w_g = space.wrap(gateway.interp2app_temp(g))
args = argument.Arguments(space, [])
w_res = space.call_args(w_g, args)
assert space.eq_w(w_res, space.w_True)
开发者ID:Qointum,项目名称:pypy,代码行数:11,代码来源:test_gateway.py
示例14: test_interp2app_unwrap_spec_int_float
def test_interp2app_unwrap_spec_int_float(self):
space = self.space
w = space.wrap
def g3_if(space, i0, f1):
return space.wrap(i0 + f1)
app_g3_if = gateway.interp2app_temp(g3_if, unwrap_spec=[gateway.ObjSpace, int, float])
w_app_g3_if = space.wrap(app_g3_if)
assert self.space.eq_w(space.call(w_app_g3_if, space.newtuple([w(1), w(1.0)]), space.newdict()), w(2.0))
assert self.space.eq_w(space.call_function(w_app_g3_if, w(1), w(1.0)), w(2.0))
开发者ID:Qointum,项目名称:pypy,代码行数:11,代码来源:test_gateway.py
示例15: test_interp2app_unwrap_spec
def test_interp2app_unwrap_spec(self):
space = self.space
w = space.wrap
def g3(space, w_a, w_b):
return space.add(w_a, w_b)
app_g3 = gateway.interp2app_temp(g3, unwrap_spec=[gateway.ObjSpace, gateway.W_Root, gateway.W_Root])
w_app_g3 = space.wrap(app_g3)
assert self.space.eq_w(space.call(w_app_g3, space.newtuple([w("foo"), w("bar")]), space.newdict()), w("foobar"))
assert self.space.eq_w(space.call_function(w_app_g3, w("foo"), w("bar")), w("foobar"))
开发者ID:Qointum,项目名称:pypy,代码行数:11,代码来源:test_gateway.py
示例16: test_unwrap_spec_default_applevel_bytes
def test_unwrap_spec_default_applevel_bytes(self):
space = self.space
@gateway.unwrap_spec(w_x=WrappedDefault("foo"))
def g(space, w_x):
return w_x
w_g = space.wrap(gateway.interp2app_temp(g))
args = argument.Arguments(space, [])
w_res = space.call_args(w_g, args)
assert space.eq_w(w_res, space.wrapbytes("foo"))
开发者ID:Qointum,项目名称:pypy,代码行数:11,代码来源:test_gateway.py
示例17: test_interp2app_classmethod
def test_interp2app_classmethod(self):
space = self.space
w = space.wrap
def g_run(space, w_type):
assert space.is_w(w_type, space.w_str)
return w(42)
app_g_run = gateway.interp2app_temp(g_run, unwrap_spec=[gateway.ObjSpace, gateway.W_Root], as_classmethod=True)
w_app_g_run = space.wrap(app_g_run)
w_bound = space.get(w_app_g_run, w("hello"), space.w_str)
assert space.eq_w(space.call_function(w_bound), w(42))
开发者ID:Qointum,项目名称:pypy,代码行数:12,代码来源:test_gateway.py
示例18: test_interp2app_unwrap_spec_args_w
def test_interp2app_unwrap_spec_args_w(self):
space = self.space
w = space.wrap
def g3_args_w(space, args_w):
return space.add(args_w[0], args_w[1])
app_g3_args_w = gateway.interp2app_temp(g3_args_w, unwrap_spec=[gateway.ObjSpace, "args_w"])
w_app_g3_args_w = space.wrap(app_g3_args_w)
assert self.space.eq_w(
space.call(w_app_g3_args_w, space.newtuple([w("foo"), w("bar")]), space.newdict()), w("foobar")
)
assert self.space.eq_w(space.call_function(w_app_g3_args_w, w("foo"), w("bar")), w("foobar"))
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:test_gateway.py
示例19: test_interp2app_unwrap_spec_r_uint
def test_interp2app_unwrap_spec_r_uint(self):
space = self.space
w = space.wrap
def g3_ll(space, n):
return space.wrap(n * 3)
app_g3_ll = gateway.interp2app_temp(g3_ll, unwrap_spec=[gateway.ObjSpace, gateway.r_uint])
w_app_g3_ll = space.wrap(app_g3_ll)
w_big = w(gateway.r_uint(sys.maxint + 100))
assert space.eq_w(space.call_function(w_app_g3_ll, w_big), w(gateway.r_uint((sys.maxint + 100) * 3)))
space.raises_w(space.w_OverflowError, space.call_function, w_app_g3_ll, w(10L ** 100))
space.raises_w(space.w_ValueError, space.call_function, w_app_g3_ll, w(-1))
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:test_gateway.py
示例20: test_interp2app_unwrap_spec_unicode
def test_interp2app_unwrap_spec_unicode(self):
space = self.space
w = space.wrap
def g3_u(space, uni):
return space.wrap(len(uni))
app_g3_u = gateway.interp2app_temp(g3_u, unwrap_spec=[gateway.ObjSpace, unicode])
w_app_g3_u = space.wrap(app_g3_u)
assert self.space.eq_w(space.call_function(w_app_g3_u, w(u"foo")), w(3))
assert self.space.eq_w(space.call_function(w_app_g3_u, w("baz")), w(3))
raises(gateway.OperationError, space.call_function, w_app_g3_u, w(None))
raises(gateway.OperationError, space.call_function, w_app_g3_u, w(42))
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:test_gateway.py
注:本文中的pypy.interpreter.gateway.interp2app_temp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论