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


Python error.operationerrfmt函数代码示例

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


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

示例1: seek_w

    def seek_w(self, space, pos, mode=0):
        self._check_closed(space)

        if not 0 <= mode <= 2:
            raise operationerrfmt(space.w_ValueError,
                "Invalid whence (%d, should be 0, 1 or 2)", mode
            )
        elif mode == 0 and pos < 0:
            raise operationerrfmt(space.w_ValueError,
                "negative seek position: %d", pos
            )
        elif mode != 0 and pos != 0:
            raise OperationError(space.w_IOError,
                space.wrap("Can't do nonzero cur-relative seeks")
            )

        # XXX: this makes almost no sense, but its how CPython does it.
        if mode == 1:
            pos = self.pos
        elif mode == 2:
            pos = len(self.buf)

        assert pos >= 0
        self.pos = pos
        return space.wrap(pos)
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:interp_stringio.py

示例2: _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 operationerrfmt(
                    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 operationerrfmt(
                    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:charred,项目名称:pypy,代码行数:33,代码来源:interp_funcptr.py

示例3: readline_w

    def readline_w(self, space, w_limit=None):
        # For backwards compatibility, a (slowish) readline().
        limit = convert_size(space, w_limit)

        old_size = -1

        has_peek = space.findattr(self, space.wrap("peek"))

        builder = StringBuilder()
        size = 0

        while limit < 0 or size < limit:
            nreadahead = 1

            if has_peek:
                w_readahead = space.call_method(self, "peek", space.wrap(1))
                if not space.isinstance_w(w_readahead, space.w_str):
                    raise operationerrfmt(
                        space.w_IOError,
                        "peek() should have returned a bytes object, " "not '%s'",
                        space.type(w_readahead).getname(space),
                    )
                length = space.len_w(w_readahead)
                if length > 0:
                    n = 0
                    buf = space.str_w(w_readahead)
                    if limit >= 0:
                        while True:
                            if n >= length or n >= limit:
                                break
                            n += 1
                            if buf[n - 1] == "\n":
                                break
                    else:
                        while True:
                            if n >= length:
                                break
                            n += 1
                            if buf[n - 1] == "\n":
                                break
                    nreadahead = n

            w_read = space.call_method(self, "read", space.wrap(nreadahead))
            if not space.isinstance_w(w_read, space.w_str):
                raise operationerrfmt(
                    space.w_IOError,
                    "peek() should have returned a bytes object, " "not '%s'",
                    space.type(w_read).getname(space),
                )
            read = space.str_w(w_read)
            if not read:
                break

            size += len(read)
            builder.append(read)

            if read[-1] == "\n":
                break

        return space.wrap(builder.build())
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:60,代码来源:interp_iobase.py

示例4: reload

def reload(space, w_module):
    """Reload the module.
    The module must have been successfully imported before."""
    if not space.is_w(space.type(w_module), space.type(space.sys)):
        raise OperationError(
            space.w_TypeError,
            space.wrap("reload() argument must be module"))

    w_modulename = space.getattr(w_module, space.wrap("__name__"))
    modulename = space.str0_w(w_modulename)
    if not space.is_w(check_sys_modules(space, w_modulename), w_module):
        raise operationerrfmt(
            space.w_ImportError,
            "reload(): module %s not in sys.modules", modulename)

    try:
        w_mod = space.reloading_modules[modulename]
        # Due to a recursive reload, this module is already being reloaded.
        return w_mod
    except KeyError:
        pass

    space.reloading_modules[modulename] = w_module
    try:
        namepath = modulename.split('.')
        subname = namepath[-1]
        parent_name = '.'.join(namepath[:-1])
        parent = None
        if parent_name:
            w_parent = check_sys_modules_w(space, parent_name)
            if w_parent is None:
                raise operationerrfmt(
                    space.w_ImportError,
                    "reload(): parent %s not in sys.modules",
                    parent_name)
            w_path = space.getattr(w_parent, space.wrap("__path__"))
        else:
            w_path = None

        find_info = find_module(
            space, modulename, w_modulename, subname, w_path)

        if not find_info:
            # ImportError
            msg = "No module named %s"
            raise operationerrfmt(space.w_ImportError, msg, modulename)

        try:
            try:
                return load_module(space, w_modulename, find_info, reuse=True)
            finally:
                if find_info.stream:
                    find_info.stream.close()
        except:
            # load_module probably removed name from modules because of
            # the error.  Put back the original module object.
            space.sys.setmodule(w_module)
            raise
    finally:
        del space.reloading_modules[modulename]
开发者ID:MichaelBlume,项目名称:pypy,代码行数:60,代码来源:importing.py

示例5: 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:
        msg = "set_param() takes at most 1 non-keyword argument, %d given"
        raise operationerrfmt(space.w_TypeError, msg, 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 operationerrfmt(space.w_TypeError,
                                      "no JIT parameter '%s'", key)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:interp_jit.py

示例6: ParserCreate

def ParserCreate(space, w_encoding=None, w_namespace_separator=None,
                 w_intern=None):
    """ParserCreate([encoding[, namespace_separator]]) -> parser
Return a new XML parser object."""
    if space.is_none(w_encoding):
        encoding = None
    elif space.isinstance_w(w_encoding, space.w_str):
        encoding = space.str_w(w_encoding)
    else:
        raise operationerrfmt(
            space.w_TypeError,
            'ParserCreate() argument 1 must be string or None, not %T',
            w_encoding)

    if space.is_none(w_namespace_separator):
        namespace_separator = 0
    elif space.isinstance_w(w_namespace_separator, space.w_str):
        separator = space.str_w(w_namespace_separator)
        if len(separator) == 0:
            namespace_separator = 0
        elif len(separator) == 1:
            namespace_separator = ord(separator[0])
        else:
            raise OperationError(
                space.w_ValueError,
                space.wrap('namespace_separator must be at most one character,'
                           ' omitted, or None'))
    else:
        raise operationerrfmt(
            space.w_TypeError,
            'ParserCreate() argument 2 must be string or None, not %T',
            w_namespace_separator)

    # Explicitly passing None means no interning is desired.
    # Not passing anything means that a new dictionary is used.
    if w_intern is None:
        w_intern = space.newdict()
    elif space.is_w(w_intern, space.w_None):
        w_intern = None

    if namespace_separator:
        xmlparser = XML_ParserCreateNS(
            encoding,
            rffi.cast(rffi.CHAR, namespace_separator))
    else:
        xmlparser = XML_ParserCreate(encoding)
    # Currently this is just the size of the pointer and some estimated bytes.
    # The struct isn't actually defined in expat.h - it is in xmlparse.c
    # XXX: find a good estimate of the XML_ParserStruct
    rgc.add_memory_pressure(XML_Parser_SIZE + 300)
    if not xmlparser:
        raise OperationError(space.w_RuntimeError,
                             space.wrap('XML_ParserCreate failed'))

    parser = W_XMLParserType(space, xmlparser, w_intern)
    XML_SetUnknownEncodingHandler(
        parser.itself, UnknownEncodingHandlerData_callback,
        rffi.cast(rffi.VOIDP, parser.id))
    return space.wrap(parser)
开发者ID:charred,项目名称:pypy,代码行数:59,代码来源:interp_pyexpat.py

示例7: test_operationerrfmt_R

def test_operationerrfmt_R(space):
    operr = operationerrfmt(space.w_ValueError, "illegal newline value: %R",
                            space.wrap('foo'))
    assert operr._compute_value(space) == "illegal newline value: 'foo'"
    operr = operationerrfmt(space.w_ValueError, "illegal newline value: %R",
                            space.wrap("'PyLadies'"))
    expected = "illegal newline value: \"'PyLadies'\""
    assert operr._compute_value(space) == expected
开发者ID:charred,项目名称:pypy,代码行数:8,代码来源:test_error.py

示例8: raiseattrerror

def raiseattrerror(space, w_obj, name, w_descr=None):
    if w_descr is None:
        raise operationerrfmt(space.w_AttributeError,
                              "'%T' object has no attribute '%s'",
                              w_obj, name)
    else:
        raise operationerrfmt(space.w_AttributeError,
                              "'%T' object attribute '%s' is read-only",
                              w_obj, name)
开发者ID:charred,项目名称:pypy,代码行数:9,代码来源:descroperation.py

示例9: test_operationerrfmt_T

def test_operationerrfmt_T(space):
    operr = operationerrfmt(space.w_AttributeError,
                            "'%T' object has no attribute '%s'",
                            space.wrap('foo'), 'foo')
    assert operr._compute_value(space) == "'str' object has no attribute 'foo'"
    operr = operationerrfmt("w_type",
                            "'%T' object has no attribute '%s'",
                            space.wrap('foo'), 'foo')
    assert operr._compute_value(space) == "'str' object has no attribute 'foo'"
开发者ID:charred,项目名称:pypy,代码行数:9,代码来源:test_error.py

示例10: getindex

 def getindex(self, space, item):
     if item >= self.size:
         raise operationerrfmt(space.w_IndexError,
           '%d above array size', item)
     if item < 0:
         item += self.size
     if item < 0:
         raise operationerrfmt(space.w_IndexError,
           '%d below zero', item)
     return item
开发者ID:ieure,项目名称:pypy,代码行数:10,代码来源:interp_numarray.py

示例11: descr_delattr

 def descr_delattr(self, space, w_attr):
     name = unwrap_attr(space, w_attr)
     if name in ("__dict__", "__name__", "__bases__"):
         raise operationerrfmt(space.w_TypeError, "cannot delete attribute '%s'", name)
     try:
         space.delitem(self.w_dict, w_attr)
     except OperationError, e:
         if not e.match(space, space.w_KeyError):
             raise
         raise operationerrfmt(space.w_AttributeError, "class %s has no attribute '%s'", self.name, name)
开发者ID:pombredanne,项目名称:pypy,代码行数:10,代码来源:interp_classobj.py

示例12: get_method

def get_method(space, b_type, name, b_paramtypes):
    try:
        method = b_type.GetMethod(name, b_paramtypes)
    except AmbiguousMatchException:
        msg = 'Multiple overloads for %s could match'
        raise operationerrfmt(space.w_TypeError, msg, name)
    if method is None:
        msg = 'No overloads for %s could match'
        raise operationerrfmt(space.w_TypeError, msg, name)
    return method
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:interp_clr.py

示例13: test_operationerrfmt

def test_operationerrfmt():
    operr = operationerrfmt("w_type", "abc %s def %d", "foo", 42)
    assert isinstance(operr, OperationError)
    assert operr.w_type == "w_type"
    assert operr._w_value is None
    assert operr._compute_value() == "abc foo def 42"
    operr2 = operationerrfmt("w_type2", "a %s b %d c", "bar", 43)
    assert operr2.__class__ is operr.__class__
    operr3 = operationerrfmt("w_type2", "a %s b %s c", "bar", "4b")
    assert operr3.__class__ is not operr.__class__
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_error.py

示例14: _convert_error

 def _convert_error(self, expected, w_got):
     space = self.space
     if isinstance(w_got, cdataobj.W_CData):
         return operationerrfmt(space.w_TypeError,
                                "initializer for ctype '%s' must be a %s, "
                                "not cdata '%s'", self.name, expected,
                                w_got.ctype.name)
     else:
         return operationerrfmt(space.w_TypeError,
                                "initializer for ctype '%s' must be a %s, "
                                "not %T", self.name, expected, w_got)
开发者ID:charred,项目名称:pypy,代码行数:11,代码来源:ctypeobj.py

示例15: format

 def format(space, w_obj, w_format_spec):
     w_descr = space.lookup(w_obj, '__format__')
     if w_descr is None:
         raise operationerrfmt(space.w_TypeError,
                               "'%T' object does not define __format__",
                               w_obj)
     w_res = space.get_and_call_function(w_descr, w_obj, w_format_spec)
     if not space.isinstance_w(w_res, space.w_basestring):
         msg = "%T.__format__ must return string or unicode, not %T"
         raise operationerrfmt(space.w_TypeError, msg, w_obj, w_res)
     return w_res
开发者ID:charred,项目名称:pypy,代码行数:11,代码来源:descroperation.py


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