[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.156,1.157 test_datetime.py,1.109,1.110

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Fri, 31 Jan 2003 19:02:37 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv25782

Modified Files:
	datetime.py test_datetime.py 
Log Message:
__getstate__() isn't needed for pickling anymore, but is used for other
things (like hashing and comparison), so make them private methods.  This
was done earlier for __setstate__() too.


Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.156
retrieving revision 1.157
diff -C2 -d -r1.156 -r1.157
*** datetime.py	31 Jan 2003 21:52:15 -0000	1.156
--- datetime.py	1 Feb 2003 03:02:33 -0000	1.157
***************
*** 601,608 ****
              raise TypeError, ("can't compare timedelta to %s instance" %
                                type(other).__name__)
!         return cmp(self.__getstate__(), other.__getstate__())
  
      def __hash__(self):
!         return hash(self.__getstate__())
  
      def __nonzero__(self):
--- 601,608 ----
              raise TypeError, ("can't compare timedelta to %s instance" %
                                type(other).__name__)
!         return cmp(self.__getstate(), other.__getstate())
  
      def __hash__(self):
!         return hash(self.__getstate())
  
      def __nonzero__(self):
***************
*** 615,623 ****
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate__(self):
          return (self.__days, self.__seconds, self.__microseconds)
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate__())
  
  timedelta.min = timedelta(-999999999)
--- 615,623 ----
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate(self):
          return (self.__days, self.__seconds, self.__microseconds)
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate())
  
  timedelta.min = timedelta(-999999999)
***************
*** 778,782 ****
      def __hash__(self):
          "Hash."
!         return hash(self.__getstate__())
  
      # Computations
--- 778,782 ----
      def __hash__(self):
          "Hash."
!         return hash(self.__getstate())
  
      # Computations
***************
*** 853,857 ****
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate__(self):
          yhi, ylo = divmod(self.__year, 256)
          return ("%c%c%c%c" % (yhi, ylo, self.__month, self.__day), )
--- 853,857 ----
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate(self):
          yhi, ylo = divmod(self.__year, 256)
          return ("%c%c%c%c" % (yhi, ylo, self.__month, self.__day), )
***************
*** 865,869 ****
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate__())
  
  _date_class = date  # so functions w/ args named "date" can get at the class
--- 865,869 ----
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate())
  
  _date_class = date  # so functions w/ args named "date" can get at the class
***************
*** 1038,1042 ****
          tzoff = self._utcoffset()
          if not tzoff: # zero or None
!             return hash(self.__getstate__()[0])
          h, m = divmod(self.hour * 60 + self.minute - tzoff, 60)
          if 0 <= h < 24:
--- 1038,1042 ----
          tzoff = self._utcoffset()
          if not tzoff: # zero or None
!             return hash(self.__getstate()[0])
          h, m = divmod(self.hour * 60 + self.minute - tzoff, 60)
          if 0 <= h < 24:
***************
*** 1177,1181 ****
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate__(self):
          us2, us3 = divmod(self.__microsecond, 256)
          us1, us2 = divmod(us2, 256)
--- 1177,1181 ----
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate(self):
          us2, us3 = divmod(self.__microsecond, 256)
          us1, us2 = divmod(us2, 256)
***************
*** 1201,1205 ****
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate__())
  
  _time_class = time  # so functions w/ args named "time" can get at the class
--- 1201,1205 ----
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate())
  
  _time_class = time  # so functions w/ args named "time" can get at the class
***************
*** 1561,1565 ****
          tzoff = self._utcoffset()
          if tzoff is None:
!             return hash(self.__getstate__()[0])
          days = _ymd2ord(self.year, self.month, self.day)
          seconds = self.hour * 3600 + (self.minute - tzoff) * 60 + self.second
--- 1561,1565 ----
          tzoff = self._utcoffset()
          if tzoff is None:
!             return hash(self.__getstate()[0])
          days = _ymd2ord(self.year, self.month, self.day)
          seconds = self.hour * 3600 + (self.minute - tzoff) * 60 + self.second
***************
*** 1570,1574 ****
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate__(self):
          yhi, ylo = divmod(self.__year, 256)
          us2, us3 = divmod(self.__microsecond, 256)
--- 1570,1574 ----
      __safe_for_unpickling__ = True      # For Python 2.2
  
!     def __getstate(self):
          yhi, ylo = divmod(self.__year, 256)
          us2, us3 = divmod(self.__microsecond, 256)
***************
*** 1597,1601 ****
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate__())
  
  
--- 1597,1601 ----
  
      def __reduce__(self):
!         return (self.__class__, self.__getstate())
  
  

Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.109
retrieving revision 1.110
diff -C2 -d -r1.109 -r1.110
*** test_datetime.py	31 Jan 2003 21:52:15 -0000	1.109
--- test_datetime.py	1 Feb 2003 03:02:34 -0000	1.110
***************
*** 277,282 ****
          args = 12, 34, 56
          orig = timedelta(*args)
-         state = orig.__getstate__()
-         self.assertEqual(args, state)
          for pickler, unpickler, proto in pickle_choices:
              green = pickler.dumps(orig, proto)
--- 277,280 ----
***************
*** 831,836 ****
          args = 6, 7, 23
          orig = self.theclass(*args)
-         state = orig.__getstate__()
-         self.assertEqual(state, ('\x00\x06\x07\x17',), self.theclass)
          for pickler, unpickler, proto in pickle_choices:
              green = pickler.dumps(orig, proto)
--- 829,832 ----
***************
*** 1185,1190 ****
          args = 6, 7, 23, 20, 59, 1, 64**2
          orig = self.theclass(*args)
-         state = orig.__getstate__()
-         self.assertEqual(state, ('\x00\x06\x07\x17\x14\x3b\x01\x00\x10\x00',))
          for pickler, unpickler, proto in pickle_choices:
              green = pickler.dumps(orig, proto)
--- 1181,1184 ----
***************
*** 1566,1571 ****
          args = 20, 59, 16, 64**2
          orig = self.theclass(*args)
-         state = orig.__getstate__()
-         self.assertEqual(state, ('\x14\x3b\x10\x00\x10\x00',))
          for pickler, unpickler, proto in pickle_choices:
              green = pickler.dumps(orig, proto)
--- 1560,1563 ----
***************
*** 1876,1881 ****
          args = 20, 59, 16, 64**2
          orig = self.theclass(*args)
-         state = orig.__getstate__()
-         self.assertEqual(state, ('\x14\x3b\x10\x00\x10\x00',))
          for pickler, unpickler, proto in pickle_choices:
              green = pickler.dumps(orig, proto)
--- 1868,1871 ----
***************
*** 2079,2084 ****
          args = 6, 7, 23, 20, 59, 1, 64**2
          orig = self.theclass(*args)
-         state = orig.__getstate__()
-         self.assertEqual(state, ('\x00\x06\x07\x17\x14\x3b\x01\x00\x10\x00',))
          for pickler, unpickler, proto in pickle_choices:
              green = pickler.dumps(orig, proto)
--- 2069,2072 ----