#!/usr/bin/env python """ UserInt.py - A user-defined wrapper around integer objects. """ __license__ = """ Copyright (c) 2002 Mark Nottingham Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ __version__ = "0.51" class UserInt: def __init__(self, arg): if isinstance(arg, UserInt): self.data = arg.data else: self.data = int(arg) def __add__(self, other): return self.__class__(self.data + int(other)) def __radd__(self, other): return self.__class__(int(other) + self.data) def __sub__(self, other): return self.__class__(self.data - int(other)) def __rsub__(self, other): return self.__class__(int(other) - self.data) def __mul__(self, other): return self.__class__(self.data * int(other)) def __rmul__(self, other): return self.__class__(int(other) * self.data) def __div__(self, other): return self.__class__(self.data / int(other)) def __rdiv__(self, other): return self.__class__(int(other) / self.data) def __mod__(self, other): return self.__class__(self.data % int(other)) def __rmod__(self, other): return self.__class__(int(other) % self.data) def __divmod__(self, other): return self.__class__(divmod(self.data, int(other))) def __rdivmod__(self, other): return self.__class__(divmod(int(other), self.data)) def __pow__(self, other, modulo=None): return self.__class__(pow(self.data, int(other), modulo)) def __rpow__(self, other): return self.__class__(pow(int(other), self.data)) def __lshift__(self, other): return self.__class__(self.data << int(other)) def __rlshift__(self, other): return self.__class__(int(other) << self.data) def __rshift__(self, other): return self.__class__(self.data >> int(other)) def __rrshift__(self, other): return self.__class__(int(other) >> self.data) def __and__(self, other): return self.__class__(self.data & int(other)) def __rand__(self, other): return self.__class__(int(other) & self.data) def __xor__(self, other): return self.__class__(self.data ^ int(other)) def __rxor__(self, other): return self.__class__(int(other) ^ self.data) def __or__(self, other): return self.__class__(self.data | int(other)) def __ror__(self, other): return self.__class__(int(other) | self.data) def __neg__(self): return -self.data def __pos__(self): return +self.data def __abs__(self): return abs(self.data) def __invert__(self): return ~self.data def __complex__(self): return complex(self.data) def __int__(self): return int(self.data) def __long__(self): return long(self.data) def __float__(self): return float(self.data) def __oct__(self): return oct(self.data) def __hex__(self): return hex(self.data) def __str__(self): return str(self.data) def __repr__(self): return str(self.data) def __cmp__(self, other): return cmp(self.data, other) def __rcmp__(self, other): return cmp(other, self.data) def __nonzero__(self): if self.data: return 1 else: return 0