本文整理汇总了Python中pypy.interpreter.error.operationerrfmt函数的典型用法代码示例。如果您正苦于以下问题:Python operationerrfmt函数的具体用法?Python operationerrfmt怎么用?Python operationerrfmt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了operationerrfmt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: call
def call(self, space, args_w):
from pypy.module._rawffi.array import W_ArrayInstance
from pypy.module._rawffi.structure import W_StructureInstance
from pypy.module._rawffi.structure import W_Structure
argnum = len(args_w)
if argnum != len(self.argshapes):
msg = "Wrong number of arguments: expected %d, got %d"
raise operationerrfmt(space.w_TypeError, msg,
len(self.argshapes), argnum)
args_ll = []
for i in range(argnum):
argshape = self.argshapes[i]
w_arg = args_w[i]
if isinstance(argshape, W_Structure): # argument by value
arg = space.interp_w(W_StructureInstance, w_arg)
xsize, xalignment = size_alignment(self.ptr.argtypes[i])
if (arg.shape.size != xsize or
arg.shape.alignment != xalignment):
msg = ("Argument %d should be a structure of size %d and "
"alignment %d, "
"got instead size %d and alignment %d")
raise operationerrfmt(space.w_TypeError, msg, i+1,
xsize, xalignment, arg.shape.size,
arg.shape.alignment)
else:
arg = space.interp_w(W_ArrayInstance, w_arg)
if arg.length != 1:
msg = ("Argument %d should be an array of length 1, "
"got length %d")
raise operationerrfmt(space.w_TypeError, msg,
i+1, arg.length)
argletter = argshape.itemcode
letter = arg.shape.itemcode
if letter != argletter:
if not (argletter in TYPEMAP_PTR_LETTERS and
letter in TYPEMAP_PTR_LETTERS):
msg = "Argument %d should be typecode %s, got %s"
raise operationerrfmt(space.w_TypeError, msg,
i+1, argletter, letter)
args_ll.append(arg.ll_buffer)
# XXX we could avoid the intermediate list args_ll
try:
if self.resshape is not None:
result = self.resshape.allocate(space, 1, autofree=True)
self.ptr.call(args_ll, result.ll_buffer)
return space.wrap(result)
else:
self.ptr.call(args_ll, lltype.nullptr(rffi.VOIDP.TO))
return space.w_None
except StackCheckError, e:
raise OperationError(space.w_ValueError, space.wrap(e.message))
开发者ID:charred,项目名称:pypy,代码行数:52,代码来源:interp_rawffi.py
示例17: _missing_ffi_type
def _missing_ffi_type(self, cifbuilder, is_result_type):
space = self.space
if self.size < 0:
raise operationerrfmt(space.w_TypeError,
"ctype '%s' has incomplete type",
self.name)
if is_result_type:
place = "return value"
else:
place = "argument"
raise operationerrfmt(space.w_NotImplementedError,
"ctype '%s' (size %d) not supported as %s",
self.name, self.size, place)
开发者ID:charred,项目名称:pypy,代码行数:13,代码来源:ctypefunc.py
示例18: check_user_subclass
def check_user_subclass(w_self, w_subtype):
space = w_self.space
if not isinstance(w_subtype, W_TypeObject):
raise operationerrfmt(space.w_TypeError,
"X is not a type object ('%s')",
space.type(w_subtype).getname(space))
if not w_subtype.issubtype(w_self):
raise operationerrfmt(space.w_TypeError,
"%s.__new__(%s): %s is not a subtype of %s",
w_self.name, w_subtype.name, w_subtype.name, w_self.name)
if w_self.instancetypedef is not w_subtype.instancetypedef:
raise operationerrfmt(space.w_TypeError,
"%s.__new__(%s) is not safe, use %s.__new__()",
w_self.name, w_subtype.name, w_subtype.name)
return w_subtype
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:typeobject.py
示例19: check_user_subclass
def check_user_subclass(w_self, w_subtype):
space = w_self.space
if not isinstance(w_subtype, W_TypeObject):
raise operationerrfmt(space.w_TypeError,
"X is not a type object ('%T')",
w_subtype)
if not w_subtype.issubtype(w_self):
raise operationerrfmt(space.w_TypeError,
"%N.__new__(%N): %N is not a subtype of %N",
w_self, w_subtype, w_subtype, w_self)
if w_self.instancetypedef is not w_subtype.instancetypedef:
raise operationerrfmt(space.w_TypeError,
"%N.__new__(%N) is not safe, use %N.__new__()",
w_self, w_subtype, w_subtype)
return w_subtype
开发者ID:charred,项目名称:pypy,代码行数:15,代码来源:typeobject.py
示例20: _do_combine_starstarargs_wrapped
def _do_combine_starstarargs_wrapped(self, keys_w, w_starstararg):
space = self.space
keywords_w = [None] * len(keys_w)
keywords = [None] * len(keys_w)
i = 0
for w_key in keys_w:
try:
key = space.str_w(w_key)
except OperationError, e:
if e.match(space, space.w_TypeError):
raise OperationError(
space.w_TypeError,
space.wrap("keywords must be strings"))
if e.match(space, space.w_UnicodeEncodeError):
# Allow this to pass through
key = None
else:
raise
else:
if self.keywords and key in self.keywords:
raise operationerrfmt(self.space.w_TypeError,
"got multiple values "
"for keyword argument "
"'%s'", key)
keywords[i] = key
keywords_w[i] = space.getitem(w_starstararg, w_key)
i += 1
开发者ID:cshen,项目名称:pypy,代码行数:27,代码来源:argument.py
注:本文中的pypy.interpreter.error.operationerrfmt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论