| 1 |
from pypy.interpreter.error import OperationError, oefmt |
| 2 |
from pypy.interpreter.gateway import unwrap_spec |
| 3 |
|
| 4 |
|
| 5 |
def index(space, w_a): |
| 6 |
return space.index(w_a) |
| 7 |
|
| 8 |
def abs(space, w_obj): |
| 9 |
'abs(a) -- Same as abs(a).' |
| 10 |
return space.abs(w_obj) |
| 11 |
|
| 12 |
def add(space, w_obj1, w_obj2): |
| 13 |
'add(a, b) -- Same as a + b' |
| 14 |
return space.add(w_obj1, w_obj2) |
| 15 |
|
| 16 |
def and_(space, w_obj1, w_obj2): |
| 17 |
'and_(a, b) -- Same as a & b' |
| 18 |
return space.and_(w_obj1, w_obj2) |
| 19 |
|
| 20 |
def concat(space, w_obj1, w_obj2): |
| 21 |
'concat(a, b) -- Same as a + b, for a and b sequences.' |
| 22 |
if (space.lookup(w_obj1, '__getitem__') is None or |
| 23 |
space.lookup(w_obj2, '__getitem__') is None): |
| 24 |
raise OperationError(space.w_TypeError, space.w_None) |
| 25 |
|
| 26 |
return space.add(w_obj1, w_obj2) |
| 27 |
|
| 28 |
def contains(space, w_obj1, w_obj2): |
| 29 |
'contains(a, b) -- Same as b in a (note reversed operands).' |
| 30 |
return space.contains(w_obj1, w_obj2) |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
def delitem(space, w_obj, w_key): |
| 35 |
'delitem(a,b) -- Same as del a[b]' |
| 36 |
space.delitem(w_obj, w_key) |
| 37 |
|
| 38 |
def eq(space, w_a, w_b): |
| 39 |
'eq(a, b) -- Same as a==b' |
| 40 |
return space.eq(w_a, w_b) |
| 41 |
|
| 42 |
def floordiv(space, w_a, w_b): |
| 43 |
'floordiv(a, b) -- Same as a // b.' |
| 44 |
return space.floordiv(w_a, w_b) |
| 45 |
|
| 46 |
def ge(space, w_a, w_b): |
| 47 |
'ge(a, b) -- Same as a>=b.' |
| 48 |
return space.ge(w_a, w_b) |
| 49 |
|
| 50 |
def getitem(space, w_a, w_b): |
| 51 |
'getitem(a, b) -- Same as a[b].' |
| 52 |
return space.getitem(w_a, w_b) |
| 53 |
|
| 54 |
def gt(space, w_a, w_b): |
| 55 |
'gt(a, b) -- Same as a>b.' |
| 56 |
return space.gt(w_a, w_b) |
| 57 |
|
| 58 |
def indexOf(space, w_a, w_b): |
| 59 |
'indexOf(a, b) -- Return the first index of b in a.' |
| 60 |
return space.sequence_index(w_a, w_b) |
| 61 |
|
| 62 |
def inv(space, w_obj,): |
| 63 |
'inv(a) -- Same as ~a.' |
| 64 |
return space.invert(w_obj) |
| 65 |
|
| 66 |
def invert(space, w_obj,): |
| 67 |
'invert(a) -- Same as ~a.' |
| 68 |
return space.invert(w_obj) |
| 69 |
|
| 70 |
def is_(space, w_a, w_b): |
| 71 |
'is_(a,b) -- Same as a is b' |
| 72 |
return space.is_(w_a, w_b) |
| 73 |
|
| 74 |
def is_not(space, w_a, w_b): |
| 75 |
'is_not(a, b) -- Same as a is not b' |
| 76 |
return space.not_(space.is_(w_a, w_b)) |
| 77 |
|
| 78 |
def le(space, w_a, w_b): |
| 79 |
'le(a, b) -- Same as a<=b.' |
| 80 |
return space.le(w_a, w_b) |
| 81 |
|
| 82 |
def lshift(space, w_a, w_b): |
| 83 |
'lshift(a, b) -- Same as a << b.' |
| 84 |
return space.lshift(w_a, w_b) |
| 85 |
|
| 86 |
def lt(space, w_a, w_b): |
| 87 |
'lt(a, b) -- Same as a<b.' |
| 88 |
return space.lt(w_a, w_b) |
| 89 |
|
| 90 |
def mod(space, w_a, w_b): |
| 91 |
'mod(a, b) -- Same as a % b.' |
| 92 |
return space.mod(w_a, w_b) |
| 93 |
|
| 94 |
def mul(space, w_a, w_b): |
| 95 |
'mul(a, b) -- Same as a * b.' |
| 96 |
return space.mul(w_a, w_b) |
| 97 |
|
| 98 |
def ne(space, w_a, w_b): |
| 99 |
'ne(a, b) -- Same as a!=b.' |
| 100 |
return space.ne(w_a, w_b) |
| 101 |
|
| 102 |
def neg(space, w_obj,): |
| 103 |
'neg(a) -- Same as -a.' |
| 104 |
return space.neg(w_obj) |
| 105 |
|
| 106 |
def not_(space, w_obj,): |
| 107 |
'not_(a) -- Same as not a.' |
| 108 |
return space.not_(w_obj) |
| 109 |
|
| 110 |
def or_(space, w_a, w_b): |
| 111 |
'or_(a, b) -- Same as a | b.' |
| 112 |
return space.or_(w_a, w_b) |
| 113 |
|
| 114 |
def pos(space, w_obj,): |
| 115 |
'pos(a) -- Same as +a.' |
| 116 |
return space.pos(w_obj) |
| 117 |
|
| 118 |
def pow(space, w_a, w_b): |
| 119 |
'pow(a, b) -- Same as a**b.' |
| 120 |
return space.pow(w_a, w_b, space.w_None) |
| 121 |
|
| 122 |
def rshift(space, w_a, w_b): |
| 123 |
'rshift(a, b) -- Same as a >> b.' |
| 124 |
return space.rshift(w_a, w_b) |
| 125 |
|
| 126 |
def setitem(space, w_obj, w_key, w_value): |
| 127 |
'setitem(a, b, c) -- Same as a[b] = c.' |
| 128 |
space.setitem(w_obj, w_key, w_value) |
| 129 |
|
| 130 |
def sub(space, w_a, w_b): |
| 131 |
'sub(a, b) -- Same as a - b.' |
| 132 |
return space.sub(w_a, w_b) |
| 133 |
|
| 134 |
def truediv(space, w_a, w_b): |
| 135 |
'truediv(a, b) -- Same as a / b when __future__.division is in effect.' |
| 136 |
return space.truediv(w_a, w_b) |
| 137 |
|
| 138 |
def truth(space, w_a,): |
| 139 |
'truth(a) -- Return True if a is true, False otherwise.' |
| 140 |
return space.nonzero(w_a) |
| 141 |
|
| 142 |
def xor(space, w_a, w_b): |
| 143 |
'xor(a, b) -- Same as a ^ b.' |
| 144 |
return space.xor(w_a, w_b) |
| 145 |
|
| 146 |
def matmul(space, w_a, w_b): |
| 147 |
'matmul(a, b) -- Same as a @ b.' |
| 148 |
return space.matmul(w_a, w_b) |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
def iadd(space, w_obj1, w_obj2): |
| 153 |
'iadd(a, b) -- Same as a += b.' |
| 154 |
return space.inplace_add(w_obj1, w_obj2) |
| 155 |
|
| 156 |
def iand(space, w_obj1, w_obj2): |
| 157 |
'iand(a, b) -- Same as a =& b' |
| 158 |
return space.inplace_and(w_obj1, w_obj2) |
| 159 |
|
| 160 |
def ifloordiv(space, w_a, w_b): |
| 161 |
'ifloordiv(a, b) -- Same as a //= b.' |
| 162 |
return space.inplace_floordiv(w_a, w_b) |
| 163 |
|
| 164 |
def ilshift(space, w_a, w_b): |
| 165 |
'ilshift(a, b) -- Same as a <<= b.' |
| 166 |
return space.inplace_lshift(w_a, w_b) |
| 167 |
|
| 168 |
def imod(space, w_a, w_b): |
| 169 |
'imod(a, b) -- Same as a %= b.' |
| 170 |
return space.inplace_mod(w_a, w_b) |
| 171 |
|
| 172 |
def imul(space, w_a, w_b): |
| 173 |
'imul(a, b) -- Same as a *= b.' |
| 174 |
return space.inplace_mul(w_a, w_b) |
| 175 |
|
| 176 |
def ior(space, w_a, w_b): |
| 177 |
'ior(a, b) -- Same as a |= b.' |
| 178 |
return space.inplace_or(w_a, w_b) |
| 179 |
|
| 180 |
def ipow(space, w_a, w_b): |
| 181 |
'ipow(a, b) -- Same as a **= b.' |
| 182 |
return space.inplace_pow(w_a, w_b) |
| 183 |
|
| 184 |
def irshift(space, w_a, w_b): |
| 185 |
'irshift(a, b) -- Same as a >>= b.' |
| 186 |
return space.inplace_rshift(w_a, w_b) |
| 187 |
|
| 188 |
def isub(space, w_a, w_b): |
| 189 |
'isub(a, b) -- Same as a -= b.' |
| 190 |
return space.inplace_sub(w_a, w_b) |
| 191 |
|
| 192 |
def itruediv(space, w_a, w_b): |
| 193 |
'itruediv(a, b) -- Same as a /= b when __future__.division is in effect.' |
| 194 |
return space.inplace_truediv(w_a, w_b) |
| 195 |
|
| 196 |
def ixor(space, w_a, w_b): |
| 197 |
'ixor(a, b) -- Same as a ^= b.' |
| 198 |
return space.inplace_xor(w_a, w_b) |
| 199 |
|
| 200 |
def imatmul(space, w_a, w_b): |
| 201 |
'imatmul(a, b) -- Same as a @= b.' |
| 202 |
return space.inplace_matmul(w_a, w_b) |
| 203 |
|
| 204 |
def iconcat(space, w_obj1, w_obj2): |
| 205 |
'iconcat(a, b) -- Same as a += b, for a and b sequences.' |
| 206 |
if (space.lookup(w_obj1, '__getitem__') is None or |
| 207 |
space.lookup(w_obj2, '__getitem__') is None): |
| 208 |
raise oefmt(space.w_TypeError, "'%T' object can't be concatenated", w_obj1) |
| 209 |
|
| 210 |
return space.inplace_add(w_obj1, w_obj2) |
| 211 |
|
| 212 |
@unwrap_spec(default='index') |
| 213 |
def length_hint(space, w_iterable, default=0): |
| 214 |
"""Return an estimate of the number of items in obj. |
| 215 |
This is useful for presizing containers when building from an iterable. |
| 216 |
If the object supports len(), the result will be exact. |
| 217 |
Otherwise, it may over- or under-estimate by an arbitrary amount. |
| 218 |
The result will be an integer >= 0.""" |
| 219 |
return space.newint(space.length_hint(w_iterable, default)) |