xmlrpcserver.py :  » IDE » Boa-Constructor » boa-constructor-0.6.1 » ExternalLib » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » Boa Constructor 
Boa Constructor » boa constructor 0.6.1 » ExternalLib » xmlrpcserver.py
#
# XML-RPC SERVER
# $Id: xmlrpcserver.py,v 1.2 2001/07/28 20:26:07 riaan Exp $
#
# a simple XML-RPC server for Python
#
# History:
# 1999-02-01 fl  added to xmlrpclib distribution 
#
# written by Fredrik Lundh, January 1999.
#
# Copyright (c) 1999 by Secret Labs AB.
# Copyright (c) 1999 by Fredrik Lundh.
#
# fredrik@pythonware.com
# http://www.pythonware.com
#
# --------------------------------------------------------------------
# Permission to use, copy, modify, and distribute this software and
# its associated documentation for any purpose and without fee is
# hereby granted.  This software is provided as is.
# --------------------------------------------------------------------
#

import SocketServer, BaseHTTPServer
import xmlrpclib
import sys

class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):

    def do_POST(self):
        try:
      # get arguments
            data = self.rfile.read(int(self.headers["content-length"]))
            params, method = xmlrpclib.loads(data)

      # generate response
      try:
    response = self.call(method, params)
    if type(response) != type(()):
        response = (response,)
      except:
    # 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
      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 (from Skip Montanaro)
      self.wfile.flush()
      self.connection.shutdown(1)

    def call(self, method, params):
  # override this method to implement RPC methods
  print "CALL", method, params
  return params

if __name__ == '__main__':
    server = SocketServer.TCPServer(('', 8000), RequestHandler)
    server.serve_forever()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.