From: <gha...@us...> - 2006-06-01 14:43:00
|
Update of /cvsroot/pypgsql/pypgsql/pyPgSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18409/pyPgSQL Modified Files: PgSQL.py __init__.py Log Message: 01JUN2006 gh - Got rid of the custom PgInt2 and PgInt8 types. Normal Python int and long are used now, so coercion works again with Python 2.1 through 2.4. This will also get rid of the maintenance nightmare that came with C's "long long" type on various platforms. Index: PgSQL.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pyPgSQL/PgSQL.py,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** PgSQL.py 21 May 2005 01:31:23 -0000 1.49 --- PgSQL.py 1 Jun 2006 14:42:51 -0000 1.50 *************** *** 30,33 **** --- 30,38 ---- # Date Ini Description | # --------- --- ------------------------------------------------------- | + # 01JUN2006 gh - Got rid of the custom PgInt2 and PgInt8 types. Normal | + # Python int and long are used now, so coercion works | + # again with Python 2.1 through 2.4. This will also get | + # rid of the maintenance nightmare that came with C's | + # "long long" type on various platforms. | # 20MAY2005 bga - Fixed code so that a DateTimeDelta is returned for a | # PostgreSQL time datatype. | *************** *** 430,433 **** --- 435,444 ---- noWeakRef = 1 + # Define boolean constants for old Python versions + try: + True + except: + True, False = 1, 0 + try: from mx import DateTime *************** *** 1969,2137 **** return 'NULL' ! #-----------------------------------------------------------------------+ ! # Name: PgInt8 | ! # | ! # Description: A Python wrapper class for the PostgreSQL int8 type. | ! # It's primary purpose it to check for overflow during | ! # calulations. | ! # | ! # Note: The PgInt8 class uses a Python Long Integer to hold | ! # the PostgreSQL int8 type. | ! # | ! # Note: This class will only be defined if the C implementation | ! # of the PgInt8 object was not imported with/from libpq. | ! #-----------------------------------------------------------------------+ ! ! if dir().count('PgInt8') == 0: # Only define this class is PgInt8 wasn't ! # brought in via libpq. ! class PgInt8: ! def __init__(self, value): ! if value is None: ! self.value = value ! return ! ! self.value = long(value) ! if self.value < -9223372036854775808L or \ ! self.value > 9223372936854775807L: ! raise OverflowError, 'int8 initialization' ! ! def __checkresult(self, value, op): ! if value < -9223372036854775808L or value > 9223372936854775807L: ! raise OverflowError, 'int8 %s' % op ! return PgInt8(value) ! ! def __coerce__(self, other): ! if other is None: ! return None ! res = coerce(self.value, other) ! if res is None: ! return None ! _s, _o = res ! return (self, _o) ! ! def __hash__(self): ! return hash(self.value) ! ! def __cmp__(self, other): ! return cmp(self.value, other) ! ! def __nonzero__(self): ! return self.value != 0 ! ! def __add__(self, other): ! return self.__checkresult(self.value + other, "addition") ! ! def __sub__(self, other): ! return self.__checkresult(self.value - other, "subtraction") ! ! def __mul__(self, other): ! return self.__checkresult(self.value * other, "mulitplication") ! ! def __div__(self, other): ! return self.__checkresult(self.value / other, "division") ! ! def __divmod__(self, other): ! _a, _b = divmod(self.value, other) ! return (self.__checkresult(_a, "divmod"), _b) ! ! def __pow__(self, other, modulus=None): ! return self.__checkresult(pow(self.value, other, modulus), "pow") ! ! def __lshift__(self, other): ! return self.__checkresult(self.value << other, 'lshift') ! ! def __rshift__(self, other): ! return self.__checkresult(self.value >> other, 'rshift') ! ! def __and__(self, other): ! return self.__checkresult(self.value & other, 'and') ! ! def __xor__(self, other): ! return self.__checkresult(self.value ^ other, 'xor') ! ! def __or__(self, other): ! return self.__checkresult(self.value | other, 'or') ! ! def __radd__(self, other): ! return self.__checkresult(other + self.value, "addition") ! ! def __rsub__(self, other): ! return self.__checkresult(other - self.value, "subtraction") ! ! def __rmul__(self, other): ! return self.__checkresult(other * self.value, "mulitplication") ! ! def __rdiv__(self, other): ! return self.__checkresult(other / self.value, "division") ! ! def __rdivmod__(self, other): ! _a, _b = divmod(other, self.value) ! return (self.__checkresult(_a, "divmod"), ! self.__checkresult(_b, "divmod")) ! ! def __rpow__(self, other, modulus=None): ! return self.__checkresult(pow(other, self.value, modulus), "pow") ! ! def __rlshift__(self, other): ! return self.__checkresult(other << self.value, 'lshift') ! ! def __rrshift__(self, other): ! return self.__checkresult(other >> self.value, 'rshift') ! ! def __rand__(self, other): ! return self.__checkresult(other & self.value, 'and') ! ! def __rxor__(self, other): ! return self.__checkresult(other ^ self.value, 'xor') ! ! def __ror__(self, other): ! return self.__checkresult(other | self.value, 'or') ! ! def __neg__(self): ! return self.__checkresult(neg(self.value), 'neg') ! ! def __pos__(self): ! return self.__checkresult(pos(self.value), 'pos') ! ! def __abs__(self): ! return self.__checkresult(abs(self.value), 'abs') ! ! def __complex__(self): ! return complex(self) ! ! def __int__(self): ! return int(self.value) ! ! def __long__(self): ! return self.value # PgInt8 is already a Long. ! ! def __float__(self): ! return float(self.value) ! ! def __complex__(self): ! return complex(self.value) ! ! def __hex__(self): ! return hex(self.value) ! ! def __oct__(self): ! return oct(self.value) ! ! def __repr__(self): ! return repr(self.value) ! ! def __str__(self): ! return str(self.value) ! ! def _quote(self, forArray=0): ! if self.value is not None: ! s = str(self.value) ! if s[-1:] == "L": ! s = s[:-1] ! return "%s" % s ! return 'NULL' ! PgInt8Type = PgInt8 #-----------------------------------------------------------------------+ --- 1980,1992 ---- return 'NULL' ! # PgInt2 and PgInt8 used to be custom number types that checked for overflows ! # in their specific ranges. In order to make them work across current Python ! # versions we got rid of them and replaced them with int and long. ! PgInt2 = int ! PgInt2Type = IntType + PgInt8 = long + PgInt8Type = LongType #-----------------------------------------------------------------------+ Index: __init__.py =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pyPgSQL/__init__.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** __init__.py 14 Jul 2003 21:25:34 -0000 1.5 --- __init__.py 1 Jun 2006 14:42:51 -0000 1.6 *************** *** 32,34 **** """ ! __version__ = "2.4" --- 32,34 ---- """ ! __version__ = "2.5" |