Revision: 3167
          http://spambayes.svn.sourceforge.net/spambayes/?rev=3167&view=rev
Author:   montanaro
Date:     2007-10-21 19:45:57 -0700 (Sun, 21 Oct 2007)

Log Message:
-----------
Use the new safe_pickle function to write the cache file.  Don't bomb if the
cache file can't be read for some reason.  From Dave Abrahams (SF 1816240).

Modified Paths:
--------------
    trunk/spambayes/spambayes/dnscache.py

Modified: trunk/spambayes/spambayes/dnscache.py
===================================================================
--- trunk/spambayes/spambayes/dnscache.py       2007-10-22 02:44:14 UTC (rev 
3166)
+++ trunk/spambayes/spambayes/dnscache.py       2007-10-22 02:45:57 UTC (rev 
3167)
@@ -94,9 +94,15 @@
         # end of user-settable attributes
 
         self.cachefile = os.path.expanduser(cachefile)
+        self.caches = None
+
         if self.cachefile and os.path.exists(self.cachefile):
-            self.caches = pickle.load(open(self.cachefile, "rb"))
-        else:
+            try:
+                self.caches = pickle.load(open(self.cachefile, "rb"))
+            except:
+                os.unlink(self.cachefile)
+
+        if self.caches is None:
             self.caches = {"A": {}, "PTR": {}}
 
         if options["globals", "verbose"]:
@@ -123,7 +129,8 @@
         if self.printStatsAtEnd:
             self.printStats()
         if self.cachefile:
-            pickle.dump(self.caches, open(self.cachefile, "wb"))
+            from storage import safe_pickle
+            safe_pickle(self.cachefile, self.caches)
 
     def printStats(self):
         for key,val in self.caches.items():


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.
_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to