[Spambayes] example usage of sb_xmlrpcsrv.py?
j.beyer at web.de
Fri Mar 17 21:48:49 CET 2006
Tony Meyer wrote:
>>>> I am looking for example usage of sb_xmlrpcsrv.py.
>>> I presume you mean sb_xmlrpcserver.py.
>> yes - the FAQ spells it to sb_xmlrpcsrv.py, see
> Thanks; I'll fix that.
>>>> Is there any sample code available to train a given mail as ham/ spam?
>>> Have you looked at sb_client.py? It classifies rather than trains,
>>> it's not particularly different.
>> Thanks for that hint. Now digged deeper into sb_xmlrpcserver.py and I
>> see, that the hammie.Hammie.train() method is not available. I think
>> a patch like this is needed:
>> --- sb_xmlrpcserver.py,orig 2006-03-14 10:20:15.000000000 +0100
>> +++ sb_xmlrpcserver.py 2006-03-14 10:44:34.629148074 +0100
>> @@ -60,6 +60,16 @@
>> return xmlrpclib.Binary(hammie.Hammie.filter(self, msg,
>> + def train(self, msg, is_spam):
>> + try:
>> + msg = msg.data
>> + except AttributeError:
>> + pass
>> + hammie.Hammie.train(self, msg, is_spam)
> As in the previous email, you'll also need to store() the classifier
> here, or the changes won't be saved to disk.
>> + # how do I return "nothing"? (in C this would be a void
>> + return xmlrpclib.Boolean(True)
>> def usage(code, msg=''):
>> """Print usage message and sys.exit(code)."""
>> A minor issue is, that I dont know, how I could return nothing (None?)
>> from that xmlrpc call - so I return a boolean True.
> You either just use "return" by itself (generally what is done) or you
> can explicitly "return None" if that's what you'd rather do. In this
> case, you're returning at the end of the method, so you don't have to
> have a return call at all. For example:
> + def train(self, msg, is_spam):
> + try:
> + msg = msg.data
> + except AttributeError:
> + pass
> + hammie.Hammie.train(self, msg, is_spam)
> + hammie.Hammie.store()
I get this error message:
<Fault 1: 'exceptions.TypeError:unbound method store() must be called
with Hammie instance as first argument (got nothing instead)'>
(on the xmlrpc client side).
so I changed the suggested store call to:
is that right?
then I got this error message:
<Fault 1: 'exceptions.TypeError:cannot marshal None unless allow_none is
I had to put in the return again:
with the hammie.Hammie.store(self) call the data is written back to
disk and the feedback to spambayes via an imap client (as I described
in another thread) works.
> Would be all that is needed.
>> Would such a patch be accepted?
> Yes. I'll try and find time to check this in.
thanks for that.
thank for you help
More information about the SpamBayes