[Spambayes] example usage of sb_xmlrpcsrv.py?

Tony Meyer tameyer at ihug.co.nz
Fri Mar 17 21:02:57 CET 2006


>>> 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
> http://spambayes.sourceforge.net/faq.html

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,  but
>> 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 @@
>              pass
>          return xmlrpclib.Binary(hammie.Hammie.filter(self, msg,  
> *extra))
>
> +    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  
> function)
> +       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()

Would be all that is needed.

> Would such a patch be accepted?

Yes.  I'll try and find time to check this in.

=Tony.Meyer

-- 
Please always include the list (spambayes at python.org) in your replies
(reply-all), and please don't send me personal mail about SpamBayes.
http://www.massey.ac.nz/~tameyer/writing/reply_all.html explains this.




More information about the SpamBayes mailing list