# HG changeset patch # User paulb@localhost.localdomain # Date 1165103255 -3600 # Node ID 8dd0a818223097c32dbb9f5db8acbfec9f806856 # Parent 9934256582eb92c5cc9bb0d010bfda8321c10412 Reordered classes, changed string to str, removed superfluous types and values. Added a fallback __iadd__ method on object. diff -r 9934256582eb -r 8dd0a8182230 lib/builtins.py --- a/lib/builtins.py Sat Dec 02 18:51:23 2006 +0100 +++ b/lib/builtins.py Sun Dec 03 00:47:35 2006 +0100 @@ -27,6 +27,9 @@ # NOTE: See the reference: 3.3.1 Basic customization return False + def __iadd__(self, other): + return self.__add__(other) + class bool: def __bool__(self): return self @@ -37,241 +40,25 @@ else: return "False" -class int: - def __iadd__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __isub__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __add__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __radd__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __sub__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __rsub__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __mul__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __rmul__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __div__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __rdiv__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __floordiv__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __rfloordiv__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __pow__(self, other): - if isinstance(other, int): - return int() - else: - raise TypeError - - def __lt__(self, other): - if isinstance(other, int): - return bool() - else: - raise TypeError - - def __gt__(self, other): - if isinstance(other, int): - return bool() - else: - raise TypeError - - def __le__(self, other): - if isinstance(other, int): - return bool() - else: - raise TypeError - - def __ge__(self, other): - if isinstance(other, int): - return bool() - else: - raise TypeError - - def __eq__(self, other): - if isinstance(other, int): - return bool() - else: - raise TypeError - - def __ne__(self, other): - if isinstance(other, int): - return bool() - else: +class buffer: + def __init__(self, size): + if not isinstance(size, int): raise TypeError - def __neg__(self): - return int() - - def __pos__(self): - return self + def append(self, s): + if not isinstance(s, str): + raise TypeError + pass def __str__(self): - return string() - - def __bool__(self): - return self != 0 - -class long: - def __iadd__(self, other): - if isinstance(other, int): - return long() - elif isinstance(other, long): - return long() - else: - raise TypeError - - def __isub__(self, other): - if isinstance(other, int): - return long() - elif isinstance(other, long): - return long() - else: - raise TypeError - - def __add__(self, other): - if isinstance(other, int): - return long() - elif isinstance(other, long): - return long() - else: - raise TypeError - - def __radd__(self, other): - if isinstance(other, int): - return long() - elif isinstance(other, long): - return long() - else: - raise TypeError - - def __sub__(self, other): - if isinstance(other, int): - return long() - elif isinstance(other, long): - return long() - else: - raise TypeError - - def __rsub__(self, other): - if isinstance(other, int): - return long() - elif isinstance(other, long): - return long() - else: - raise TypeError + return str() - def __lt__(self, other): - if isinstance(other, int): - return bool() - elif isinstance(other, long): - return bool() - else: - raise TypeError - - def __gt__(self, other): - if isinstance(other, int): - return bool() - elif isinstance(other, long): - return bool() - else: - raise TypeError - - def __le__(self, other): - if isinstance(other, int): - return bool() - elif isinstance(other, long): - return bool() - else: - raise TypeError +class dict: + pass - def __ge__(self, other): - if isinstance(other, int): - return bool() - elif isinstance(other, long): - return bool() - else: - raise TypeError - - def __eq__(self, other): - if isinstance(other, int): - return bool() - elif isinstance(other, long): - return bool() - else: - raise TypeError - - def __ne__(self, other): - if isinstance(other, int): - return bool() - elif isinstance(other, long): - return bool() - else: - raise TypeError - - def __neg__(self): - return long() - - def __pos__(self): - return self - - def __str__(self): - return string() - - def __bool__(self): - return self != 0 +class file: + def write(self, s): + pass class float: def __iadd__(self, other): @@ -481,67 +268,137 @@ return self def __str__(self): - return string() + return str() def __bool__(self): return self != 0 -class str: - def __init__(self, x=None): - x.__str__() +class int: + def __iadd__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __isub__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError def __add__(self, other): - if isinstance(other, string): - return string() + if isinstance(other, int): + return int() else: raise TypeError def __radd__(self, other): - if isinstance(other, string): - return string() + if isinstance(other, int): + return int() + else: + raise TypeError + + def __sub__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __rsub__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __mul__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __rmul__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __div__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __rdiv__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __floordiv__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __rfloordiv__(self, other): + if isinstance(other, int): + return int() else: raise TypeError - def __len__(self): + def __pow__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __lt__(self, other): + if isinstance(other, int): + return bool() + else: + raise TypeError + + def __gt__(self, other): + if isinstance(other, int): + return bool() + else: + raise TypeError + + def __le__(self, other): + if isinstance(other, int): + return bool() + else: + raise TypeError + + def __ge__(self, other): + if isinstance(other, int): + return bool() + else: + raise TypeError + + def __eq__(self, other): + if isinstance(other, int): + return bool() + else: + raise TypeError + + def __ne__(self, other): + if isinstance(other, int): + return bool() + else: + raise TypeError + + def __neg__(self): return int() + def __pos__(self): + return self + def __str__(self): - return self + return str() def __bool__(self): - return self.__len__() != 0 - - def join(self, l): - total = 0 - first = 1 - self_len = self.__len__() - for i in l: - if not first: - total += self_len - total += len(str(i)) - first = 0 - b = buffer(total) - first = 1 - for i in l: - if not first: - b.append(self) - b.append(str(i)) - first = 0 - s = str(b) - return s - -class buffer: - def __init__(self, size): - if not isinstance(size, int): - raise TypeError - - def append(self, s): - if not isinstance(s, string): - raise TypeError - pass - - def __str__(self): - return string() + return self != 0 class list: def __init__(self, *args): @@ -664,6 +521,166 @@ def __bool__(self): return bool() +class long: + def __iadd__(self, other): + if isinstance(other, int): + return long() + elif isinstance(other, long): + return long() + else: + raise TypeError + + def __isub__(self, other): + if isinstance(other, int): + return long() + elif isinstance(other, long): + return long() + else: + raise TypeError + + def __add__(self, other): + if isinstance(other, int): + return long() + elif isinstance(other, long): + return long() + else: + raise TypeError + + def __radd__(self, other): + if isinstance(other, int): + return long() + elif isinstance(other, long): + return long() + else: + raise TypeError + + def __sub__(self, other): + if isinstance(other, int): + return long() + elif isinstance(other, long): + return long() + else: + raise TypeError + + def __rsub__(self, other): + if isinstance(other, int): + return long() + elif isinstance(other, long): + return long() + else: + raise TypeError + + def __lt__(self, other): + if isinstance(other, int): + return bool() + elif isinstance(other, long): + return bool() + else: + raise TypeError + + def __gt__(self, other): + if isinstance(other, int): + return bool() + elif isinstance(other, long): + return bool() + else: + raise TypeError + + def __le__(self, other): + if isinstance(other, int): + return bool() + elif isinstance(other, long): + return bool() + else: + raise TypeError + + def __ge__(self, other): + if isinstance(other, int): + return bool() + elif isinstance(other, long): + return bool() + else: + raise TypeError + + def __eq__(self, other): + if isinstance(other, int): + return bool() + elif isinstance(other, long): + return bool() + else: + raise TypeError + + def __ne__(self, other): + if isinstance(other, int): + return bool() + elif isinstance(other, long): + return bool() + else: + raise TypeError + + def __neg__(self): + return long() + + def __pos__(self): + return self + + def __str__(self): + return str() + + def __bool__(self): + return self != 0 + +class none: + def __bool__(self): + return False + + def __str__(self): + return "None" + +class str: + def __init__(self, x=None): + x.__str__() + + def __add__(self, other): + if isinstance(other, str): + return str() + else: + raise TypeError + + def __radd__(self, other): + if isinstance(other, str): + return str() + else: + raise TypeError + + def __len__(self): + return int() + + def __str__(self): + return self + + def __bool__(self): + return self.__len__() != 0 + + def join(self, l): + total = 0 + first = 1 + self_len = self.__len__() + for i in l: + if not first: + total += self_len + total += len(str(i)) + first = 0 + b = buffer(total) + first = 1 + for i in l: + if not first: + b.append(self) + b.append(str(i)) + first = 0 + s = str(b) + return s + class tuple: def __init__(self, *args): self.next = None @@ -756,34 +773,6 @@ def __bool__(self): return bool() -class dict: - pass - -class Exception: - pass - -class StopIteration(Exception): - pass - -class IndexError(Exception): - pass - -class AttributeError(Exception): - pass - -class TypeError(Exception): - pass - -class none: - def __bool__(self): - return False - - def __str__(self): - return "None" - -class undefined: - pass - class xrange: def __init__(self, start, end, step=1): self.start = start @@ -801,6 +790,21 @@ self.current += self.step return current +class Exception: + pass + +class AttributeError(Exception): + pass + +class IndexError(Exception): + pass + +class StopIteration(Exception): + pass + +class TypeError(Exception): + pass + # General functions. def isinstance(obj, cls): @@ -844,16 +848,15 @@ True = bool() False = bool() None = none() -Undefined = undefined() +stdin = file() +stdout = file() +stderr = file() # Special functions. These all operate on references at run-time. def __is__(a, b): return bool() -def __is_not__(a, b): - return bool() - def __not__(a): return bool()