本文整理汇总了Python中pypy.objspace.std.stdtypedef.StdTypeDef类的典型用法代码示例。如果您正苦于以下问题:Python StdTypeDef类的具体用法?Python StdTypeDef怎么用?Python StdTypeDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StdTypeDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: descr_get_imag
def descr_get_imag(space, w_obj):
return space.newlong(0)
def bit_length(space, w_obj):
bigint = space.bigint_w(w_obj)
try:
return space.wrap(bigint.bit_length())
except OverflowError:
raise OperationError(space.w_OverflowError,
space.wrap("too many digits in integer"))
# ____________________________________________________________
long_typedef = StdTypeDef("long",
__doc__ = '''long(x[, base]) -> integer
Convert a string or number to a long integer, if possible. A floating
point argument will be truncated towards zero (this does not include a
string representation of a floating point number!) When converting a
string, use the optional base. It is an error to supply a base when
converting a non-string.''',
__new__ = gateway.interp2app(descr__new__),
conjugate = gateway.interp2app(descr_conjugate),
numerator = typedef.GetSetProperty(descr_get_numerator),
denominator = typedef.GetSetProperty(descr_get_denominator),
real = typedef.GetSetProperty(descr_get_real),
imag = typedef.GetSetProperty(descr_get_imag),
bit_length = gateway.interp2app(bit_length),
)
long_typedef.registermethods(globals())
示例2: WrappedDefault
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.inttype import int_typedef
@unwrap_spec(w_obj = WrappedDefault(False))
def descr__new__(space, w_booltype, w_obj):
space.w_bool.check_user_subclass(w_booltype)
if space.is_true(w_obj):
return space.w_True
else:
return space.w_False
# ____________________________________________________________
bool_typedef = StdTypeDef("bool", int_typedef,
__doc__ = '''bool(x) -> bool
Returns True when the argument x is true, False otherwise.
The builtins True and False are the only two instances of the class bool.
The class bool is a subclass of the class int, and cannot be subclassed.''',
__new__ = interp2app(descr__new__),
)
bool_typedef.acceptable_as_base_class = False
示例3: list_reversed__ANY
' the list')
def list_reversed__ANY(space, w_list):
from pypy.objspace.std.iterobject import W_ReverseSeqIterObject
return W_ReverseSeqIterObject(space, w_list, -1)
register_all(vars(), globals())
# ____________________________________________________________
def descr__new__(space, w_listtype, __args__):
from pypy.objspace.std.listobject import W_ListObject
w_obj = space.allocate_instance(W_ListObject, w_listtype)
w_obj.clear(space)
return w_obj
# ____________________________________________________________
list_typedef = StdTypeDef("list",
__doc__ = '''list() -> new list
list(sequence) -> new list initialized from sequence's items''',
__new__ = gateway.interp2app(descr__new__),
__hash__ = None,
)
list_typedef.registermethods(globals())
# ____________________________________________________________
def get_list_index(space, w_index):
return space.getindex_w(w_index, space.w_IndexError, "list index")
示例4: SMM
' one of the sets.)')
frozenset_union = SMM('union', 2,
doc='Return the union of two sets as a'
' new set.\n\n(i.e. all elements'
' that are in either set.)')
frozenset_reduce = SMM('__reduce__',1,
doc='Return state information for'
' pickling.')
register_all(vars(), globals())
def descr__frozenset__new__(space, w_frozensettype, w_iterable=NoneNotWrapped):
from pypy.objspace.std.setobject import W_FrozensetObject
from pypy.objspace.std.setobject import _is_frozenset_exact
if _is_frozenset_exact(w_iterable):
return w_iterable
w_obj = space.allocate_instance(W_FrozensetObject, w_frozensettype)
W_FrozensetObject.__init__(w_obj, space, None)
return w_obj
frozenset_typedef = StdTypeDef("frozenset",
__doc__ = """frozenset(iterable) --> frozenset object
Build an immutable unordered collection.""",
__new__ = newmethod(descr__frozenset__new__),
)
frozenset_typedef.custom_hash = True
frozenset_typedef.registermethods(globals())
示例5: descr__new__
def descr__new__(space, w_dicttype, __args__):
from pypy.objspace.std.dictmultiobject import W_DictMultiObject
w_obj = W_DictMultiObject.allocate_and_init_instance(space, w_dicttype)
return w_obj
# ____________________________________________________________
dict_typedef = StdTypeDef("dict",
__doc__ = '''dict() -> new empty dictionary.
dict(mapping) -> new dictionary initialized from a mapping object\'s
(key, value) pairs.
dict(seq) -> new dictionary initialized as if via:
d = {}
for k, v in seq:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)''',
__new__ = gateway.interp2app(descr__new__),
__hash__ = None,
__repr__ = gateway.interp2app(descr_repr),
fromkeys = gateway.interp2app(descr_fromkeys, as_classmethod=True),
)
dict_typedef.registermethods(globals())
# ____________________________________________________________
def descr_dictiter__reduce__(w_self, space):
"""
This is a slightly special case of pickling.
Since iteration over a dict is a bit hairy,
示例6: SMM
frozenset_reduce = SMM('__reduce__',1,
doc='Return state information for'
' pickling.')
# 2.6 methods
frozenset_isdisjoint = SMM('isdisjoint', 2,
doc='Return True if two sets have a'
' null intersection.')
register_all(vars(), globals())
def descr__frozenset__new__(space, w_frozensettype,
w_iterable=gateway.NoneNotWrapped):
from pypy.objspace.std.setobject import W_FrozensetObject
from pypy.objspace.std.setobject import make_setdata_from_w_iterable
if (space.is_w(w_frozensettype, space.w_frozenset) and
w_iterable is not None and type(w_iterable) is W_FrozensetObject):
return w_iterable
w_obj = space.allocate_instance(W_FrozensetObject, w_frozensettype)
data = make_setdata_from_w_iterable(space, w_iterable)
W_FrozensetObject.__init__(w_obj, space, data)
return w_obj
frozenset_typedef = StdTypeDef("frozenset",
__doc__ = """frozenset(iterable) --> frozenset object
Build an immutable unordered collection.""",
__new__ = gateway.interp2app(descr__frozenset__new__),
)
frozenset_typedef.registermethods(globals())
示例7: SMM
doc="count(obj) -> number of times obj appears in the tuple")
tuple_index = SMM("index", 4, defaults=(0, sys.maxint),
doc="index(obj, [start, [stop]]) -> first index that obj "
"appears in the tuple")
def descr__new__(space, w_tupletype, w_sequence=gateway.NoneNotWrapped):
from pypy.objspace.std.tupleobject import W_TupleObject
if w_sequence is None:
tuple_w = []
elif (space.is_w(w_tupletype, space.w_tuple) and
space.is_w(space.type(w_sequence), space.w_tuple)):
return w_sequence
else:
tuple_w = space.fixedview(w_sequence)
w_obj = space.allocate_instance(W_TupleObject, w_tupletype)
W_TupleObject.__init__(w_obj, tuple_w)
return w_obj
# ____________________________________________________________
tuple_typedef = StdTypeDef("tuple",
__doc__ = '''tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items
If the argument is a tuple, the return value is the same object.''',
__new__ = gateway.interp2app(descr__new__),
)
tuple_typedef.registermethods(globals())
示例8: slicewprop
space.newtuple([w_self.w_start,
w_self.w_stop,
w_self.w_step]),
])
# ____________________________________________________________
def slicewprop(name):
def fget(space, w_obj):
from pypy.objspace.std.sliceobject import W_SliceObject
if not isinstance(w_obj, W_SliceObject):
raise OperationError(space.w_TypeError,
space.wrap("descriptor is for 'slice'"))
return getattr(w_obj, name)
return GetSetProperty(fget)
slice_typedef = StdTypeDef("slice",
__doc__ = '''slice([start,] stop[, step])
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).''',
__new__ = gateway.interp2app(descr__new__),
__hash__ = None,
__reduce__ = gateway.interp2app(descr__reduce__),
start = slicewprop('w_start'),
stop = slicewprop('w_stop'),
step = slicewprop('w_step'),
)
slice_typedef.acceptable_as_base_class = False
slice_typedef.registermethods(globals())
示例9: isinstance
"""
from pypy.objspace.std.iterobject import W_ReverseSeqIterObject
assert isinstance(w_self, W_ReverseSeqIterObject)
from pypy.interpreter.mixedmodule import MixedModule
w_mod = space.getbuiltinmodule("_pickle_support")
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get("reverseseqiter_new")
tup = [w_self.w_seq, space.wrap(w_self.index)]
return space.newtuple([new_inst, space.newtuple(tup)])
# ____________________________________________________________
iter_typedef = StdTypeDef(
"sequenceiterator",
__doc__="""iter(collection) -> iterator
iter(callable, sentinel) -> iterator
Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.""",
__reduce__=gateway.interp2app(descr_seqiter__reduce__),
)
iter_typedef.acceptable_as_base_class = False
reverse_iter_typedef = StdTypeDef(
"reversesequenceiterator", __reduce__=gateway.interp2app(descr_reverseseqiter__reduce__)
)
reverse_iter_typedef.acceptable_as_base_class = False
示例10: isinstance
encoding, errors)
if space.is_w(w_unicodetype, space.w_unicode):
return w_value
if space.config.objspace.std.withropeunicode:
assert isinstance(w_value, W_RopeUnicodeObject)
w_newobj = space.allocate_instance(W_RopeUnicodeObject, w_unicodetype)
W_RopeUnicodeObject.__init__(w_newobj, w_value._node)
return w_newobj
assert isinstance(w_value, W_UnicodeObject)
w_newobj = space.allocate_instance(W_UnicodeObject, w_unicodetype)
W_UnicodeObject.__init__(w_newobj, w_value._value)
return w_newobj
# ____________________________________________________________
unicode_typedef = StdTypeDef("unicode", basestring_typedef,
__new__ = gateway.interp2app(descr_new_),
__doc__ = '''unicode(string [, encoding[, errors]]) -> object
Create a new Unicode object from the given encoded string.
encoding defaults to the current default string encoding.
errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.'''
)
unicode_typedef.registermethods(globals())
unitypedef = unicode_typedef
register_all(vars(), globals())
示例11: StdTypeDef
w_obj = space.allocate_instance(W_RopeObject, w_stringtype)
W_RopeObject.__init__(w_obj, rope.LiteralStringNode(value))
return w_obj
else:
w_obj = space.allocate_instance(W_StringObject, w_stringtype)
W_StringObject.__init__(w_obj, value)
return w_obj
# ____________________________________________________________
str_typedef = StdTypeDef(
"str",
basestring_typedef,
__new__=gateway.interp2app(descr__new__),
__doc__="""str(object) -> string
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.""",
)
str_typedef.registermethods(globals())
# ____________________________________________________________
# Helpers for several string implementations
@specialize.argtype(0)
def stringendswith(u_self, suffix, start, end):
begin = end - len(suffix)
示例12: OperationError
while i < length and s[i].isspace():
i += 1
if i != length:
raise OperationError(space.w_ValueError,
space.wrap("invalid hex string"))
w_float = space.wrap(sign * value)
return space.call_function(w_cls, w_float)
def descr_get_real(space, w_obj):
return space.float(w_obj)
def descr_get_imag(space, w_obj):
return space.wrap(0.0)
# ____________________________________________________________
float_typedef = StdTypeDef("float",
__doc__ = '''float(x) -> floating point number
Convert a string or number to a floating point number, if possible.''',
__new__ = gateway.interp2app(descr__new__),
__getformat__ = gateway.interp2app(descr___getformat__,
as_classmethod=True),
fromhex = gateway.interp2app(descr_fromhex,
as_classmethod=True),
conjugate = gateway.interp2app(descr_conjugate),
real = typedef.GetSetProperty(descr_get_real),
imag = typedef.GetSetProperty(descr_get_imag),
)
float_typedef.registermethods(globals())
示例13: return
return (space.float_w(space.float(w_complex)), 0.0)
def complexwprop(name):
def fget(space, w_obj):
from pypy.objspace.std.complexobject import W_ComplexObject
if not isinstance(w_obj, W_ComplexObject):
raise OperationError(space.w_TypeError,
space.wrap("descriptor is for 'complex'"))
return space.newfloat(getattr(w_obj, name))
return GetSetProperty(fget)
def descr___getnewargs__(space, w_self):
from pypy.objspace.std.complexobject import W_ComplexObject
assert isinstance(w_self, W_ComplexObject)
return space.newtuple([space.newfloat(w_self.realval),
space.newfloat(w_self.imagval)])
complex_typedef = StdTypeDef("complex",
__doc__ = """complex(real[, imag]) -> complex number
Create a complex number from a real part and an optional imaginary part.
This is equivalent to (real + imag*1j) where imag defaults to 0.""",
__new__ = interp2app(descr__new__),
__getnewargs__ = interp2app(descr___getnewargs__),
real = complexwprop('realval'),
imag = complexwprop('imagval'),
)
complex_typedef.registermethods(globals())
示例14: OperationError
raise OperationError(space.w_ValueError, space.wrap(
"non-hexadecimal number found in fromhex() arg at position %d" % i))
top = _hex_digit_to_int(hexstring[i])
if top == -1:
raise OperationError(space.w_ValueError, space.wrap(
"non-hexadecimal number found in fromhex() arg at position %d" % i))
bot = _hex_digit_to_int(hexstring[i+1])
if bot == -1:
raise OperationError(space.w_ValueError, space.wrap(
"non-hexadecimal number found in fromhex() arg at position %d" % (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)
# ____________________________________________________________
bytearray_typedef = StdTypeDef("bytearray",
__doc__ = '''bytearray() -> an empty bytearray
bytearray(sequence) -> bytearray initialized from sequence\'s items
If the argument is a bytearray, the return value is the same object.''',
__new__ = gateway.interp2app(descr__new__),
__hash__ = None,
__reduce__ = gateway.interp2app(descr_bytearray__reduce__),
fromhex = gateway.interp2app(descr_fromhex, as_classmethod=True)
)
bytearray_typedef.registermethods(globals())
示例15: complexwprop
W_ComplexObject.__init__(w_obj, realval, imagval)
return w_obj
def complexwprop(name):
def fget(space, w_obj):
from pypy.objspace.std.complexobject import W_ComplexObject
if not isinstance(w_obj, W_ComplexObject):
raise OperationError(space.w_TypeError,
space.wrap("descriptor is for 'complex'"))
return space.newfloat(getattr(w_obj, name))
return GetSetProperty(fget)
def descr___getnewargs__(space, w_self):
from pypy.objspace.std.complexobject import W_ComplexObject
assert isinstance(w_self, W_ComplexObject)
return space.newtuple([space.newcomplex(w_self.realval,w_self.imagval)])
complex_typedef = StdTypeDef("complex",
__doc__ = """complex(real[, imag]) -> complex number
Create a complex number from a real part and an optional imaginary part.
This is equivalent to (real + imag*1j) where imag defaults to 0.""",
__new__ = newmethod(descr__new__),
__getnewargs__ = newmethod(descr___getnewargs__),
real = complexwprop('realval'),
imag = complexwprop('imagval'),
)
complex_typedef.custom_hash = True
complex_typedef.registermethods(globals())