1.1 --- a/lib/builtins.py Sat Dec 02 18:51:23 2006 +0100
1.2 +++ b/lib/builtins.py Sun Dec 03 00:47:35 2006 +0100
1.3 @@ -27,6 +27,9 @@
1.4 # NOTE: See the reference: 3.3.1 Basic customization
1.5 return False
1.6
1.7 + def __iadd__(self, other):
1.8 + return self.__add__(other)
1.9 +
1.10 class bool:
1.11 def __bool__(self):
1.12 return self
1.13 @@ -37,241 +40,25 @@
1.14 else:
1.15 return "False"
1.16
1.17 -class int:
1.18 - def __iadd__(self, other):
1.19 - if isinstance(other, int):
1.20 - return int()
1.21 - else:
1.22 - raise TypeError
1.23 -
1.24 - def __isub__(self, other):
1.25 - if isinstance(other, int):
1.26 - return int()
1.27 - else:
1.28 - raise TypeError
1.29 -
1.30 - def __add__(self, other):
1.31 - if isinstance(other, int):
1.32 - return int()
1.33 - else:
1.34 - raise TypeError
1.35 -
1.36 - def __radd__(self, other):
1.37 - if isinstance(other, int):
1.38 - return int()
1.39 - else:
1.40 - raise TypeError
1.41 -
1.42 - def __sub__(self, other):
1.43 - if isinstance(other, int):
1.44 - return int()
1.45 - else:
1.46 - raise TypeError
1.47 -
1.48 - def __rsub__(self, other):
1.49 - if isinstance(other, int):
1.50 - return int()
1.51 - else:
1.52 - raise TypeError
1.53 -
1.54 - def __mul__(self, other):
1.55 - if isinstance(other, int):
1.56 - return int()
1.57 - else:
1.58 - raise TypeError
1.59 -
1.60 - def __rmul__(self, other):
1.61 - if isinstance(other, int):
1.62 - return int()
1.63 - else:
1.64 - raise TypeError
1.65 -
1.66 - def __div__(self, other):
1.67 - if isinstance(other, int):
1.68 - return int()
1.69 - else:
1.70 - raise TypeError
1.71 -
1.72 - def __rdiv__(self, other):
1.73 - if isinstance(other, int):
1.74 - return int()
1.75 - else:
1.76 - raise TypeError
1.77 -
1.78 - def __floordiv__(self, other):
1.79 - if isinstance(other, int):
1.80 - return int()
1.81 - else:
1.82 - raise TypeError
1.83 -
1.84 - def __rfloordiv__(self, other):
1.85 - if isinstance(other, int):
1.86 - return int()
1.87 - else:
1.88 - raise TypeError
1.89 -
1.90 - def __pow__(self, other):
1.91 - if isinstance(other, int):
1.92 - return int()
1.93 - else:
1.94 - raise TypeError
1.95 -
1.96 - def __lt__(self, other):
1.97 - if isinstance(other, int):
1.98 - return bool()
1.99 - else:
1.100 - raise TypeError
1.101 -
1.102 - def __gt__(self, other):
1.103 - if isinstance(other, int):
1.104 - return bool()
1.105 - else:
1.106 - raise TypeError
1.107 -
1.108 - def __le__(self, other):
1.109 - if isinstance(other, int):
1.110 - return bool()
1.111 - else:
1.112 - raise TypeError
1.113 -
1.114 - def __ge__(self, other):
1.115 - if isinstance(other, int):
1.116 - return bool()
1.117 - else:
1.118 - raise TypeError
1.119 -
1.120 - def __eq__(self, other):
1.121 - if isinstance(other, int):
1.122 - return bool()
1.123 - else:
1.124 - raise TypeError
1.125 -
1.126 - def __ne__(self, other):
1.127 - if isinstance(other, int):
1.128 - return bool()
1.129 - else:
1.130 +class buffer:
1.131 + def __init__(self, size):
1.132 + if not isinstance(size, int):
1.133 raise TypeError
1.134
1.135 - def __neg__(self):
1.136 - return int()
1.137 -
1.138 - def __pos__(self):
1.139 - return self
1.140 + def append(self, s):
1.141 + if not isinstance(s, str):
1.142 + raise TypeError
1.143 + pass
1.144
1.145 def __str__(self):
1.146 - return string()
1.147 -
1.148 - def __bool__(self):
1.149 - return self != 0
1.150 -
1.151 -class long:
1.152 - def __iadd__(self, other):
1.153 - if isinstance(other, int):
1.154 - return long()
1.155 - elif isinstance(other, long):
1.156 - return long()
1.157 - else:
1.158 - raise TypeError
1.159 -
1.160 - def __isub__(self, other):
1.161 - if isinstance(other, int):
1.162 - return long()
1.163 - elif isinstance(other, long):
1.164 - return long()
1.165 - else:
1.166 - raise TypeError
1.167 -
1.168 - def __add__(self, other):
1.169 - if isinstance(other, int):
1.170 - return long()
1.171 - elif isinstance(other, long):
1.172 - return long()
1.173 - else:
1.174 - raise TypeError
1.175 -
1.176 - def __radd__(self, other):
1.177 - if isinstance(other, int):
1.178 - return long()
1.179 - elif isinstance(other, long):
1.180 - return long()
1.181 - else:
1.182 - raise TypeError
1.183 -
1.184 - def __sub__(self, other):
1.185 - if isinstance(other, int):
1.186 - return long()
1.187 - elif isinstance(other, long):
1.188 - return long()
1.189 - else:
1.190 - raise TypeError
1.191 -
1.192 - def __rsub__(self, other):
1.193 - if isinstance(other, int):
1.194 - return long()
1.195 - elif isinstance(other, long):
1.196 - return long()
1.197 - else:
1.198 - raise TypeError
1.199 + return str()
1.200
1.201 - def __lt__(self, other):
1.202 - if isinstance(other, int):
1.203 - return bool()
1.204 - elif isinstance(other, long):
1.205 - return bool()
1.206 - else:
1.207 - raise TypeError
1.208 -
1.209 - def __gt__(self, other):
1.210 - if isinstance(other, int):
1.211 - return bool()
1.212 - elif isinstance(other, long):
1.213 - return bool()
1.214 - else:
1.215 - raise TypeError
1.216 -
1.217 - def __le__(self, other):
1.218 - if isinstance(other, int):
1.219 - return bool()
1.220 - elif isinstance(other, long):
1.221 - return bool()
1.222 - else:
1.223 - raise TypeError
1.224 +class dict:
1.225 + pass
1.226
1.227 - def __ge__(self, other):
1.228 - if isinstance(other, int):
1.229 - return bool()
1.230 - elif isinstance(other, long):
1.231 - return bool()
1.232 - else:
1.233 - raise TypeError
1.234 -
1.235 - def __eq__(self, other):
1.236 - if isinstance(other, int):
1.237 - return bool()
1.238 - elif isinstance(other, long):
1.239 - return bool()
1.240 - else:
1.241 - raise TypeError
1.242 -
1.243 - def __ne__(self, other):
1.244 - if isinstance(other, int):
1.245 - return bool()
1.246 - elif isinstance(other, long):
1.247 - return bool()
1.248 - else:
1.249 - raise TypeError
1.250 -
1.251 - def __neg__(self):
1.252 - return long()
1.253 -
1.254 - def __pos__(self):
1.255 - return self
1.256 -
1.257 - def __str__(self):
1.258 - return string()
1.259 -
1.260 - def __bool__(self):
1.261 - return self != 0
1.262 +class file:
1.263 + def write(self, s):
1.264 + pass
1.265
1.266 class float:
1.267 def __iadd__(self, other):
1.268 @@ -481,67 +268,137 @@
1.269 return self
1.270
1.271 def __str__(self):
1.272 - return string()
1.273 + return str()
1.274
1.275 def __bool__(self):
1.276 return self != 0
1.277
1.278 -class str:
1.279 - def __init__(self, x=None):
1.280 - x.__str__()
1.281 +class int:
1.282 + def __iadd__(self, other):
1.283 + if isinstance(other, int):
1.284 + return int()
1.285 + else:
1.286 + raise TypeError
1.287 +
1.288 + def __isub__(self, other):
1.289 + if isinstance(other, int):
1.290 + return int()
1.291 + else:
1.292 + raise TypeError
1.293
1.294 def __add__(self, other):
1.295 - if isinstance(other, string):
1.296 - return string()
1.297 + if isinstance(other, int):
1.298 + return int()
1.299 else:
1.300 raise TypeError
1.301
1.302 def __radd__(self, other):
1.303 - if isinstance(other, string):
1.304 - return string()
1.305 + if isinstance(other, int):
1.306 + return int()
1.307 + else:
1.308 + raise TypeError
1.309 +
1.310 + def __sub__(self, other):
1.311 + if isinstance(other, int):
1.312 + return int()
1.313 + else:
1.314 + raise TypeError
1.315 +
1.316 + def __rsub__(self, other):
1.317 + if isinstance(other, int):
1.318 + return int()
1.319 + else:
1.320 + raise TypeError
1.321 +
1.322 + def __mul__(self, other):
1.323 + if isinstance(other, int):
1.324 + return int()
1.325 + else:
1.326 + raise TypeError
1.327 +
1.328 + def __rmul__(self, other):
1.329 + if isinstance(other, int):
1.330 + return int()
1.331 + else:
1.332 + raise TypeError
1.333 +
1.334 + def __div__(self, other):
1.335 + if isinstance(other, int):
1.336 + return int()
1.337 + else:
1.338 + raise TypeError
1.339 +
1.340 + def __rdiv__(self, other):
1.341 + if isinstance(other, int):
1.342 + return int()
1.343 + else:
1.344 + raise TypeError
1.345 +
1.346 + def __floordiv__(self, other):
1.347 + if isinstance(other, int):
1.348 + return int()
1.349 + else:
1.350 + raise TypeError
1.351 +
1.352 + def __rfloordiv__(self, other):
1.353 + if isinstance(other, int):
1.354 + return int()
1.355 else:
1.356 raise TypeError
1.357
1.358 - def __len__(self):
1.359 + def __pow__(self, other):
1.360 + if isinstance(other, int):
1.361 + return int()
1.362 + else:
1.363 + raise TypeError
1.364 +
1.365 + def __lt__(self, other):
1.366 + if isinstance(other, int):
1.367 + return bool()
1.368 + else:
1.369 + raise TypeError
1.370 +
1.371 + def __gt__(self, other):
1.372 + if isinstance(other, int):
1.373 + return bool()
1.374 + else:
1.375 + raise TypeError
1.376 +
1.377 + def __le__(self, other):
1.378 + if isinstance(other, int):
1.379 + return bool()
1.380 + else:
1.381 + raise TypeError
1.382 +
1.383 + def __ge__(self, other):
1.384 + if isinstance(other, int):
1.385 + return bool()
1.386 + else:
1.387 + raise TypeError
1.388 +
1.389 + def __eq__(self, other):
1.390 + if isinstance(other, int):
1.391 + return bool()
1.392 + else:
1.393 + raise TypeError
1.394 +
1.395 + def __ne__(self, other):
1.396 + if isinstance(other, int):
1.397 + return bool()
1.398 + else:
1.399 + raise TypeError
1.400 +
1.401 + def __neg__(self):
1.402 return int()
1.403
1.404 + def __pos__(self):
1.405 + return self
1.406 +
1.407 def __str__(self):
1.408 - return self
1.409 + return str()
1.410
1.411 def __bool__(self):
1.412 - return self.__len__() != 0
1.413 -
1.414 - def join(self, l):
1.415 - total = 0
1.416 - first = 1
1.417 - self_len = self.__len__()
1.418 - for i in l:
1.419 - if not first:
1.420 - total += self_len
1.421 - total += len(str(i))
1.422 - first = 0
1.423 - b = buffer(total)
1.424 - first = 1
1.425 - for i in l:
1.426 - if not first:
1.427 - b.append(self)
1.428 - b.append(str(i))
1.429 - first = 0
1.430 - s = str(b)
1.431 - return s
1.432 -
1.433 -class buffer:
1.434 - def __init__(self, size):
1.435 - if not isinstance(size, int):
1.436 - raise TypeError
1.437 -
1.438 - def append(self, s):
1.439 - if not isinstance(s, string):
1.440 - raise TypeError
1.441 - pass
1.442 -
1.443 - def __str__(self):
1.444 - return string()
1.445 + return self != 0
1.446
1.447 class list:
1.448 def __init__(self, *args):
1.449 @@ -664,6 +521,166 @@
1.450 def __bool__(self):
1.451 return bool()
1.452
1.453 +class long:
1.454 + def __iadd__(self, other):
1.455 + if isinstance(other, int):
1.456 + return long()
1.457 + elif isinstance(other, long):
1.458 + return long()
1.459 + else:
1.460 + raise TypeError
1.461 +
1.462 + def __isub__(self, other):
1.463 + if isinstance(other, int):
1.464 + return long()
1.465 + elif isinstance(other, long):
1.466 + return long()
1.467 + else:
1.468 + raise TypeError
1.469 +
1.470 + def __add__(self, other):
1.471 + if isinstance(other, int):
1.472 + return long()
1.473 + elif isinstance(other, long):
1.474 + return long()
1.475 + else:
1.476 + raise TypeError
1.477 +
1.478 + def __radd__(self, other):
1.479 + if isinstance(other, int):
1.480 + return long()
1.481 + elif isinstance(other, long):
1.482 + return long()
1.483 + else:
1.484 + raise TypeError
1.485 +
1.486 + def __sub__(self, other):
1.487 + if isinstance(other, int):
1.488 + return long()
1.489 + elif isinstance(other, long):
1.490 + return long()
1.491 + else:
1.492 + raise TypeError
1.493 +
1.494 + def __rsub__(self, other):
1.495 + if isinstance(other, int):
1.496 + return long()
1.497 + elif isinstance(other, long):
1.498 + return long()
1.499 + else:
1.500 + raise TypeError
1.501 +
1.502 + def __lt__(self, other):
1.503 + if isinstance(other, int):
1.504 + return bool()
1.505 + elif isinstance(other, long):
1.506 + return bool()
1.507 + else:
1.508 + raise TypeError
1.509 +
1.510 + def __gt__(self, other):
1.511 + if isinstance(other, int):
1.512 + return bool()
1.513 + elif isinstance(other, long):
1.514 + return bool()
1.515 + else:
1.516 + raise TypeError
1.517 +
1.518 + def __le__(self, other):
1.519 + if isinstance(other, int):
1.520 + return bool()
1.521 + elif isinstance(other, long):
1.522 + return bool()
1.523 + else:
1.524 + raise TypeError
1.525 +
1.526 + def __ge__(self, other):
1.527 + if isinstance(other, int):
1.528 + return bool()
1.529 + elif isinstance(other, long):
1.530 + return bool()
1.531 + else:
1.532 + raise TypeError
1.533 +
1.534 + def __eq__(self, other):
1.535 + if isinstance(other, int):
1.536 + return bool()
1.537 + elif isinstance(other, long):
1.538 + return bool()
1.539 + else:
1.540 + raise TypeError
1.541 +
1.542 + def __ne__(self, other):
1.543 + if isinstance(other, int):
1.544 + return bool()
1.545 + elif isinstance(other, long):
1.546 + return bool()
1.547 + else:
1.548 + raise TypeError
1.549 +
1.550 + def __neg__(self):
1.551 + return long()
1.552 +
1.553 + def __pos__(self):
1.554 + return self
1.555 +
1.556 + def __str__(self):
1.557 + return str()
1.558 +
1.559 + def __bool__(self):
1.560 + return self != 0
1.561 +
1.562 +class none:
1.563 + def __bool__(self):
1.564 + return False
1.565 +
1.566 + def __str__(self):
1.567 + return "None"
1.568 +
1.569 +class str:
1.570 + def __init__(self, x=None):
1.571 + x.__str__()
1.572 +
1.573 + def __add__(self, other):
1.574 + if isinstance(other, str):
1.575 + return str()
1.576 + else:
1.577 + raise TypeError
1.578 +
1.579 + def __radd__(self, other):
1.580 + if isinstance(other, str):
1.581 + return str()
1.582 + else:
1.583 + raise TypeError
1.584 +
1.585 + def __len__(self):
1.586 + return int()
1.587 +
1.588 + def __str__(self):
1.589 + return self
1.590 +
1.591 + def __bool__(self):
1.592 + return self.__len__() != 0
1.593 +
1.594 + def join(self, l):
1.595 + total = 0
1.596 + first = 1
1.597 + self_len = self.__len__()
1.598 + for i in l:
1.599 + if not first:
1.600 + total += self_len
1.601 + total += len(str(i))
1.602 + first = 0
1.603 + b = buffer(total)
1.604 + first = 1
1.605 + for i in l:
1.606 + if not first:
1.607 + b.append(self)
1.608 + b.append(str(i))
1.609 + first = 0
1.610 + s = str(b)
1.611 + return s
1.612 +
1.613 class tuple:
1.614 def __init__(self, *args):
1.615 self.next = None
1.616 @@ -756,34 +773,6 @@
1.617 def __bool__(self):
1.618 return bool()
1.619
1.620 -class dict:
1.621 - pass
1.622 -
1.623 -class Exception:
1.624 - pass
1.625 -
1.626 -class StopIteration(Exception):
1.627 - pass
1.628 -
1.629 -class IndexError(Exception):
1.630 - pass
1.631 -
1.632 -class AttributeError(Exception):
1.633 - pass
1.634 -
1.635 -class TypeError(Exception):
1.636 - pass
1.637 -
1.638 -class none:
1.639 - def __bool__(self):
1.640 - return False
1.641 -
1.642 - def __str__(self):
1.643 - return "None"
1.644 -
1.645 -class undefined:
1.646 - pass
1.647 -
1.648 class xrange:
1.649 def __init__(self, start, end, step=1):
1.650 self.start = start
1.651 @@ -801,6 +790,21 @@
1.652 self.current += self.step
1.653 return current
1.654
1.655 +class Exception:
1.656 + pass
1.657 +
1.658 +class AttributeError(Exception):
1.659 + pass
1.660 +
1.661 +class IndexError(Exception):
1.662 + pass
1.663 +
1.664 +class StopIteration(Exception):
1.665 + pass
1.666 +
1.667 +class TypeError(Exception):
1.668 + pass
1.669 +
1.670 # General functions.
1.671
1.672 def isinstance(obj, cls):
1.673 @@ -844,16 +848,15 @@
1.674 True = bool()
1.675 False = bool()
1.676 None = none()
1.677 -Undefined = undefined()
1.678 +stdin = file()
1.679 +stdout = file()
1.680 +stderr = file()
1.681
1.682 # Special functions. These all operate on references at run-time.
1.683
1.684 def __is__(a, b):
1.685 return bool()
1.686
1.687 -def __is_not__(a, b):
1.688 - return bool()
1.689 -
1.690 def __not__(a):
1.691 return bool()
1.692