[Spambayes-checkins] spambayes/scripts sb_xmlrpcserver.py, 1.1, 1.1.2.1

Tony Meyer anadelonbrin at users.sourceforge.net
Wed Sep 24 02:39:21 EDT 2003


Update of /cvsroot/spambayes/spambayes/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv11527/scripts

Modified Files:
      Tag: release_1_0
	sb_xmlrpcserver.py 
Log Message:
Bring sb_xmlrpcserver into line with the rest of the spambayes world.

This is pretty much the diff that Skip posted to the list, with a couple
of minor changes.  Apparently it didn't work for him, but it works fine
for me (with sb_client.py).

Index: sb_xmlrpcserver.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_xmlrpcserver.py,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -C2 -d -r1.1 -r1.1.2.1
*** sb_xmlrpcserver.py	5 Sep 2003 01:16:46 -0000	1.1
--- sb_xmlrpcserver.py	24 Sep 2003 06:39:19 -0000	1.1.2.1
***************
*** 11,19 ****
      -p FILE
          use file as the persistent store.  loads data from this file if it
!         exists, and saves data to this file at the end.  Default: %(DEFAULTDB)s
      -d
!         use the DBM store instead of cPickle.  The file is larger and
!         creating it is slower, but checking against it is much faster,
!         especially for large word databases.
  
      IP
--- 11,17 ----
      -p FILE
          use file as the persistent store.  loads data from this file if it
!         exists, and saves data to this file at the end.
      -d
!         use the DBM store instead of cPickle.
  
      IP
***************
*** 23,26 ****
--- 21,25 ----
  """
  
+ import os
  import SimpleXMLRPCServer
  import getopt
***************
*** 28,32 ****
  import traceback
  import xmlrpclib
! from spambayes import hammie
  
  try:
--- 27,33 ----
  import traceback
  import xmlrpclib
! 
! from spambayes import hammie, Options
! from spambayes.storage import open_storage
  
  try:
***************
*** 39,45 ****
  program = sys.argv[0] # For usage(); referenced by docstring above
  
- # Default DB path
- DEFAULTDB = hammie.DEFAULTDB
- 
  class XMLHammie(hammie.Hammie):
      def score(self, msg, *extra):
--- 40,43 ----
***************
*** 58,108 ****
  
  
- class HammieHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
-     def do_POST(self):
-         """Handles the HTTP POST request.
- 
-         Attempts to interpret all HTTP POST requests as XML-RPC calls,
-         which are forwarded to the _dispatch method for handling.
- 
-         This one also prints out tracebacks, to help me debug :)
-         """
- 
-         try:
-             # get arguments
-             data = self.rfile.read(int(self.headers["content-length"]))
-             params, method = xmlrpclib.loads(data)
- 
-             # generate response
-             try:
-                 response = self._dispatch(method, params)
-                 # wrap response in a singleton tuple
-                 response = (response,)
-             except:
-                 traceback.print_exc()
-                 # report exception back to server
-                 response = xmlrpclib.dumps(
-                     xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value))
-                     )
-             else:
-                 response = xmlrpclib.dumps(response, methodresponse=1)
-         except:
-             # internal error, report as HTTP server error
-             traceback.print_exc()
-             print `data`
-             self.send_response(500)
-             self.end_headers()
-         else:
-             # got a valid XML RPC response
-             self.send_response(200)
-             self.send_header("Content-type", "text/xml")
-             self.send_header("Content-length", str(len(response)))
-             self.end_headers()
-             self.wfile.write(response)
- 
-             # shut down the connection
-             self.wfile.flush()
-             self.connection.shutdown(1)
- 
- 
  def usage(code, msg=''):
      """Print usage message and sys.exit(code)."""
--- 56,59 ----
***************
*** 110,114 ****
          print >> sys.stderr, msg
          print >> sys.stderr
!     print >> sys.stderr, __doc__ % globals()
      sys.exit(code)
  
--- 61,65 ----
          print >> sys.stderr, msg
          print >> sys.stderr
!     print >> sys.stderr, __doc__
      sys.exit(code)
  
***************
*** 121,131 ****
          usage(2, msg)
  
!     pck = DEFAULTDB
!     usedb = False
      for opt, arg in opts:
          if opt == '-h':
              usage(0)
          elif opt == '-p':
!             pck = arg
          elif opt == "-d":
              usedb = True
--- 72,85 ----
          usage(2, msg)
  
!     options = Options.options
! 
!     dbname = options["Storage", "persistent_storage_file"]
!     dbname = os.path.expanduser(dbname)
!     usedb = options["Storage", "persistent_use_database"]
      for opt, arg in opts:
          if opt == '-h':
              usage(0)
          elif opt == '-p':
!             dbname = arg
          elif opt == "-d":
              usedb = True
***************
*** 137,144 ****
      port = int(port)
  
!     bayes = hammie.createbayes(pck, usedb)
      h = XMLHammie(bayes)
  
!     server = SimpleXMLRPCServer.SimpleXMLRPCServer((ip, port), HammieHandler)
      server.register_instance(h)
      server.serve_forever()
--- 91,99 ----
      port = int(port)
  
!     bayes = open_storage(dbname, usedb)
      h = XMLHammie(bayes)
  
!     server = SimpleXMLRPCServer.SimpleXMLRPCServer((ip, port),
!                                                    SimpleXMLRPCServer.SimpleXMLRPCRequestHandler)
      server.register_instance(h)
      server.serve_forever()





More information about the Spambayes-checkins mailing list