Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16690

Modified Files:
      Tag: CORESVR
        XMLRPCPlugin.py 
Log Message:
cache messages
make xmlrpc thread a daemon
convert msg text to utf-8 string if it's unicode


Index: XMLRPCPlugin.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/Attic/XMLRPCPlugin.py,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -d -r1.1.2.6 -r1.1.2.7
*** XMLRPCPlugin.py     5 Jun 2007 02:43:41 -0000       1.1.2.6
--- XMLRPCPlugin.py     6 Jun 2007 03:37:37 -0000       1.1.2.7
***************
*** 46,49 ****
--- 46,50 ----
  from spambayes.Options import _, options
  from spambayes.tokenizer import tokenize
+ import spambayes.message
  
  class XMLRPCUI(PluginUI):
***************
*** 66,69 ****
--- 67,71 ----
          self.server.register_instance(self)
          self.thread = threading.Thread(target=self.server.serve_forever)
+         self.thread.setDaemon(True)
          self.thread.start()
  
***************
*** 79,97 ****
          return self.score_mime(mime_message)
  
!     def score_mime(self, msg, encoding):
          """Score a message representing a MIME document.
  
          The msg argument will be a string in the given encoding.
          """
-         tokens = self.tokenize(msg, encoding)
-         return self.state.bayes.spamprob(tokens, evidence=True)
  
!     def tokenize(self, msg, encoding):
!         """Tokenize the message.  Make sure the bayes instance is 
available."""
          if self.state.bayes is None:
              self.state.create_workers()
!         msg = unicode(msg, encoding)
!         msg = message_from_string(msg)
!         return tokenize(msg)
  
  def form_to_mime(form, mime_type, extra_tokens):
--- 81,114 ----
          return self.score_mime(mime_message)
  
!     def score_mime(self, msg_text, encoding):
          """Score a message representing a MIME document.
  
          The msg argument will be a string in the given encoding.
          """
  
!         # XXX Much of this probably belongs in the core server...
! 
          if self.state.bayes is None:
              self.state.create_workers()
!         if isinstance(msg_text, unicode):
!             msg_text = msg_text.encode("utf-8")
!         msg = message_from_string(msg_text,
!                                   _class=spambayes.message.SBHeaderMessage)
! 
!         tokens = tokenize(msg)
! 
!         # XXX Maybe from here on down...
! 
!         prob = self.state.bayes.spamprob(tokens, evidence=False)
!         self.state.record_classification(msg.GetClassification(), prob)
! 
!         # Cache the message.
!         if not self.state.is_test and options["Storage", "cache_messages"]:
!             msg.setId(self.state.getNewMessageName())
!             # Write the message into the Unknown cache.
!             makeMessage = self.state.unknownCorpus.makeMessage
!             message = makeMessage(msg.getId(), msg.as_string())
!             self.state.unknownCorpus.addMessage(message)
!         return prob
  
  def form_to_mime(form, mime_type, extra_tokens):

_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to