summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-06-03 23:43:22 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-06-03 23:43:22 (GMT)
commit7b1ddca380158f2217824bacf30a5e90a90c6696 (patch)
treeead581b79e0aebbb7df3dcacc815d50a1d62b317 /Demo
parent0b4e554be5e3730f16d0575f81757a81254be214 (diff)
downloadcpython-7b1ddca380158f2217824bacf30a5e90a90c6696.zip
cpython-7b1ddca380158f2217824bacf30a5e90a90c6696.tar.gz
cpython-7b1ddca380158f2217824bacf30a5e90a90c6696.tar.bz2
This demo requires Medusa (not just asyncore); remove it
Diffstat (limited to 'Demo')
-rw-r--r--Demo/xmlrpc/xmlrpc_handler.py104
1 files changed, 0 insertions, 104 deletions
diff --git a/Demo/xmlrpc/xmlrpc_handler.py b/Demo/xmlrpc/xmlrpc_handler.py
deleted file mode 100644
index 359d6f1..0000000
--- a/Demo/xmlrpc/xmlrpc_handler.py
+++ /dev/null
@@ -1,104 +0,0 @@
-#
-# XML-RPC SERVER
-# $Id$
-#
-# an asynchronous XML-RPC server for Medusa
-#
-# written by Sam Rushing
-#
-# Based on "xmlrpcserver.py" by Fredrik Lundh (fredrik@pythonware.com)
-#
-
-import http_server
-import xmlrpclib
-
-import sys
-
-class xmlrpc_handler:
-
- def match (self, request):
- # Note: /RPC2 is not required by the spec, so you may override this method.
- if request.uri[:5] == '/RPC2':
- return 1
- else:
- return 0
-
- def handle_request (self, request):
- [path, params, query, fragment] = request.split_uri()
-
- if request.command.lower() in ('post', 'put'):
- request.collector = collector (self, request)
- else:
- request.error (400)
-
- def continue_request (self, data, request):
- params, method = xmlrpclib.loads (data)
- try:
- # generate response
- try:
- response = self.call (method, params)
- response = (response,)
- except:
- # report exception back to server
- response = xmlrpclib.dumps (
- xmlrpclib.Fault (1, "%s:%s" % sys.exc_info()[:2])
- )
- else:
- response = xmlrpclib.dumps (response, methodresponse=1)
- except:
- # internal error, report as HTTP server error
- request.error (500)
- else:
- # got a valid XML RPC response
- request['Content-Type'] = 'text/xml'
- request.push (response)
- request.done()
-
- def call (self, method, params):
- # override this method to implement RPC methods
- raise "NotYetImplemented"
-
-class collector:
-
- "gathers input for POST and PUT requests"
-
- def __init__ (self, handler, request):
-
- self.handler = handler
- self.request = request
- self.data = ''
-
- # make sure there's a content-length header
- cl = request.get_header ('content-length')
-
- if not cl:
- request.error (411)
- else:
- cl = int (cl)
- # using a 'numeric' terminator
- self.request.channel.set_terminator (cl)
-
- def collect_incoming_data (self, data):
- self.data = self.data + data
-
- def found_terminator (self):
- # set the terminator back to the default
- self.request.channel.set_terminator ('\r\n\r\n')
- self.handler.continue_request (self.data, self.request)
-
-if __name__ == '__main__':
-
- class rpc_demo (xmlrpc_handler):
-
- def call (self, method, params):
- print 'method="%s" params=%s' % (method, params)
- return "Sure, that works"
-
- import asyncore
- import http_server
-
- hs = http_server.http_server ('', 8000)
- rpc = rpc_demo()
- hs.install_handler (rpc)
-
- asyncore.loop()