[Spambayes-checkins] spambayes/spambayes message.py,1.58,1.59
Tony Meyer
anadelonbrin at users.sourceforge.net
Fri Nov 26 00:19:07 CET 2004
- Previous message: [Spambayes-checkins] spambayes/spambayes __init__.py,1.11,1.12
- Next message: [Spambayes-checkins] spambayes/Outlook2000 addin.py, 1.138,
1.139 manager.py, 1.98, 1.99 msgstore.py, 1.88, 1.89 tester.py,
1.23, 1.24 train.py, 1.39, 1.40
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22222/spambayes
Modified Files:
message.py
Log Message:
Use cPickle when possible.
Handle loading an Outlook messageinfo database.
Add a __len__ function to the messageinfo databases.
The messageinfo db now needs messages to have a GetDBKey function to determine the
key to store the message under. For our message classes, this is just the same as
getId().
Index: message.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/message.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** message.py 22 Nov 2004 23:34:43 -0000 1.58
--- message.py 25 Nov 2004 23:19:04 -0000 1.59
***************
*** 81,84 ****
--- 81,85 ----
import os
+ import sys
import types
import math
***************
*** 86,90 ****
import errno
import shelve
! import pickle
import traceback
--- 87,94 ----
import errno
import shelve
! try:
! import cPickle as pickle
! except ImportError:
! import pickle
import traceback
***************
*** 110,125 ****
self.db_name = db_name
def load_msg(self, msg):
if self.db is not None:
try:
! attributes = self.db[msg.getId()]
except KeyError:
! pass
else:
if not isinstance(attributes, types.ListType):
! # Old-style message info db, which only
! # handles storing 'c' and 't'.
! (msg.c, msg.t) = attributes
! return
for att, val in attributes:
setattr(msg, att, val)
--- 114,152 ----
self.db_name = db_name
+ def __len__(self):
+ return len(self.db)
+
def load_msg(self, msg):
if self.db is not None:
try:
! try:
! attributes = self.db[msg.getDBKey()]
! except pickle.UnpicklingError:
! # The old-style Outlook message info db didn't use
! # shelve, so get it straight from the dbm.
! if hasattr(self, "dbm"):
! attributes = self.dbm[msg.getDBKey()]
! else:
! raise
except KeyError:
! # Set to None, as it's not there.
! for att in msg.stored_attributes:
! setattr(msg, att, None)
else:
if not isinstance(attributes, types.ListType):
! # Old-style message info db
! if isinstance(attributes, types.TupleType):
! # sb_server/sb_imapfilter, which only handled
! # storing 'c' and 't'.
! (msg.c, msg.t) = attributes
! return
! elif isinstance(attributes, types.StringTypes):
! # Outlook plug-in, which only handled storing 't',
! # and did it as a string.
! msg.t = {"0" : False, "1" : True}[attributes]
! return
! else:
! print >> sys.stderr, "Unknown message info type"
! sys.exit(1)
for att, val in attributes:
setattr(msg, att, val)
***************
*** 130,139 ****
for att in msg.stored_attributes:
attributes.append((att, getattr(msg, att)))
! self.db[msg.getId()] = attributes
self.store()
def remove_msg(self, msg):
if self.db is not None:
! del self.db[msg.getId()]
self.store()
--- 157,166 ----
for att in msg.stored_attributes:
attributes.append((att, getattr(msg, att)))
! self.db[msg.getDBKey()] = attributes
self.store()
def remove_msg(self, msg):
if self.db is not None:
! del self.db[msg.getDBKey()]
self.store()
***************
*** 241,244 ****
--- 268,272 ----
self.message_info_db = open_storage(nm, typ)
self.stored_attributes = ['c', 't',]
+ self.getDBKey = self.getId
self.id = None
self.c = None
- Previous message: [Spambayes-checkins] spambayes/spambayes __init__.py,1.11,1.12
- Next message: [Spambayes-checkins] spambayes/Outlook2000 addin.py, 1.138,
1.139 manager.py, 1.98, 1.99 msgstore.py, 1.88, 1.89 tester.py,
1.23, 1.24 train.py, 1.39, 1.40
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Spambayes-checkins
mailing list