from pypy.interpreter import gateway from pypy.interpreter.error import OperationError from pypy.objspace.std.stdtypedef import StdTypeDef, SMM from pypy.objspace.std.register_all import register_all from sys import maxint list_append = SMM('append', 2, doc='L.append(object) -- append object to end') list_insert = SMM('insert', 3, doc='L.insert(index, object) -- insert object before index') list_extend = SMM('extend', 2, doc='L.extend(iterable) -- extend list by appending' ' elements from the iterable') list_pop = SMM('pop', 2, defaults=(None,), doc='L.pop([index]) -> item -- remove and return item at' ' index (default last)') list_remove = SMM('remove', 2, doc='L.remove(value) -- remove first occurrence of value') list_index = SMM('index', 4, defaults=(0,maxint), doc='L.index(value, [start, [stop]]) -> integer -- return' ' first index of value') list_count = SMM('count', 2, doc='L.count(value) -> integer -- return number of' ' occurrences of value') list_reverse = SMM('reverse',1, doc='L.reverse() -- reverse *IN PLACE*') list_sort = SMM('sort', 4, defaults=(None, None, False), argnames=['cmp', 'key', 'reverse'], doc='L.sort(cmp=None, key=None, reverse=False) -- stable' ' sort *IN PLACE*;\ncmp(x, y) -> -1, 0, 1') list_reversed = SMM('__reversed__', 1,
from pypy.interpreter.error import OperationError from pypy.objspace.std.objspace import register_all from pypy.objspace.std.stdtypedef import StdTypeDef, newmethod from pypy.objspace.std.stdtypedef import SMM from pypy.interpreter.gateway import NoneNotWrapped from pypy.interpreter import gateway frozenset_copy = SMM('copy', 1, doc='Return a shallow copy of a set.') frozenset_difference = SMM('difference', 2, doc='Return the difference of two sets' ' as a new set.\n\n(i.e. all' ' elements that are in this set but' ' not the other.)') frozenset_intersection = SMM('intersection', 2, doc='Return the intersection of two sets' ' as a new set.\n\n(i.e. all' ' elements that are in both sets.)') frozenset_issubset = SMM('issubset', 2, doc='Report whether another set contains' ' this set.') frozenset_issuperset = SMM('issuperset', 2, doc='Report whether this set contains' ' another set.') frozenset_symmetric_difference = SMM('symmetric_difference', 2, doc='Return the symmetric difference of' ' two sets as a new set.\n\n(i.e.' ' all elements that are in exactly' ' one of the sets.)') frozenset_union = SMM('union', 2, doc='Return the union of two sets as a'
w_initializer = __args__.arguments_w[0] if space.type(w_initializer) is space.w_str: a.fromstring(space.str_w(w_initializer)) elif space.type(w_initializer) is space.w_list: a.fromlist(w_initializer) else: a.extend(w_initializer, True) break else: msg = 'bad typecode (must be c, b, B, u, h, H, i, I, l, L, f or d)' raise OperationError(space.w_ValueError, space.wrap(msg)) return a array_append = SMM('append', 2) array_extend = SMM('extend', 2) array_count = SMM('count', 2) array_index = SMM('index', 2) array_reverse = SMM('reverse', 1) array_remove = SMM('remove', 2) array_pop = SMM('pop', 2, defaults=(-1, )) array_insert = SMM('insert', 3) array_tolist = SMM('tolist', 1) array_fromlist = SMM('fromlist', 2) array_tostring = SMM('tostring', 1) array_fromstring = SMM('fromstring', 2) array_tounicode = SMM('tounicode', 1) array_fromunicode = SMM('fromunicode', 2)
space.w_str): return orig_obj return wrapstr(space, s[start:stop]) def joined2(space, str1, str2): if space.config.objspace.std.withstrbuf: from pypy.objspace.std.strbufobject import joined2 return joined2(str1, str2) else: return wrapstr(space, str1 + str2) str_join = SMM('join', 2, doc='S.join(sequence) -> string\n\nReturn a string which is' ' the concatenation of the strings in the\nsequence. ' ' The separator between elements is S.') str_split = SMM('split', 3, defaults=(None, -1), doc='S.split([sep [,maxsplit]]) -> list of strings\n\nReturn' ' a list of the words in the string S, using sep as' ' the\ndelimiter string. If maxsplit is given, at most' ' maxsplit\nsplits are done. If sep is not specified or' ' is None, any\nwhitespace string is a separator.') str_rsplit = SMM('rsplit', 3, defaults=(None, -1), doc='S.rsplit([sep [,maxsplit]]) -> list of' ' strings\n\nReturn a list of the words in the string S,'
import math import sys from rpython.rlib.unroll import unrolling_iterable from rpython.rlib import rfloat, rarithmetic from pypy.interpreter import typedef from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault,\ interpindirect2app from pypy.interpreter.error import OperationError from pypy.objspace.std.register_all import register_all from pypy.objspace.std.stdtypedef import StdTypeDef, SMM from pypy.objspace.std.model import W_Object from rpython.rlib.rbigint import rbigint from rpython.rlib.rstring import ParseStringError float_as_integer_ratio = SMM("as_integer_ratio", 1) float_is_integer = SMM("is_integer", 1) float_hex = SMM("hex", 1) def descr_conjugate(space, w_float): return space.float(w_float) register_all(vars(), globals()) @unwrap_spec(w_x=WrappedDefault(0.0)) def descr__new__(space, w_floattype, w_x): from pypy.objspace.std.floatobject import W_FloatObject w_value = w_x # 'x' is the keyword argument name in CPython if space.lookup(w_value, "__float__") is not None:
return W_SmallTupleObject3(list_w) if len(list_w) == 4: return W_SmallTupleObject4(list_w) if len(list_w) == 5: return W_SmallTupleObject5(list_w) if len(list_w) == 6: return W_SmallTupleObject6(list_w) if len(list_w) == 7: return W_SmallTupleObject7(list_w) if len(list_w) == 8: return W_SmallTupleObject8(list_w) return W_TupleObject(list_w) tuple_count = SMM("count", 2, 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)):
from pypy.interpreter import gateway from pypy.interpreter.error import OperationError from pypy.objspace.std.register_all import register_all from pypy.objspace.std.stdtypedef import StdTypeDef, SMM frozenset_copy = SMM('copy', 1, doc='Return a shallow copy of a set.') frozenset_difference = SMM('difference', 1, varargs_w=True, doc='Return a new set with elements in' ' the set that are not in the others.') frozenset_intersection = SMM('intersection', 1, varargs_w=True, doc='Return a new set with elements common' ' to the set and all others.') frozenset_issubset = SMM('issubset', 2, doc='Report whether another set contains' ' this set.') frozenset_issuperset = SMM('issuperset', 2, doc='Report whether this set contains' ' another set.') frozenset_symmetric_difference = SMM('symmetric_difference', 2, doc='Return the symmetric difference of' ' two sets as a new set.\n\n(i.e.' ' all elements that are in exactly' ' one of the sets.)') frozenset_union = SMM('union',
from pypy.interpreter.error import OperationError from pypy.interpreter.mixedmodule import MixedModule from pypy.interpreter import gateway from pypy.objspace.std.stdtypedef import StdTypeDef, SMM from pypy.objspace.std.register_all import register_all dict_copy = SMM('copy', 1, doc='D.copy() -> a shallow copy of D') dict_items = SMM('items', 1, doc="D.items() -> list of D's (key, value) pairs, as" ' 2-tuples') dict_keys = SMM('keys', 1, doc="D.keys() -> list of D's keys") dict_values = SMM('values', 1, doc="D.values() -> list of D's values") dict_has_key = SMM('has_key', 2, doc='D.has_key(k) -> True if D has a key k, else False') dict_clear = SMM('clear', 1, doc='D.clear() -> None. Remove all items from D.') dict_get = SMM('get', 3, defaults=(None, ), doc='D.get(k[,d]) -> D[k] if k in D, else d. d defaults' ' to None.') dict_pop = SMM('pop', 2, varargs_w=True, doc='D.pop(k[,d]) -> v, remove specified key and return' ' the corresponding value\nIf key is not found, d is' ' returned if given, otherwise KeyError is raised') dict_popitem = SMM('popitem',
from pypy.interpreter.error import OperationError from pypy.objspace.std.register_all import register_all from pypy.objspace.std.stdtypedef import StdTypeDef, SMM from pypy.objspace.std.stringtype import ( str_decode, str_count, str_index, str_rindex, str_find, str_rfind, str_replace, str_startswith, str_endswith, str_islower, str_isupper, str_isalpha, str_isalnum, str_isdigit, str_isspace, str_istitle, str_upper, str_lower, str_title, str_swapcase, str_capitalize, str_expandtabs, str_ljust, str_rjust, str_center, str_zfill, str_join, str_split, str_rsplit, str_partition, str_rpartition, str_splitlines, str_translate) from pypy.objspace.std.listtype import (list_append, list_extend) bytearray_insert = SMM('insert', 3, doc="B.insert(index, int) -> None\n\n" "Insert a single item into the bytearray before " "the given index.") bytearray_pop = SMM('pop', 2, defaults=(-1, ), doc="B.pop([index]) -> int\n\nRemove and return a " "single item from B. If no index\nargument is given, " "will pop the last value.") bytearray_remove = SMM('remove', 2, doc="B.remove(int) -> None\n\n" "Remove the first occurance of a value in B.")
from pypy.interpreter.error import OperationError from pypy.objspace.std.objspace import register_all from pypy.objspace.std.stdtypedef import StdTypeDef, newmethod, no_hash_descr from pypy.objspace.std.stdtypedef import SMM from pypy.interpreter.gateway import NoneNotWrapped from pypy.interpreter import gateway set_add = SMM('add', 2, doc='Add an element to a set.\n\nThis' ' has no effect if the element is' ' already present.') set_clear = SMM('clear', 1, doc='Remove all elements from this set.') set_copy = SMM('copy', 1, doc='Return a shallow copy of a set.') set_difference = SMM('difference', 2, doc='Return the difference of two sets' ' as a new set.\n\n(i.e. all' ' elements that are in this set but' ' not the other.)') set_difference_update = SMM('difference_update', 2, doc='Remove all elements of another set' ' from this set.') set_discard = SMM('discard', 2, doc='Remove an element from a set if it' ' is a member.\n\nIf the element is' ' not a member, do nothing.') set_intersection = SMM('intersection', 2,
from pypy.interpreter import baseobjspace, gateway from pypy.interpreter.typedef import GetSetProperty from pypy.objspace.std.stdtypedef import StdTypeDef, SMM from pypy.objspace.std.register_all import register_all from pypy.interpreter.error import OperationError from pypy.rlib.objectmodel import specialize # indices multimehtod slice_indices = SMM('indices', 2, doc='S.indices(len) -> (start, stop, stride)\n\nAssuming a' ' sequence of length len, calculate the start and' ' stop\nindices, and the stride length of the extended' ' slice described by\nS. Out of bounds indices are' ' clipped in a manner consistent with the\nhandling of' ' normal slices.') # utility functions def _eval_slice_index(space, w_int): # note that it is the *callers* responsibility to check for w_None # otherwise you can get funny error messages try: return space.getindex_w(w_int, None) # clamp if long integer too large except OperationError, err: if not err.match(space, space.w_TypeError): raise raise OperationError( space.w_TypeError, space.wrap("slice indices must be integers or " "None or have an __index__ method"))
except UnicodeDecodeError: for i in range(len(s)): if ord(s[i]) > 127: raise OperationError( space.w_UnicodeDecodeError, space.newtuple([ space.wrap('ascii'), space.wrap(s), space.wrap(i), space.wrap(i+1), space.wrap("ordinal not in range(128)")])) assert False, "unreachable" unicode_capitalize = SMM('capitalize', 1, doc='S.capitalize() -> unicode\n\nReturn a' ' capitalized version of S, i.e. make the first' ' character\nhave upper case.') unicode_center = SMM('center', 3, defaults=(' ',), doc='S.center(width[, fillchar]) -> unicode\n\nReturn' ' S centered in a Unicode string of length width.' ' Padding is\ndone using the specified fill' ' character (default is a space)') unicode_count = SMM('count', 4, defaults=(0, maxint), doc='S.count(sub[, start[, end]]) -> int\n\nReturn' ' the number of occurrences of substring sub in' ' Unicode string\nS[start:end]. Optional' ' arguments start and end are\ninterpreted as in' ' slice notation.') unicode_encode = SMM('encode', 3, defaults=(None, None), argnames=['encoding', 'errors'], doc='S.encode([encoding[,errors]]) -> string or'
from pypy.interpreter.error import OperationError from pypy.interpreter import gateway from pypy.objspace.std.register_all import register_all from pypy.objspace.std.stdtypedef import StdTypeDef, SMM set_add = SMM('add', 2, doc='Add an element to a set.\n\nThis' ' has no effect if the element is' ' already present.') set_clear = SMM('clear', 1, doc='Remove all elements from this set.') set_copy = SMM('copy', 1, doc='Return a shallow copy of a set.') set_difference = SMM('difference', 1, varargs_w=True, doc='Return a new set with elements in' ' the set that are not in the others.') set_difference_update = SMM('difference_update', 1, varargs_w=True, doc='Update the set, removing elements' ' found in others.') set_discard = SMM('discard', 2, doc='Remove an element from a set if it' ' is a member.\n\nIf the element is' ' not a member, do nothing.') set_intersection = SMM('intersection', 1, varargs_w=True, doc='Return a new set with elements common' ' to the set and all others.') set_intersection_update = SMM('intersection_update', 1, varargs_w=True, doc='Update the set, keeping only elements' ' found in it and all others.') set_issubset = SMM('issubset', 2, doc='Report whether another set contains'