1
"""Hack to provide Python 2.3-style boolean operation in 2.2
4
if str(True) != 'True':
5
# Python 2.2.3 has True, but it's just 1 and 0 refs...
12
def __new__(cls, val=0):
13
# This constructor always returns an existing instance
27
def __and__(self, other):
28
if isinstance(other, bool):
29
return bool(int(self) & int(other))
31
return int.__and__(self, other)
35
def __or__(self, other):
36
if isinstance(other, bool):
37
return bool(int(self) | int(other))
39
return int.__or__(self, other)
43
def __xor__(self, other):
44
if isinstance(other, bool):
45
return bool(int(self) ^ int(other))
47
return int.__xor__(self, other)
51
# Bootstrap truth values through sheer willpower
52
False = int.__new__(bool, 0==1)
53
True = int.__new__(bool, 1==1)
56
"""Install the enhanced bool, True and False in __builtin__"""
58
__builtin__.True = True
59
__builtin__.False = False
60
__builtin__.bool = bool
63
if __name__ == "__main__":