当前位置: 首页>>代码示例>>Python>>正文


Python ootype.new函数代码示例

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


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

示例1: f

 def f(n):
     obj1 = ootype.new(A)
     if n:
         obj2 = obj1
     else:
         obj2 = ootype.new(A)
     return obj1 is obj2
开发者ID:enyst,项目名称:plexnet,代码行数:7,代码来源:test_basic.py

示例2: ll_join_chars

 def ll_join_chars(length_dummy, lst):
     if typeOf(lst)._ITEMTYPE == Char:
         buf = ootype.new(ootype.StringBuilder)
     else:
         buf = ootype.new(ootype.UnicodeBuilder)
     length = lst.ll_length()
     buf.ll_allocate(length)
     i = 0
     while i < length:
         buf.ll_append_char(lst.ll_getitem_fast(i))
         i += 1
     return buf.ll_build()
开发者ID:antoine1fr,项目名称:pygirl,代码行数:12,代码来源:rstr.py

示例3: test_unwrap_object

 def test_unwrap_object(self):
     A = ootype.Instance("A", ootype.ROOT, {})
     a1 = ootype.new(A)
     a2 = ootype.new(A)
     obj1 = ootype.cast_to_object(a1)
     obj2 = ootype.cast_to_object(a2)
     def fn(flag):
         if flag:
             obj = obj1
         else:
             obj = obj2
         a3 = ootype.cast_from_object(A, obj)
         return a3 is a1
     res = self.interpret(fn, [True], backendopt=False)
     assert res is True
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:constant.py

示例4: fn_instance

 def fn_instance():
     a = ootype.new(A)
     obj = ootype.cast_to_object(a)
     a2 = ootype.cast_from_object(A, obj)
     a3 = ootype.cast_from_object(ootype.ROOT, obj)
     assert a is a2
     assert a is a3
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py

示例5: ll_rangeiter

def ll_rangeiter(ITER, rng):
    iter = new(ITER)
    iter.next = rng.start
    iter.stop = rng.stop
    if ITER is RANGESTITER:
        iter.step = rng.step
    return iter
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:rrange.py

示例6: fn_record

 def fn_record():
     b = ootype.new(B)
     b.x = 42
     obj = ootype.cast_to_object(b)
     b2 = ootype.cast_from_object(B, obj)
     assert b2.x == 42
     assert b is b2
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py

示例7: fn_is_true

 def fn_is_true(flag):
     if flag:
         a = ootype.new(A)
     else:
         a = ootype.null(A)
     obj = ootype.cast_to_object(a)
     return bool(obj)
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py

示例8: test_invalid_cache

def test_invalid_cache():
    DT = Dict(Signed, Signed)
    d = new(DT)
    py.test.raises(AssertionError, d.ll_get, 0)
    d.ll_set(42, 1)
    d.ll_contains(43)
    py.test.raises(AssertionError, d.ll_get, 42)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_oodict.py

示例9: fn_mix_null

 def fn_mix_null(flag):
     a = ootype.new(A)
     obj = ootype.cast_to_object(a)
     if flag:
         return obj
     else:
         return ootype.NULL
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py

示例10: make_pyexcclass2exc

    def make_pyexcclass2exc(self, rtyper):
        # ll_pyexcclass2exc(python_exception_class) -> exception_instance
        table = {}
        Exception_def = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception)
        for clsdef in rtyper.class_reprs:
            if (clsdef and clsdef is not Exception_def
                and clsdef.issubclass(Exception_def)):
                if not hasattr(clsdef.classdesc, 'pyobj'):
                    continue
                cls = clsdef.classdesc.pyobj
                if cls in self.standardexceptions and cls not in FORCE_ATTRIBUTES_INTO_CLASSES:
                    is_standard = True
                    assert not clsdef.attrs, (
                        "%r should not have grown attributes" % (cls,))
                else:
                    is_standard = (cls.__module__ == 'exceptions'
                                   and not clsdef.attrs)
                if is_standard:
                    example = self.get_standard_ll_exc_instance(rtyper, clsdef)
                    table[cls] = example
        r_inst = rclass.getinstancerepr(rtyper, None)
        r_inst.setup()
        r_class = rclass.getclassrepr(rtyper, None)
        r_class.setup()
        default_excinst = ootype.new(self.lltype_of_exception_value)
        default_excinst.meta = r_class.get_meta_instance()

        # build the table in order base classes first, subclasses last
        sortedtable = []
        def add_class(cls):
            if cls in table:
                for base in cls.__bases__:
                    add_class(base)
                sortedtable.append((cls, table[cls]))
                del table[cls]
        for cls in table.keys():
            add_class(cls)
        assert table == {}

        initial_value_of_i = len(sortedtable) - 1
        def pyexcclass2exc(python_exception_class):
            python_exception_class = python_exception_class._obj.value
            i = initial_value_of_i
            while i >= 0:
                if issubclass(python_exception_class, sortedtable[i][0]):
                    return sortedtable[i][1]
                i -= 1
            return default_excinst

        # This function will only be used by the llinterpreter which usually
        # expects a low-level callable (_meth, _static_meth), so we just
        # fake it here.
        FakeCallableType = ootype.OOType()
        FakeCallableType.ARGS = ()
        class fake_callable(object):
            def __init__(self, fn):
                self._TYPE = FakeCallableType
                self._callable = fn
        return fake_callable(pyexcclass2exc)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:59,代码来源:exceptiondata.py

示例11: h

 def h(x, y, z):
     s = ootype.new(S)
     s.x = x
     s.y = y
     fsm = llhelper(F, f)
     gsm = llhelper(G, g)
     assert typeOf(fsm) == F
     return fsm(s, z)+fsm(s, z*2)+gsm(s)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_llann.py

示例12: ll_newrangest

def ll_newrangest(start, stop, step):
    if step == 0:
        raise ValueError
    l = new(RANGEST)
    l.start = start
    l.stop = stop
    l.step = step
    return l
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:rrange.py

示例13: ll_known_maxlength2list

def ll_known_maxlength2list(RESLIST, l):
    res = ootype.new(RESLIST)
    length = l.length
    res._ll_resize_ge(length)
    for i in range(length):
        item = l.items.ll_getitem_fast(i)
        res.ll_setitem_fast(i, item)
    return res
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:rlist.py

示例14: ll_popitem

def ll_popitem(ELEM, d):
    it = d.ll_get_items_iterator()
    if it.ll_go_next():
        res = ootype.new(ELEM)
        key = res.item0 = it.ll_current_key()
        res.item1 = it.ll_current_value()
        d.ll_remove(key)
        return res
    raise KeyError
开发者ID:ieure,项目名称:pypy,代码行数:9,代码来源:rdict.py

示例15: get_meta_instance

 def get_meta_instance(self, cast_to_root_meta=True):
     if self.meta_instance is None:
         self.meta_instance = ootype.new(self.lowleveltype) 
         self.setup_meta_instance(self.meta_instance, self)
     
     meta_instance = self.meta_instance
     if cast_to_root_meta:
         meta_instance = ootype.ooupcast(CLASSTYPE, meta_instance)
     return meta_instance
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:rclass.py


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