[Python-checkins] python/dist/src/Lib shelve.py,1.17,1.18

montanaro@users.sourceforge.net montanaro@users.sourceforge.net
Sun, 08 Dec 2002 10:36:26 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv2668/Lib

Modified Files:
	shelve.py 
Log Message:
Add support for binary pickles to the shelve module.  In some situations
this can result in significantly smaller files.  All classes as well as the
open function now accept an optional binary parameter, which defaults to
False for backward compatibility.  Added a small test suite, updated the
libref documentation (including documenting the exported classes and fixing
a few other nits) and added a note about the change to Misc/NEWS.



Index: shelve.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/shelve.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** shelve.py	15 Nov 2002 06:46:14 -0000	1.17
--- shelve.py	8 Dec 2002 18:36:24 -0000	1.18
***************
*** 52,57 ****
      """
  
!     def __init__(self, dict):
          self.dict = dict
  
      def keys(self):
--- 52,58 ----
      """
  
!     def __init__(self, dict, binary=False):
          self.dict = dict
+         self.binary = binary
  
      def keys(self):
***************
*** 78,82 ****
      def __setitem__(self, key, value):
          f = StringIO()
!         p = Pickler(f)
          p.dump(value)
          self.dict[key] = f.getvalue()
--- 79,83 ----
      def __setitem__(self, key, value):
          f = StringIO()
!         p = Pickler(f, self.binary)
          p.dump(value)
          self.dict[key] = f.getvalue()
***************
*** 113,118 ****
      """
  
!     def __init__(self, dict):
!         Shelf.__init__(self, dict)
  
      def set_location(self, key):
--- 114,119 ----
      """
  
!     def __init__(self, dict, binary=False):
!         Shelf.__init__(self, dict, binary)
  
      def set_location(self, key):
***************
*** 149,158 ****
      """
  
!     def __init__(self, filename, flag='c'):
          import anydbm
!         Shelf.__init__(self, anydbm.open(filename, flag))
  
  
! def open(filename, flag='c'):
      """Open a persistent dictionary for reading and writing.
  
--- 150,159 ----
      """
  
!     def __init__(self, filename, flag='c', binary=False):
          import anydbm
!         Shelf.__init__(self, anydbm.open(filename, flag), binary)
  
  
! def open(filename, flag='c', binary=False):
      """Open a persistent dictionary for reading and writing.
  
***************
*** 161,163 ****
      """
  
!     return DbfilenameShelf(filename, flag)
--- 162,164 ----
      """
  
!     return DbfilenameShelf(filename, flag, binary)