[Spambayes-checkins] spambayes/spambayes Corpus.py,1.2,1.3
Skip Montanaro
montanaro at users.sourceforge.net
Fri Jan 17 12:02:40 EST 2003
- Previous message: [Spambayes-checkins] spambayes/spambayes/resources - New directory
- Next message: [Spambayes-checkins] spambayes/spambayes/resources
.cvsignore,NONE,1.1
__init__.py,NONE,1.1 classify.gif,NONE,1.1 classify_gif.py,NONE,1.1
config.gif,NONE,1.1 config_gif.py,NONE,1.1 helmet.gif,NONE,1.1
helmet_gif.py,NONE,1.1 message.gif,NONE,1.1 message_gif.py,NONE,1.1
query.gif,NONE,1.1 query_gif.py,NONE,1.1
scanning__init__.py,NONE,1.1 status.gif,NONE,1.1
status_gif.py,NONE,1.1 train.gif,NONE,1.1 train_gif.py,NONE,1.1
ui_html.py,NONE,1.1ui_psp.py,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv21613
Modified Files:
Corpus.py
Log Message:
* prevent infinite loop in __getattr__
* add a get() method
* punt on malformed messages - put all in payload & let header be empty
Index: Corpus.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/Corpus.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Corpus.py 14 Jan 2003 05:38:20 -0000 1.2
--- Corpus.py 17 Jan 2003 20:02:37 -0000 1.3
***************
*** 201,210 ****
self.addMessage(msg)
def __getitem__(self, key):
'''Corpus is a dictionary'''
! amsg = self.msgs[key]
! if not amsg:
amsg = self.makeMessage(key) # lazy init, saves memory
self.cacheMessage(amsg)
--- 201,216 ----
self.addMessage(msg)
+ def get(self, key, default=None):
+ try:
+ return self[key]
+ except KeyError:
+ return default
+
def __getitem__(self, key):
'''Corpus is a dictionary'''
! amsg = self.msgs.get(key)
! if amsg is None:
amsg = self.makeMessage(key) # lazy init, saves memory
self.cacheMessage(amsg)
***************
*** 280,284 ****
if attributeName in ('hdrtxt', 'payload'):
self.load()
! return getattr(self, attributeName)
def load(self):
--- 286,293 ----
if attributeName in ('hdrtxt', 'payload'):
self.load()
! try:
! return self.__dict__[attributeName]
! except KeyError:
! raise AttributeError, attributeName
def load(self):
***************
*** 325,328 ****
--- 334,341 ----
self.payload = bmatch.group(2)
self.hdrtxt = sub[:bmatch.start(2)]
+ else:
+ # malformed message - punt
+ self.payload = sub
+ self.hdrtxt = ""
def getSubstance(self):
- Previous message: [Spambayes-checkins] spambayes/spambayes/resources - New directory
- Next message: [Spambayes-checkins] spambayes/spambayes/resources
.cvsignore,NONE,1.1
__init__.py,NONE,1.1 classify.gif,NONE,1.1 classify_gif.py,NONE,1.1
config.gif,NONE,1.1 config_gif.py,NONE,1.1 helmet.gif,NONE,1.1
helmet_gif.py,NONE,1.1 message.gif,NONE,1.1 message_gif.py,NONE,1.1
query.gif,NONE,1.1 query_gif.py,NONE,1.1
scanning__init__.py,NONE,1.1 status.gif,NONE,1.1
status_gif.py,NONE,1.1 train.gif,NONE,1.1 train_gif.py,NONE,1.1
ui_html.py,NONE,1.1ui_psp.py,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Spambayes-checkins
mailing list