SVN: r25693 - trunk/quixote/doc

David Binger <dbinger-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Mon, 6 Dec 2004 19:02:12 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: dbinger
Date: 2004-11-30 15:43:36 -0500 (Tue, 30 Nov 2004)
New Revision: 25693

Modified:
   trunk/quixote/doc/web-services.txt
Log:
Attempt to update web-services.txt to the Quixote 2 pattern.


Modified: trunk/quixote/doc/web-services.txt
===================================================================
--- trunk/quixote/doc/web-services.txt	2004-11-30 20:34:34 UTC (rev 25692)
+++ trunk/quixote/doc/web-services.txt	2004-11-30 20:43:36 UTC (rev 25693)
@@ -17,16 +17,16 @@
 standard data types and the XML-RPC data types.
 
 ==============  =====================
-XML-RPC Type	Python Type or Class
+XML-RPC Type    Python Type or Class
 --------------  ---------------------
-<int>		int
-<double>	float
-<string>	string
-<array>		list
-<struct>	dict
-<boolean>	xmlrpclib.Boolean
-<base64>	xmlrpclib.Binary
-<dateTime>	xmlrpclib.DateTime
+<int>       int
+<double>    float
+<string>    string
+<array>     list
+<struct>    dict
+<boolean>   xmlrpclib.Boolean
+<base64>    xmlrpclib.Binary
+<dateTime>  xmlrpclib.DateTime
 ==============  =====================
 
 
@@ -82,13 +82,17 @@
 single method, ``get_time()``, that simply returns the current
 time.  The first task is to expose a URL for accessing the service. ::
 
+    from quixote.directory import Directory
     from quixote.util import xmlrpc
+    from quixote import get_request
 
-    _q_exports = ['rpc']
+    class RPCDirectory(Directory):
 
-    def rpc (request):
-        return xmlrpc(request, rpc_process)
+        _q_exports = ['rpc']
 
+        def rpc (self):
+            return xmlrpc(get_request(), rpc_process)
+
     def rpc_process (meth, params):
         ...
 
@@ -102,12 +106,12 @@
     import time
 
     def rpc_process (meth, params):
-	if meth == 'get_time':
-	    # params is ignored
-	    now = time.gmtime(time.time())
-	    return xmlrpclib.DateTime(now)
-	else:
-	    raise RuntimeError, "Unknown XML-RPC method: %r" % meth
+        if meth == 'get_time':
+            # params is ignored
+            now = time.gmtime(time.time())
+            return xmlrpclib.DateTime(now)
+        else:
+            raise RuntimeError, "Unknown XML-RPC method: %r" % meth
 
 ``rpc_process()`` receives the method name and the parameters, and its
 job is to run the right code for the method, returning a result that
@@ -139,24 +143,24 @@
 to the keys of this dictionary::
 
     def echo (*params):
-	# Just returns the parameters it's passed
-	return params
+        # Just returns the parameters it's passed
+        return params
 
     def get_time ():
-	now = time.gmtime(time.time())
-	return xmlrpclib.DateTime(now)
+        now = time.gmtime(time.time())
+        return xmlrpclib.DateTime(now)
 
     methods = {'echo' : echo, 
-	       'get_time' : get_time}
+               'get_time' : get_time}
 
     def rpc_process (meth, params):
-	func = methods.get[meth]
-	if methods.has_key(meth):
-	    # params is ignored
-	    now = time.gmtime(time.time())
-	    return xmlrpclib.DateTime(now)
-	else:
-	    raise RuntimeError, "Unknown XML-RPC method: %r" % meth
+        func = methods.get[meth]
+        if methods.has_key(meth):
+            # params is ignored
+            now = time.gmtime(time.time())
+            return xmlrpclib.DateTime(now)
+        else:
+            raise RuntimeError, "Unknown XML-RPC method: %r" % meth
 
 This approach works nicely when there are many methods and the
 ``if...elif...else`` statement would be unworkably long.