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


Python typedef.interp_attrproperty函数代码示例

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


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

示例1: test_interp_attrproperty

def test_interp_attrproperty():
    W_MyType.typedef = TypeDef("MyType",
                               x = interp_attrproperty("x", W_MyType))
    space = CPyObjSpace()

    def mytest(w_myobj):
        myobj = space.interp_w(W_MyType, w_myobj, can_be_None=True)
        if myobj is None:
            myobj = W_MyType(space)
            myobj.x = 1
        myobj.x *= 2
        w_myobj = space.wrap(myobj)
        w_x = space.wrap(myobj.x)
        return space.newtuple([w_myobj, w_x])

    def fn(obj):
        w_obj = W_Object(obj)
        w_res = mytest(w_obj)
        return w_res.value
    fn.allow_someobjects = True

    fn = compile(fn, [object],
                 annotatorpolicy = CPyAnnotatorPolicy(space))

    res, x = fn(None, expected_extra_mallocs=1)
    assert type(res).__name__ == 'MyType'
    assert x == 2
    assert res.x == 2

    res2, x = fn(res, expected_extra_mallocs=1)
    assert res2 is res
    assert x == 4
    assert res.x == 4
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:33,代码来源:test_typedef.py

示例2: test_with_new_with_allocate_instance_subclass

def test_with_new_with_allocate_instance_subclass():
    py.test.skip("dealloction for now segfaults")
    def mytype_new(space, w_subtype, x):
        w_obj = space.allocate_instance(W_MyType, w_subtype)
        W_MyType.__init__(space.interp_w(W_MyType, w_obj), space, x)
        return w_obj
    mytype_new.unwrap_spec = [ObjSpace, W_Root, int]

    W_MyType.typedef = TypeDef("MyType",
                               __new__ = interp2app(mytype_new),
                               x = interp_attrproperty("x", W_MyType))
    space = CPyObjSpace()

    def build():
        w_type = space.gettypefor(W_MyType)
        return space.call_function(w_type, space.wrap(42))

    fn = compile(build, [],
                 annotatorpolicy = CPyAnnotatorPolicy(space))
    res = fn(expected_extra_mallocs=1)
    assert type(res).__name__ == 'MyType'
    assert res.x == 42

    class MyType2(type(res)):
        pass

    res2 = MyType2(42)
    assert type(res2) is MyType2
    assert res2.x == 42

    del res2
    import gc
    gc.collect()
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:33,代码来源:test_typedef.py

示例3: test_with_new_with_allocate_instance

def test_with_new_with_allocate_instance():
    def mytype_new(space, w_subtype, x):
        w_obj = space.allocate_instance(W_MyType, w_subtype)
        W_MyType.__init__(space.interp_w(W_MyType, w_obj), space, x)
        return w_obj
    mytype_new.unwrap_spec = [ObjSpace, W_Root, int]

    W_MyType.typedef = TypeDef("MyType",
                               __new__ = interp2app(mytype_new),
                               x = interp_attrproperty("x", W_MyType))
    space = CPyObjSpace()

    def build():
        w_type = space.gettypefor(W_MyType)
        return space.call_function(w_type, space.wrap(42))

    w_obj = build()
    w_name = space.getattr(space.type(w_obj), space.wrap('__name__'))
    assert space.unwrap(w_name) == 'MyType'
    assert space.int_w(space.getattr(w_obj, space.wrap('x'))) == 42

    fn = compile(build, [],
                 annotatorpolicy = CPyAnnotatorPolicy(space))
    res = fn(expected_extra_mallocs=1)
    assert type(res).__name__ == 'MyType'
    assert res.x == 42
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:test_typedef.py

示例4: patch_unicodedb

def patch_unicodedb():
    from pypy.module.unicodedata import unicodedb_4_1_0
    from pypy.module.unicodedata.interp_ucd import UCD, methods, \
         unichr_to_code_w
    from pypy.interpreter.gateway import W_Root, ObjSpace, NoneNotWrapped
    from unicodedb import _casefold
    from pypy.interpreter.typedef import TypeDef, interp_attrproperty
    from pypy.interpreter.gateway import  interp2app

    def casefold(code):
        try:
            return _casefold[code]
        except KeyError:
            return [code]

    unicodedb_4_1_0.casefold = casefold

    # patch the app-level, so it's exposed
    def interp_casefold(self, space, w_unichr):
        code = unichr_to_code_w(space, w_unichr)
        return space.newlist([space.wrap(c) for c in casefold(code)])
    unwrap_spec = ['self', ObjSpace, W_Root]
    
    UCD.casefold = interp_casefold
    methods['casefold'] = interp2app(UCD.casefold, unwrap_spec=unwrap_spec)
    UCD.typedef = TypeDef("unicodedata.UCD",
                          __doc__ = "",
                          unidata_version = interp_attrproperty('version', UCD),
                          **methods)
开发者ID:enyst,项目名称:plexnet,代码行数:29,代码来源:pypy_startup.py

示例5: test_multiple_inheritance

    def test_multiple_inheritance(self):
        class W_A(W_Root):
            a = 1
            b = 2
        class W_C(W_A):
            b = 3
        W_A.typedef = typedef.TypeDef("A",
            a = typedef.interp_attrproperty("a", cls=W_A),
            b = typedef.interp_attrproperty("b", cls=W_A),
        )
        class W_B(W_Root):
            pass
        def standalone_method(space, w_obj):
            if isinstance(w_obj, W_A):
                return space.w_True
            else:
                return space.w_False
        W_B.typedef = typedef.TypeDef("B",
            c = interp2app(standalone_method)
        )
        W_C.typedef = typedef.TypeDef("C", (W_A.typedef, W_B.typedef,))

        w_o1 = self.space.wrap(W_C())
        w_o2 = self.space.wrap(W_B())
        w_c = self.space.gettypefor(W_C)
        w_b = self.space.gettypefor(W_B)
        w_a = self.space.gettypefor(W_A)
        assert w_c.mro_w == [
            w_c,
            w_a,
            w_b,
            self.space.w_object,
        ]
        for w_tp in w_c.mro_w:
            assert self.space.isinstance_w(w_o1, w_tp)
        def assert_attr(w_obj, name, value):
            assert self.space.unwrap(self.space.getattr(w_obj, self.space.wrap(name))) == value
        def assert_method(w_obj, name, value):
            assert self.space.unwrap(self.space.call_method(w_obj, name)) == value
        assert_attr(w_o1, "a", 1)
        assert_attr(w_o1, "b", 3)
        assert_method(w_o1, "c", True)
        assert_method(w_o2, "c", False)
开发者ID:Darriall,项目名称:pypy,代码行数:43,代码来源:test_typedef.py

示例6: __init__

    def __init__(self, space):
        W_IOError.__init__(self, space)
        self.written = 0

    @unwrap_spec(written=int)
    def descr_init(self, space, w_errno, w_strerror, written=0):
        W_IOError.descr_init(self, space, [w_errno, w_strerror])
        self.written = written

W_BlockingIOError.typedef = TypeDef(
    'BlockingIOError', W_IOError.typedef,
    __doc__ = ("Exception raised when I/O would block on a non-blocking "
               "I/O stream"),
    __new__  = generic_new_descr(W_BlockingIOError),
    __init__ = interp2app(W_BlockingIOError.descr_init),
    characters_written = interp_attrproperty('written', W_BlockingIOError),
    )

DEFAULT_BUFFER_SIZE = 8 * 1024

@unwrap_spec(mode=str, buffering=int,
             encoding="str_or_None", errors="str_or_None",
             newline="str_or_None", closefd=bool)
def open(space, w_file, mode="r", buffering=-1, encoding=None, errors=None,
    newline=None, closefd=True):
    from pypy.module._io.interp_bufferedio import (W_BufferedRandom,
        W_BufferedWriter, W_BufferedReader)

    if not (space.isinstance_w(w_file, space.w_basestring) or
        space.isinstance_w(w_file, space.w_int) or
        space.isinstance_w(w_file, space.w_long)):
开发者ID:Darriall,项目名称:pypy,代码行数:31,代码来源:interp_io.py

示例7: TypeDef

                      res_dtype, w_lhs, w_rhs, out)
        w_lhs.add_invalidates(w_res)
        w_rhs.add_invalidates(w_res)
        if out:
            w_res.get_concrete()
        return w_res


W_Ufunc.typedef = TypeDef("ufunc",
    __module__ = "numpypy",

    __call__ = interp2app(W_Ufunc.descr_call),
    __repr__ = interp2app(W_Ufunc.descr_repr),

    identity = GetSetProperty(W_Ufunc.descr_get_identity),
    nin = interp_attrproperty("argcount", cls=W_Ufunc),

    reduce = interp2app(W_Ufunc.descr_reduce),
)


def find_binop_result_dtype(space, dt1, dt2, promote_to_float=False,
    promote_bools=False, int_only=False):
    # dt1.num should be <= dt2.num
    if dt1.num > dt2.num:
        dt1, dt2 = dt2, dt1
    if int_only and (not dt1.is_int_type() or not dt2.is_int_type()):
        raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
    # Some operations promote op(bool, bool) to return int8, rather than bool
    if promote_bools and (dt1.kind == dt2.kind == interp_dtype.BOOLLTR):
        return interp_dtype.get_dtype_cache(space).w_int8dtype
开发者ID:are-prabhu,项目名称:pypy,代码行数:31,代码来源:interp_ufuncs.py

示例8: __repr__

        self.name = name
        self.w_ffitype = w_ffitype
        self.offset = -1

    def __repr__(self):
        return '<Field %s %s>' % (self.name, self.w_ffitype.name)

@unwrap_spec(name=str)
def descr_new_field(space, w_type, name, w_ffitype):
    w_ffitype = space.interp_w(W_FFIType, w_ffitype)
    return W_Field(name, w_ffitype)

W_Field.typedef = TypeDef(
    'Field',
    __new__ = interp2app(descr_new_field),
    name = interp_attrproperty('name', W_Field),
    ffitype = interp_attrproperty('w_ffitype', W_Field),
    offset = interp_attrproperty('offset', W_Field),
    )


# ==============================================================================

class FFIStructOwner(object):
    """
    The only job of this class is to stay outside of the reference cycle
    W__StructDescr -> W_FFIType -> W__StructDescr and free the ffistruct
    """

    def __init__(self, ffistruct):
        self.ffistruct = ffistruct
开发者ID:MichaelBlume,项目名称:pypy,代码行数:31,代码来源:interp_struct.py

示例9: Decompress___new__

        except rzlib.RZlibError:
            string = ""
        else:
            string, finished, unused_len = result
            self._save_unconsumed_input(data, finished, unused_len)
        return space.wrap(string)


@unwrap_spec(wbits=int)
def Decompress___new__(space, w_subtype, wbits=rzlib.MAX_WBITS):
    """
    Create a new Decompress and call its initializer.
    """
    stream = space.allocate_instance(Decompress, w_subtype)
    stream = space.interp_w(Decompress, stream)
    Decompress.__init__(stream, space, wbits)
    return space.wrap(stream)


Decompress.typedef = TypeDef(
    'Decompress',
    __new__ = interp2app(Decompress___new__),
    decompress = interp2app(Decompress.decompress),
    flush = interp2app(Decompress.flush),
    unused_data = interp_attrproperty('unused_data', Decompress),
    unconsumed_tail = interp_attrproperty('unconsumed_tail', Decompress),
    __doc__ = """decompressobj([wbits]) -- Return a decompressor object.

Optional arg wbits is the window buffer size.
""")
开发者ID:Darriall,项目名称:pypy,代码行数:30,代码来源:interp_zlib.py

示例10: cclassmethod_descr_get

        return space.wrap(Method(space, w_function, w_obj, w_cls))
    else:
        return w_function

def cclassmethod_descr_get(space, w_function, w_obj, w_cls=None):
    if not w_cls:
        w_cls = space.type(w_obj)
    return space.wrap(Method(space, w_function, w_cls, space.w_None))


W_PyCFunctionObject.typedef = TypeDef(
    'builtin_function_or_method',
    __call__ = interp2app(cfunction_descr_call),
    __doc__ = GetSetProperty(W_PyCFunctionObject.get_doc),
    __module__ = interp_attrproperty_w('w_module', cls=W_PyCFunctionObject),
    __name__ = interp_attrproperty('name', cls=W_PyCFunctionObject),
    )
W_PyCFunctionObject.typedef.acceptable_as_base_class = False

W_PyCMethodObject.typedef = TypeDef(
    'method',
    __get__ = interp2app(cmethod_descr_get),
    __call__ = interp2app(cmethod_descr_call),
    __name__ = interp_attrproperty('name', cls=W_PyCMethodObject),
    __objclass__ = interp_attrproperty_w('w_objclass', cls=W_PyCMethodObject),
    __repr__ = interp2app(W_PyCMethodObject.descr_method_repr),
    )
W_PyCMethodObject.typedef.acceptable_as_base_class = False

W_PyCClassMethodObject.typedef = TypeDef(
    'classmethod',
开发者ID:charred,项目名称:pypy,代码行数:31,代码来源:methodobject.py

示例11: len

        start, stop = self.decodeslice(space, w_slice)
        value = space.str_w(w_value)
        if start + len(value) != stop:
            raise oefmt(space.w_ValueError, "cannot resize array")
        ll_buffer = self.ll_buffer
        for i in range(len(value)):
            ll_buffer[start + i] = value[i]

W_ArrayInstance.typedef = TypeDef(
    'ArrayInstance',
    __repr__    = interp2app(W_ArrayInstance.descr_repr),
    __setitem__ = interp2app(W_ArrayInstance.descr_setitem),
    __getitem__ = interp2app(W_ArrayInstance.descr_getitem),
    __len__     = interp2app(W_ArrayInstance.getlength),
    buffer      = GetSetProperty(W_ArrayInstance.getbuffer),
    shape       = interp_attrproperty('shape', W_ArrayInstance),
    free        = interp2app(W_ArrayInstance.free),
    byptr       = interp2app(W_ArrayInstance.byptr),
    itemaddress = interp2app(W_ArrayInstance.descr_itemaddress),
)
W_ArrayInstance.typedef.acceptable_as_base_class = False


class W_ArrayInstanceAutoFree(W_ArrayInstance):
    def __init__(self, space, shape, length):
        W_ArrayInstance.__init__(self, space, shape, length, 0)

    @rgc.must_be_light_finalizer
    def __del__(self):
        if self.ll_buffer:
            self._free()
开发者ID:mozillazg,项目名称:pypy,代码行数:31,代码来源:array.py

示例12: W_Structure

    if space.is_true(space.isinstance(w_shapeinfo, space.w_tuple)):
        w_size, w_alignment = space.fixedview(w_shapeinfo, expected_length=2)
        S = W_Structure(space, None, space.int_w(w_size), space.int_w(w_alignment))
    else:
        fields = unpack_fields(space, w_shapeinfo)
        S = W_Structure(space, fields, 0, 0)
    return space.wrap(S)


W_Structure.typedef = TypeDef(
    "Structure",
    __new__=interp2app(descr_new_structure),
    __call__=interp2app(W_Structure.descr_call),
    __repr__=interp2app(W_Structure.descr_repr),
    fromaddress=interp2app(W_Structure.fromaddress),
    size=interp_attrproperty("size", W_Structure),
    alignment=interp_attrproperty("alignment", W_Structure),
    fieldoffset=interp2app(W_Structure.descr_fieldoffset),
    size_alignment=interp2app(W_Structure.descr_size_alignment),
)
W_Structure.typedef.acceptable_as_base_class = False


def push_field(self, num, value):
    ptr = rffi.ptradd(self.ll_buffer, self.shape.ll_positions[num])
    TP = lltype.typeOf(value)
    T = lltype.Ptr(rffi.CArray(TP))
    rffi.cast(T, ptr)[0] = value


push_field._annspecialcase_ = "specialize:argtype(2)"
开发者ID:alkorzt,项目名称:pypy,代码行数:31,代码来源:structure.py

示例13: TypeDef

W_SRE_Pattern.typedef = TypeDef(
    'SRE_Pattern',
    __new__      = interp2app(SRE_Pattern__new__),
    __copy__     = interp2app(W_SRE_Pattern.cannot_copy_w),
    __deepcopy__ = interp2app(W_SRE_Pattern.cannot_copy_w),
    __weakref__  = make_weakref_descr(W_SRE_Pattern),
    findall      = interp2app(W_SRE_Pattern.findall_w),
    finditer     = interp2app(W_SRE_Pattern.finditer_w),
    match        = interp2app(W_SRE_Pattern.match_w),
    scanner      = interp2app(W_SRE_Pattern.finditer_w),    # reuse finditer()
    search       = interp2app(W_SRE_Pattern.search_w),
    split        = interp2app(W_SRE_Pattern.split_w),
    sub          = interp2app(W_SRE_Pattern.sub_w),
    subn         = interp2app(W_SRE_Pattern.subn_w),
    flags        = interp_attrproperty('flags', W_SRE_Pattern),
    groupindex   = interp_attrproperty_w('w_groupindex', W_SRE_Pattern),
    groups       = interp_attrproperty('num_groups', W_SRE_Pattern),
    pattern      = interp_attrproperty_w('w_pattern', W_SRE_Pattern),
)

# ____________________________________________________________
#
# SRE_Match class

class W_SRE_Match(Wrappable):
    flatten_cache = None

    def __init__(self, srepat, ctx):
        self.space = srepat.space
        self.srepat = srepat
开发者ID:gorakhargosh,项目名称:pypy,代码行数:30,代码来源:interp_sre.py

示例14: wrap_oserror

        except OSError, e:
            raise wrap_oserror(space, e, exception_name='w_IOError')

        return w_size

W_FileIO.typedef = TypeDef(
    'FileIO', W_RawIOBase.typedef,
    __new__  = interp2app(W_FileIO.descr_new.im_func),
    __init__  = interp2app(W_FileIO.descr_init),
    __repr__ = interp2app(W_FileIO.repr_w),

    seek = interp2app(W_FileIO.seek_w),
    tell = interp2app(W_FileIO.tell_w),
    write = interp2app(W_FileIO.write_w),
    read = interp2app(W_FileIO.read_w),
    readinto = interp2app(W_FileIO.readinto_w),
    readall = interp2app(W_FileIO.readall_w),
    truncate = interp2app(W_FileIO.truncate_w),
    close = interp2app(W_FileIO.close_w),

    readable = interp2app(W_FileIO.readable_w),
    writable = interp2app(W_FileIO.writable_w),
    seekable = interp2app(W_FileIO.seekable_w),
    fileno = interp2app(W_FileIO.fileno_w),
    isatty = interp2app(W_FileIO.isatty_w),
    name = interp_member_w('w_name', cls=W_FileIO),
    closefd = interp_attrproperty('closefd', cls=W_FileIO),
    mode = GetSetProperty(W_FileIO.descr_get_mode),
    )

开发者ID:ieure,项目名称:pypy,代码行数:29,代码来源:interp_fileio.py

示例15: r_longlong

            fmin = -(r_longlong(1) << (self.bitsize - 1))
            fmax = (r_longlong(1) << (self.bitsize - 1)) - 1
            if fmax == 0:
                fmax = 1      # special case to let "int x:1" receive "1"
        else:
            is_signed = False
            fmin = r_longlong(0)
            fmax = r_longlong((r_ulonglong(1) << self.bitsize) - 1)
        if value < fmin or value > fmax:
            raise oefmt(space.w_OverflowError,
                        "value %d outside the range allowed by the bit field "
                        "width: %d <= x <= %d", value, fmin, fmax)
        rawmask = ((r_ulonglong(1) << self.bitsize) - 1) << self.bitshift
        rawvalue = r_ulonglong(value) << self.bitshift
        rawfielddata = misc.read_raw_unsigned_data(cdata, ctype.size)
        rawfielddata = (rawfielddata & ~rawmask) | (rawvalue & rawmask)
        if is_signed:
            misc.write_raw_signed_data(cdata, rawfielddata, ctype.size)
        else:
            misc.write_raw_unsigned_data(cdata, rawfielddata, ctype.size)


W_CField.typedef = TypeDef(
    '_cffi_backend.CField',
    type = interp_attrproperty('ctype', W_CField),
    offset = interp_attrproperty('offset', W_CField),
    bitshift = interp_attrproperty('bitshift', W_CField),
    bitsize = interp_attrproperty('bitsize', W_CField),
    )
W_CField.typedef.acceptable_as_base_class = False
开发者ID:bukzor,项目名称:pypy,代码行数:30,代码来源:ctypestruct.py


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