[Spambayes-checkins] spambayes/spambayes storage.py,1.22,1.23
Skip Montanaro
montanaro at users.sourceforge.net
Mon Aug 25 13:08:59 EDT 2003
Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv13358
Modified Files:
storage.py
Log Message:
push all prints to sys.stderr and include a comment for future authors
to do the same
Index: storage.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/storage.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** storage.py 25 Aug 2003 15:31:39 -0000 1.22
--- storage.py 25 Aug 2003 19:08:57 -0000 1.23
***************
*** 47,50 ****
--- 47,54 ----
# Foundation license.
+ ### Note to authors - please direct all prints to sys.stderr. In some
+ ### situations prints to sys.stdout will garble the message (e.g., in
+ ### hammiefilter).
+
__author__ = "Neale Pickett <neale at woozle.org>, \
Tim Stone <tim at fourstonesExpressions.com>"
***************
*** 59,62 ****
--- 63,67 ----
return not not val
+ import sys
from spambayes import classifier
from spambayes.Options import options
***************
*** 97,101 ****
if options.verbose:
! print 'Loading state from',self.db_name,'pickle'
tempbayes = None
--- 102,106 ----
if options.verbose:
! print >> sys.stderr, 'Loading state from',self.db_name,'pickle'
tempbayes = None
***************
*** 115,124 ****
tempbayes.__getstate__())
if options.verbose:
! print '%s is an existing pickle, with %d ham and %d spam' \
% (self.db_name, self.nham, self.nspam)
else:
# new pickle
if options.verbose:
! print self.db_name,'is a new pickle'
self.wordinfo = {}
self.nham = 0
--- 120,130 ----
tempbayes.__getstate__())
if options.verbose:
! print >> sys.stderr, ('%s is an existing pickle,'
! ' with %d ham and %d spam') \
% (self.db_name, self.nham, self.nspam)
else:
# new pickle
if options.verbose:
! print >> sys.stderr, self.db_name,'is a new pickle'
self.wordinfo = {}
self.nham = 0
***************
*** 129,133 ****
if options.verbose:
! print 'Persisting',self.db_name,'as a pickle'
fp = open(self.db_name, 'wb')
--- 135,139 ----
if options.verbose:
! print >> sys.stderr, 'Persisting',self.db_name,'as a pickle'
fp = open(self.db_name, 'wb')
***************
*** 155,159 ****
if options.verbose:
! print 'Loading state from',self.db_name,'database'
self.dbm = dbmstorage.open(self.db_name, self.mode)
--- 161,165 ----
if options.verbose:
! print >> sys.stderr, 'Loading state from',self.db_name,'database'
self.dbm = dbmstorage.open(self.db_name, self.mode)
***************
*** 167,176 ****
if options.verbose:
! print '%s is an existing database, with %d spam and %d ham' \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options.verbose:
! print self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
--- 173,183 ----
if options.verbose:
! print >> sys.stderr, ('%s is an existing database,'
! ' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options.verbose:
! print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
***************
*** 182,186 ****
if options.verbose:
! print 'Persisting',self.db_name,'state in database'
# Iterate over our changed word list.
--- 189,193 ----
if options.verbose:
! print >> sys.stderr, 'Persisting',self.db_name,'state in database'
# Iterate over our changed word list.
***************
*** 306,310 ****
(word,))
except Exception, e:
! print "error:", (e, word)
raise
rows = self.fetchall(c)
--- 313,317 ----
(word,))
except Exception, e:
! print >> sys.stderr, "error:", (e, word)
raise
rows = self.fetchall(c)
***************
*** 392,396 ****
if options.verbose:
! print 'Loading state from',self.db_name,'database'
self.db = psycopg.connect(self.db_name)
--- 399,403 ----
if options.verbose:
! print >> sys.stderr, 'Loading state from',self.db_name,'database'
self.db = psycopg.connect(self.db_name)
***************
*** 408,417 ****
self.nham = row["nham"]
if options.verbose:
! print '%s is an existing database, with %d spam and %d ham' \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options.verbose:
! print self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
--- 415,425 ----
self.nham = row["nham"]
if options.verbose:
! print >> sys.stderr, ('%s is an existing database,'
! ' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options.verbose:
! print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
***************
*** 462,466 ****
if options.verbose:
! print 'Loading state from',self.db_name,'database'
self.db = MySQLdb.connect(host=self.host, db=self.db_name,
--- 470,474 ----
if options.verbose:
! print >> sys.stderr, 'Loading state from',self.db_name,'database'
self.db = MySQLdb.connect(host=self.host, db=self.db_name,
***************
*** 479,488 ****
self.nham = int(row[2])
if options.verbose:
! print '%s is an existing database, with %d spam and %d ham' \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options.verbose:
! print self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
--- 487,497 ----
self.nham = int(row[2])
if options.verbose:
! print >> sys.stderr, ('%s is an existing database,'
! ' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options.verbose:
! print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
***************
*** 521,525 ****
if options.verbose:
! print 'training with',message.key()
self.bayes.learn(message.tokenize(), self.is_spam)
--- 530,534 ----
if options.verbose:
! print >> sys.stderr, 'training with',message.key()
self.bayes.learn(message.tokenize(), self.is_spam)
***************
*** 535,539 ****
if options.verbose:
! print 'untraining with',message.key()
self.bayes.unlearn(message.tokenize(), self.is_spam)
--- 544,548 ----
if options.verbose:
! print >> sys.stderr, 'untraining with',message.key()
self.bayes.unlearn(message.tokenize(), self.is_spam)
***************
*** 614,620 ****
# We expect this to hit a fair few people, so warn them nicely,
# rather than just printing the trackback.
! print """You do not have a dbm module available to use. You
! need to either use a pickle (see the FAQ), use Python 2.3 (or above), or
! install a dbm module such as bsddb (see http://sf.net/projects/pybsddb)."""
import sys
sys.exit()
--- 623,630 ----
# We expect this to hit a fair few people, so warn them nicely,
# rather than just printing the trackback.
! print >> sys.stderr, """\
! You do not have a dbm module available to use. You need to either use a
! pickle (see the FAQ), use Python 2.3 (or above), or install a dbm module
! such as bsddb (see http://sf.net/projects/pybsddb)."""
import sys
sys.exit()
More information about the Spambayes-checkins
mailing list