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

Python error.oefmt函数代码示例

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

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



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

示例1: _new_array_type

def _new_array_type(space, w_ctptr, length):
    _setup_wref(rweakref.has_weakref_support())
    if not isinstance(w_ctptr, ctypeptr.W_CTypePointer):
        raise oefmt(space.w_TypeError, "first arg must be a pointer ctype")
    arrays = w_ctptr._array_types
    if arrays is None:
        arrays = rweakref.RWeakValueDictionary(int, ctypearray.W_CTypeArray)
        w_ctptr._array_types = arrays
    else:
        ctype = arrays.get(length)
        if ctype is not None:
            return ctype
    #
    ctitem = w_ctptr.ctitem
    if ctitem.size < 0:
        raise oefmt(space.w_ValueError, "array item of unknown size: '%s'",
                    ctitem.name)
    if length < 0:
        assert length == -1
        arraysize = -1
        extra = '[]'
    else:
        try:
            arraysize = ovfcheck(length * ctitem.size)
        except OverflowError:
            raise oefmt(space.w_OverflowError,
                        "array size would overflow a ssize_t")
        extra = '[%d]' % length
    #
    ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra)
    arrays.set(length, ctype)
    return ctype
开发者ID:mozillazg,项目名称:pypy,代码行数:32,代码来源:newtype.py


示例2: descr_translate

 def descr_translate(self, space, w_table):
     selfvalue = self._value
     w_sys = space.getbuiltinmodule('sys')
     maxunicode = space.int_w(space.getattr(w_sys,
                                            space.wrap("maxunicode")))
     result = []
     for unichar in selfvalue:
         try:
             w_newval = space.getitem(w_table, space.wrap(ord(unichar)))
         except OperationError as e:
             if e.match(space, space.w_LookupError):
                 result.append(unichar)
             else:
                 raise
         else:
             if space.is_w(w_newval, space.w_None):
                 continue
             elif space.isinstance_w(w_newval, space.w_int):
                 newval = space.int_w(w_newval)
                 if newval < 0 or newval > maxunicode:
                     raise oefmt(space.w_TypeError,
                                 "character mapping must be in range(%s)",
                                 hex(maxunicode + 1))
                 result.append(unichr(newval))
             elif space.isinstance_w(w_newval, space.w_unicode):
                 result.append(space.unicode_w(w_newval))
             else:
                 raise oefmt(space.w_TypeError,
                             "character mapping must return integer, None "
                             "or str")
     return W_UnicodeObject(u''.join(result))
开发者ID:Qointum,项目名称:pypy,代码行数:31,代码来源:unicodeobject.py


示例3: _getfunc

    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype):
        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
            space, w_argtypes, w_restype)
        if space.isinstance_w(w_name, space.w_str):
            name = space.str_w(w_name)
            try:
                func = CDLL.cdll.getpointer(name, argtypes, restype,
                                            flags = CDLL.flags)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No symbol %s found in library %s",
                            name, CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        elif space.isinstance_w(w_name, space.w_int):
            ordinal = space.int_w(w_name)
            try:
                func = CDLL.cdll.getpointer_by_ordinal(
                    ordinal, argtypes, restype,
                    flags = CDLL.flags)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No ordinal %d found in library %s",
                            ordinal, CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        else:
            raise OperationError(space.w_TypeError, space.wrap(
                    'function name must be a string or integer'))
开发者ID:Darriall,项目名称:pypy,代码行数:33,代码来源:interp_funcptr.py


示例4: _realize_c_struct_or_union

def _realize_c_struct_or_union(ffi, sindex):
    s = ffi.ctxobj.ctx.c_struct_unions[sindex]
    type_index = rffi.getintfield(s, 'c_type_index')
    if ffi.cached_types[type_index] is not None:
        return ffi.cached_types[type_index] #found already in the "primary" slot

    space = ffi.space
    w_ctype = None
    c_flags = rffi.getintfield(s, 'c_flags')
    c_first_field_index = rffi.getintfield(s, 'c_first_field_index')
    if (c_flags & cffi_opcode.F_EXTERNAL) == 0:
        if (c_flags & cffi_opcode.F_UNION) != 0:
            name = _realize_name("union ", s.c_name)
            x = ctypestruct.W_CTypeUnion(space, name)
        else:
            name = _realize_name("struct ", s.c_name)
            x = ctypestruct.W_CTypeStruct(space, name)
        if (c_flags & cffi_opcode.F_OPAQUE) == 0:
            assert c_first_field_index >= 0
            w_ctype = x
            w_ctype.size = rffi.getintfield(s, 'c_size')
            w_ctype.alignment = rffi.getintfield(s, 'c_alignment')
            # w_ctype._field_list and other underscore fields are still
            # None, making it a "lazy" (i.e. "non-forced") kind of struct
            w_ctype._lazy_ffi = ffi
            w_ctype._lazy_s = s
        else:
            assert c_first_field_index < 0
    else:
        assert c_first_field_index < 0
        x = _fetch_external_struct_or_union(s, ffi.included_ffis_libs)
        if x is None:
            raise oefmt(ffi.w_FFIError,
                    "'%s %s' should come from ffi.include() but was not found",
                    "union" if c_flags & cffi_opcode.F_UNION else "struct",
                    rffi.charp2str(s.c_name))
        assert isinstance(x, ctypestruct.W_CTypeStructOrUnion)
        if (c_flags & cffi_opcode.F_OPAQUE) == 0 and x.size < 0:
            prefix = "union" if c_flags & cffi_opcode.F_UNION else "struct"
            name = rffi.charp2str(s.c_name)
            raise oefmt(space.w_NotImplementedError,
                    "'%s %s' is opaque in the ffi.include(), but no "
                    "longer in the ffi doing the include (workaround: don't "
                    "use ffi.include() but duplicate the declarations of "
                    "everything using %s %s)",
                    prefix, name, prefix, name)

    # Update the "primary" OP_STRUCT_UNION slot
    ffi.cached_types[type_index] = x

    if w_ctype is not None and rffi.getintfield(s, 'c_size') == -2:
        # oops, this struct is unnamed and we couldn't generate
        # a C expression to get its size.  We have to rely on
        # complete_struct_or_union() to compute it now.
        try:
            do_realize_lazy_struct(w_ctype)
        except:
            ffi.cached_types[type_index] = None
            raise
    return x
开发者ID:Qointum,项目名称:pypy,代码行数:60,代码来源:realize_c_type.py


示例5: descr_long

 def descr_long(self, space):
     try:
         return W_LongObject.fromfloat(space, self.floatval)
     except OverflowError:
         raise oefmt(space.w_OverflowError, "cannot convert float infinity to integer")
     except ValueError:
         raise oefmt(space.w_ValueError, "cannot convert float NaN to integer")
开发者ID:cimarieta,项目名称:usp,代码行数:7,代码来源:floatobject.py


示例6: __init__

 def __init__(self, space, ctype, w_callable, w_error, w_onerror):
     raw_closure = rffi.cast(rffi.CCHARP, clibffi.closureHeap.alloc())
     self._closure = Closure(raw_closure)
     W_ExternPython.__init__(self, space, raw_closure, ctype,
                             w_callable, w_error, w_onerror)
     self.key_pycode = space._try_fetch_pycode(w_callable)
     #
     cif_descr = self.getfunctype().cif_descr
     if not cif_descr:
         raise oefmt(space.w_NotImplementedError,
                     "%s: callback with unsupported argument or "
                     "return type or with '...'", self.getfunctype().name)
     with self as ptr:
         closure_ptr = rffi.cast(clibffi.FFI_CLOSUREP, ptr)
         unique_id = self.hide_object()
         res = clibffi.c_ffi_prep_closure(closure_ptr, cif_descr.cif,
                                          invoke_callback,
                                          unique_id)
     if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK:
         raise oefmt(space.w_SystemError,
                     "libffi failed to build this callback")
     if closure_ptr.c_user_data != unique_id:
         raise oefmt(space.w_SystemError,
             "ffi_prep_closure(): bad user_data (it seems that the "
             "version of the libffi library seen at runtime is "
             "different from the 'ffi.h' file seen at compile-time)")
开发者ID:mozillazg,项目名称:pypy,代码行数:26,代码来源:ccallback.py


示例7: execve

def execve(space, w_command, w_args, w_env):
    """ execve(path, args, env)

Execute a path with arguments and environment, replacing current process.

        path: path of executable file
        args: iterable of arguments
        env: dictionary of strings mapping to strings
    """
    command = fsencode_w(space, w_command)
    try:
        args_w = space.unpackiterable(w_args)
        if len(args_w) < 1:
            raise oefmt(space.w_ValueError,
                        "execv() must have at least one argument")
        args = [fsencode_w(space, w_arg) for w_arg in args_w]
    except OperationError as e:
        if not e.match(space, space.w_TypeError):
            raise
        raise oefmt(space.w_TypeError,
                    "execv() arg 2 must be an iterable of strings")
    #
    if w_env is None:    # when called via execv() above
        try:
            os.execv(command, args)
        except OSError as e:
            raise wrap_oserror(space, e)
    else:
        env = _env2interp(space, w_env)
        try:
            os.execve(command, args, env)
        except OSError as e:
            raise wrap_oserror(space, e)
开发者ID:mozillazg,项目名称:pypy,代码行数:33,代码来源:interp_posix.py


示例8: utime

def utime(space, w_path, w_tuple):
    """ utime(path, (atime, mtime))
utime(path, None)

Set the access and modified time of the file to the given values.  If the
second form is used, set the access and modified times to the current time.
    """
    if space.is_w(w_tuple, space.w_None):
        try:
            dispatch_filename(rposix.utime, 1)(space, w_path, None)
            return
        except OSError as e:
            raise wrap_oserror2(space, e, w_path)
    try:
        msg = "utime() arg 2 must be a tuple (atime, mtime) or None"
        args_w = space.fixedview(w_tuple)
        if len(args_w) != 2:
            raise oefmt(space.w_TypeError, msg)
        actime = space.float_w(args_w[0], allow_conversion=False)
        modtime = space.float_w(args_w[1], allow_conversion=False)
        dispatch_filename(rposix.utime, 2)(space, w_path, (actime, modtime))
    except OSError as e:
        raise wrap_oserror2(space, e, w_path)
    except OperationError as e:
        if not e.match(space, space.w_TypeError):
            raise
        raise oefmt(space.w_TypeError, msg)
开发者ID:mozillazg,项目名称:pypy,代码行数:27,代码来源:interp_posix.py


示例9: poll

    def poll(self, space, w_timeout):
        if space.is_w(w_timeout, space.w_None):
            timeout = -1
        else:
            # we want to be compatible with cpython and also accept things
            # that can be casted to integer (I think)
            try:
                # compute the integer
                w_timeout = space.int(w_timeout)
            except OperationError:
                raise oefmt(space.w_TypeError, "timeout must be an integer or None")
            timeout = space.c_int_w(w_timeout)

        if self.running:
            raise oefmt(space.w_RuntimeError, "concurrent poll() invocation")
        self.running = True
        try:
            retval = rpoll.poll(self.fddict, timeout)
        except rpoll.PollError as e:
            w_errortype = space.fromcache(Cache).w_error
            message = e.get_msg()
            raise OperationError(w_errortype, space.newtuple([space.wrap(e.errno), space.wrap(message)]))
        finally:
            self.running = False

        retval_w = []
        for fd, revents in retval:
            retval_w.append(space.newtuple([space.wrap(fd), space.wrap(revents)]))
        return space.newlist(retval_w)
开发者ID:mozillazg,项目名称:pypy,代码行数:29,代码来源:interp_select.py


示例10: convert_array_from_object

 def convert_array_from_object(self, cdata, w_ob):
     space = self.space
     if (space.isinstance_w(w_ob, space.w_list) or
         space.isinstance_w(w_ob, space.w_tuple)):
         self._convert_array_from_listview(cdata, w_ob)
     elif (self.can_cast_anything or
           (self.ctitem.is_primitive_integer and
            self.ctitem.size == rffi.sizeof(lltype.Char))):
         if not space.isinstance_w(w_ob, space.w_str):
             raise self._convert_error("str or list or tuple", w_ob)
         s = space.str_w(w_ob)
         n = len(s)
         if self.length >= 0 and n > self.length:
             raise oefmt(space.w_IndexError,
                         "initializer string is too long for '%s' (got %d "
                         "characters)", self.name, n)
         copy_string_to_raw(llstr(s), cdata, 0, n)
         if n != self.length:
             cdata[n] = '\x00'
     elif isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveUniChar):
         if not space.isinstance_w(w_ob, space.w_unicode):
             raise self._convert_error("unicode or list or tuple", w_ob)
         s = space.unicode_w(w_ob)
         n = len(s)
         if self.length >= 0 and n > self.length:
             raise oefmt(space.w_IndexError,
                         "initializer unicode string is too long for '%s' "
                         "(got %d characters)", self.name, n)
         unichardata = rffi.cast(rffi.CWCHARP, cdata)
         copy_unicode_to_raw(llunicode(s), unichardata, 0, n)
         if n != self.length:
             unichardata[n] = u'\x00'
     else:
         raise self._convert_error("list or tuple", w_ob)
开发者ID:bukzor,项目名称:pypy,代码行数:34,代码来源:ctypeptr.py


示例11: _build_function_type

def _build_function_type(space, fargs, fresult, ellipsis, abi):
    from pypy.module._cffi_backend import ctypefunc
    #
    if ((fresult.size < 0 and
         not isinstance(fresult, ctypevoid.W_CTypeVoid))
        or isinstance(fresult, ctypearray.W_CTypeArray)):
        if (isinstance(fresult, ctypestruct.W_CTypeStructOrUnion) and
                fresult.size < 0):
            raise oefmt(space.w_TypeError,
                        "result type '%s' is opaque", fresult.name)
        else:
            raise oefmt(space.w_TypeError,
                        "invalid result type: '%s'", fresult.name)
    #
    fct = ctypefunc.W_CTypeFunc(space, fargs, fresult, ellipsis, abi)
    unique_cache = space.fromcache(UniqueCache)
    func_hash = _func_key_hash(unique_cache, fargs, fresult, ellipsis, abi)
    for weakdict in unique_cache.functions:
        if weakdict.get(func_hash) is None:
            weakdict.set(func_hash, fct)
            break
    else:
        weakdict = rweakref.RWeakValueDictionary(int, ctypefunc.W_CTypeFunc)
        unique_cache.functions.append(weakdict)
        weakdict.set(func_hash, fct)
    return fct
开发者ID:mozillazg,项目名称:pypy,代码行数:26,代码来源:newtype.py


示例12: new_enum_type

def new_enum_type(space, name, w_enumerators, w_enumvalues, w_basectype):
    enumerators_w = space.fixedview(w_enumerators)
    enumvalues_w  = space.fixedview(w_enumvalues)
    if len(enumerators_w) != len(enumvalues_w):
        raise oefmt(space.w_ValueError, "tuple args must have the same size")
    enumerators = [space.str_w(w) for w in enumerators_w]
    #
    if (not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveSigned) and
        not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveUnsigned)):
        raise oefmt(space.w_TypeError,
                    "expected a primitive signed or unsigned base type")
    #
    lvalue = lltype.malloc(rffi.CCHARP.TO, w_basectype.size, flavor='raw')
    try:
        for w in enumvalues_w:
            # detects out-of-range or badly typed values
            w_basectype.convert_from_object(lvalue, w)
    finally:
        lltype.free(lvalue, flavor='raw')
    #
    size = w_basectype.size
    align = w_basectype.align
    if isinstance(w_basectype, ctypeprim.W_CTypePrimitiveSigned):
        enumvalues = [space.int_w(w) for w in enumvalues_w]
        ctype = ctypeenum.W_CTypeEnumSigned(space, name, size, align,
                                            enumerators, enumvalues)
    else:
        enumvalues = [space.uint_w(w) for w in enumvalues_w]
        ctype = ctypeenum.W_CTypeEnumUnsigned(space, name, size, align,
                                              enumerators, enumvalues)
    return ctype
开发者ID:mozillazg,项目名称:pypy,代码行数:31,代码来源:newtype.py


示例13: create_all_slots

def create_all_slots(w_self, hasoldstylebase):
    space = w_self.space
    dict_w = w_self.dict_w
    if "__slots__" not in dict_w:
        wantdict = True
        wantweakref = True
    else:
        wantdict = False
        wantweakref = False
        w_slots = dict_w["__slots__"]
        if space.isinstance_w(w_slots, space.w_str) or space.isinstance_w(w_slots, space.w_unicode):
            slot_names_w = [w_slots]
        else:
            slot_names_w = space.unpackiterable(w_slots)
        for w_slot_name in slot_names_w:
            slot_name = space.str_w(w_slot_name)
            if slot_name == "__dict__":
                if wantdict or w_self.hasdict:
                    raise oefmt(space.w_TypeError, "__dict__ slot disallowed: we already got one")
                wantdict = True
            elif slot_name == "__weakref__":
                if wantweakref or w_self.weakrefable:
                    raise oefmt(space.w_TypeError, "__weakref__ slot disallowed: we already got one")
                wantweakref = True
            else:
                create_slot(w_self, slot_name)
    wantdict = wantdict or hasoldstylebase
    if wantdict:
        create_dict_slot(w_self)
    if wantweakref:
        create_weakref_slot(w_self)
    if "__del__" in dict_w:
        w_self.needsdel = True
开发者ID:GaussDing,项目名称:pypy,代码行数:33,代码来源:typeobject.py


示例14: fmt_c

 def fmt_c(self, w_value):
     self.prec = -1     # just because
     space = self.space
     if space.isinstance_w(w_value, space.w_str):
         s = space.str_w(w_value)
         if len(s) != 1:
             raise oefmt(space.w_TypeError, "%c requires int or char")
         self.std_wp(s)
     elif space.isinstance_w(w_value, space.w_unicode):
         if not do_unicode:
             raise NeedUnicodeFormattingError
         ustr = space.unicode_w(w_value)
         if len(ustr) != 1:
             raise oefmt(space.w_TypeError, "%c requires int or unichar")
         self.std_wp(ustr)
     else:
         n = space.int_w(w_value)
         if do_unicode:
             try:
                 c = unichr(n)
             except ValueError:
                 raise oefmt(space.w_OverflowError,
                             "unicode character code out of range")
             self.std_wp(c)
         else:
             try:
                 s = chr(n)
             except ValueError:
                 raise oefmt(space.w_OverflowError,
                             "character code not in range(256)")
             self.std_wp(s)
开发者ID:mozillazg,项目名称:pypy,代码行数:31,代码来源:formatting.py


示例15: decodeslice

    def decodeslice(self, space, w_slice):
        if not space.isinstance_w(w_slice, space.w_slice):
            raise oefmt(space.w_TypeError, "index must be int or slice")
        letter = self.shape.itemcode
        if letter != 'c':
            raise oefmt(space.w_TypeError, "only 'c' arrays support slicing")
        w_start = space.getattr(w_slice, space.wrap('start'))
        w_stop = space.getattr(w_slice, space.wrap('stop'))
        w_step = space.getattr(w_slice, space.wrap('step'))

        if space.is_w(w_start, space.w_None):
            start = 0
        else:
            start = space.int_w(w_start)
        if space.is_w(w_stop, space.w_None):
            stop = self.length
        else:
            stop = space.int_w(w_stop)
        if not space.is_w(w_step, space.w_None):
            step = space.int_w(w_step)
            if step != 1:
                raise oefmt(space.w_ValueError, "no step support")
        if not (0 <= start <= stop <= self.length):
            raise oefmt(space.w_ValueError, "slice out of bounds")
        if not self.ll_buffer:
            raise segfault_exception(space, "accessing a freed array")
        return start, stop
开发者ID:mozillazg,项目名称:pypy,代码行数:27,代码来源:array.py


示例16: descr_setstate

    def descr_setstate(self, space, w_data):
        if self.fields is None:  # if builtin dtype
            return space.w_None

        version = space.int_w(space.getitem(w_data, space.wrap(0)))
        if version != 3:
            raise oefmt(space.w_ValueError,
                        "can't handle version %d of numpy.dtype pickle",
                        version)

        endian = space.str_w(space.getitem(w_data, space.wrap(1)))
        if endian == NPY.NATBYTE:
            endian = NPY.NATIVE

        w_subarray = space.getitem(w_data, space.wrap(2))
        w_names = space.getitem(w_data, space.wrap(3))
        w_fields = space.getitem(w_data, space.wrap(4))
        size = space.int_w(space.getitem(w_data, space.wrap(5)))
        alignment = space.int_w(space.getitem(w_data, space.wrap(6)))

        if (w_names == space.w_None) != (w_fields == space.w_None):
            raise oefmt(space.w_ValueError, "inconsistent fields and names")

        self.byteorder = endian
        self.shape = []
        self.subdtype = None
        self.base = self

        if w_subarray != space.w_None:
            if not space.isinstance_w(w_subarray, space.w_tuple) or \
                    space.len_w(w_subarray) != 2:
                raise oefmt(space.w_ValueError,
                            "incorrect subarray in __setstate__")
            subdtype, w_shape = space.fixedview(w_subarray)
            assert isinstance(subdtype, W_Dtype)
            if not support.issequence_w(space, w_shape):
                self.shape = [space.int_w(w_shape)]
            else:
                self.shape = [space.int_w(w_s) for w_s in space.fixedview(w_shape)]
            self.subdtype = subdtype
            self.base = subdtype.base

        if w_names != space.w_None:
            self.names = []
            self.fields = {}
            for w_name in space.fixedview(w_names):
                name = space.str_w(w_name)
                value = space.getitem(w_fields, w_name)

                dtype = space.getitem(value, space.wrap(0))
                assert isinstance(dtype, W_Dtype)
                offset = space.int_w(space.getitem(value, space.wrap(1)))

                self.names.append(name)
                self.fields[name] = offset, dtype
            self.itemtype = types.RecordType()

        if self.is_flexible():
            self.elsize = size
            self.alignment = alignment
开发者ID:yuyichao,项目名称:pypy,代码行数:60,代码来源:descriptor.py


示例17: semlock_release

    def semlock_release(self, space):
        if self.kind == RECURSIVE_MUTEX:
            sem_post(self.handle)
            return
        if HAVE_BROKEN_SEM_GETVALUE:
            # We will only check properly the maxvalue == 1 case
            if self.maxvalue == 1:
                # make sure that already locked
                try:
                    sem_trywait(self.handle)
                except OSError as e:
                    if e.errno != errno.EAGAIN:
                        raise
                    # it is already locked as expected
                else:
                    # it was not locked so undo wait and raise
                    sem_post(self.handle)
                    raise oefmt(space.w_ValueError,
                                "semaphore or lock released too many times")
        else:
            # This check is not an absolute guarantee that the semaphore does
            # not rise above maxvalue.
            if sem_getvalue(self.handle) >= self.maxvalue:
                raise oefmt(space.w_ValueError,
                            "semaphore or lock released too many times")

        sem_post(self.handle)
开发者ID:mozillazg,项目名称:pypy,代码行数:27,代码来源:interp_semaphore.py


示例18: set_param

def set_param(space, __args__):
    '''Configure the tunable JIT parameters.
        * set_param(name=value, ...)            # as keyword arguments
        * set_param("name=value,name=value")    # as a user-supplied string
        * set_param("off")                      # disable the jit
        * set_param("default")                  # restore all defaults
    '''
    # XXXXXXXXX
    args_w, kwds_w = __args__.unpack()
    if len(args_w) > 1:
        raise oefmt(space.w_TypeError,
                    "set_param() takes at most 1 non-keyword argument, %d "
                    "given", len(args_w))
    if len(args_w) == 1:
        text = space.str_w(args_w[0])
        try:
            jit.set_user_param(None, text)
        except ValueError:
            raise OperationError(space.w_ValueError,
                                 space.wrap("error in JIT parameters string"))
    for key, w_value in kwds_w.items():
        if key == 'enable_opts':
            jit.set_param(None, 'enable_opts', space.str_w(w_value))
        else:
            intval = space.int_w(w_value)
            for name, _ in unroll_parameters:
                if name == key and name != 'enable_opts':
                    jit.set_param(None, name, intval)
                    break
            else:
                raise oefmt(space.w_TypeError, "no JIT parameter '%s'", key)
开发者ID:abhinavthomas,项目名称:pypy,代码行数:31,代码来源:interp_jit.py


示例19: descr_fromhex

    def descr_fromhex(space, w_bytearraytype, w_hexstring):
        hexstring = space.str_w(w_hexstring)
        hexstring = hexstring.lower()
        data = []
        length = len(hexstring)
        i = -2
        while True:
            i += 2
            while i < length and hexstring[i] == ' ':
                i += 1
            if i >= length:
                break
            if i + 1 == length:
                raise oefmt(space.w_ValueError, NON_HEX_MSG, i)

            top = _hex_digit_to_int(hexstring[i])
            if top == -1:
                raise oefmt(space.w_ValueError, NON_HEX_MSG, i)
            bot = _hex_digit_to_int(hexstring[i+1])
            if bot == -1:
                raise oefmt(space.w_ValueError, NON_HEX_MSG, i + 1)
            data.append(chr(top*16 + bot))

        # in CPython bytearray.fromhex is a staticmethod, so
        # we ignore w_type and always return a bytearray
        return new_bytearray(space, space.w_bytearray, data)
开发者ID:abhinavthomas,项目名称:pypy,代码行数:26,代码来源:bytearrayobject.py


示例20: PyUnicode_FromEncodedObject

def PyUnicode_FromEncodedObject(space, w_obj, encoding, errors):
    """Coerce an encoded object obj to an Unicode object and return a reference with
    incremented refcount.

    String and other char buffer compatible objects are decoded according to the
    given encoding and using the error handling defined by errors.  Both can be
    NULL to have the interface use the default values (see the next section for
    details).

    All other objects, including Unicode objects, cause a TypeError to be
    set."""
    if not encoding:
        raise oefmt(space.w_TypeError, "decoding Unicode is not supported")
    w_encoding = space.wrap(rffi.charp2str(encoding))
    if errors:
        w_errors = space.wrap(rffi.charp2str(errors))
    else:
        w_errors = None

    # - unicode is disallowed
    # - raise TypeError for non-string types
    if space.isinstance_w(w_obj, space.w_unicode):
        w_meth = None
    else:
        try:
            w_meth = space.getattr(w_obj, space.wrap('decode'))
        except OperationError as e:
            if not e.match(space, space.w_AttributeError):
                raise
            w_meth = None
    if w_meth is None:
        raise oefmt(space.w_TypeError, "decoding Unicode is not supported")
    return space.call_function(w_meth, w_encoding, w_errors)
开发者ID:mozillazg,项目名称:pypy,代码行数:33,代码来源:unicodeobject.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python error.operationerrfmt函数代码示例发布时间:2022-05-27
下一篇:
Python baseobjspace.ObjSpace类代码示例发布时间: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