[Python-checkins] python/nondist/sandbox/spambayes mboxcount.py,1.1,1.2
bwarsaw@users.sourceforge.net
bwarsaw@users.sourceforge.net
Mon, 26 Aug 2002 11:23:28 -0700
Update of /cvsroot/python/python/nondist/sandbox/spambayes
In directory usw-pr-cvs1:/tmp/cvs-serv30428
Modified Files:
mboxcount.py
Log Message:
_factory(): Use a marker object to designate between good messages and
unparseable messages. For some reason, returning None from the except
clause in _factory() caused Python 2.2.1 to exit early out of the for
loop.
main(): Print statistics about both the number of good messages and
the number of unparseable messages.
Index: mboxcount.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/spambayes/mboxcount.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** mboxcount.py 23 Aug 2002 02:36:07 -0000 1.1
--- mboxcount.py 26 Aug 2002 18:23:26 -0000 1.2
***************
*** 31,34 ****
--- 31,36 ----
program = sys.argv[0]
+ _marker = object()
+
def usage(code, msg=''):
print >> sys.stderr, __doc__
***************
*** 41,54 ****
return email.message_from_file(fp)
except email.Errors.MessageParseError:
! return None
def count(fname):
fp = open(fname, 'rb')
mbox = mailbox.PortableUnixMailbox(fp, _factory)
! count = 0
for msg in mbox:
! count += 1
fp.close()
! return count
def main():
--- 43,60 ----
return email.message_from_file(fp)
except email.Errors.MessageParseError:
! return _marker
def count(fname):
fp = open(fname, 'rb')
mbox = mailbox.PortableUnixMailbox(fp, _factory)
! goodcount = 0
! badcount = 0
for msg in mbox:
! if msg is _marker:
! badcount += 1
! else:
! goodcount += 1
fp.close()
! return goodcount, badcount
def main():
***************
*** 72,77 ****
for fname in fnames:
! n = count(fname)
! print "%-50s %7d" % (fname, n)
if __name__ == '__main__':
--- 78,83 ----
for fname in fnames:
! goodn, badn = count(fname)
! print "%-50s %7d (unparseable: %d)" % (fname, goodn, badn)
if __name__ == '__main__':