Use cPickle and the binary format.
authorAdam Sampson <ats@offog.org>
Wed, 28 Jul 2004 12:11:33 +0000 (12:11 +0000)
committerAdam Sampson <ats@offog.org>
Wed, 28 Jul 2004 12:11:33 +0000 (12:11 +0000)
rawdoglib/persister.py

index 230725d78194ab3b9f6e02ba208c11a887bb45cf..edc9ee952ebff8ad2f517447c1faeba36df0ff2c 100644 (file)
@@ -16,7 +16,8 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place, Suite
 # 330, Boston, MA 02111-1307 USA, or see http://www.gnu.org/.
 
-import pickle, fcntl
+import fcntl
+import cPickle as pickle
 
 class Persistable:
        """Something which can be persisted. When a subclass of this wants to
@@ -56,6 +57,11 @@ class Persister:
                if self.object.is_modified():
                        self.file.seek(0)
                        self.file.truncate(0)
-                       pickle.dump(self.object, self.file)
+                       try:
+                               pickle.dump(self.object, self.file, pickle.HIGHEST_PROTOCOL)
+                       except AttributeError:
+                               # Python 2.2 doesn't have the protocol
+                               # argument.
+                               pickle.dump(self.object, self.file, True)
                self.file.close()