Changeset 97
- Timestamp:
- 12/29/04 14:03:24
- Files:
-
- trunk/ChangeLog.txt (modified) (1 diff)
- trunk/cherrypy/lib/filter/xmlrpcfilter.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog.txt
r96 r97 1 1 2004/12-29: 2 2 * CherryPY-2.0-beta released 3 * xmlrpcfilter added (Remco) 3 4 * cpg.response.body is now always an iterable type - ticket #59 (Carlos) 4 5 * Allowed default session functions to be accessed by other modules - trunk/cherrypy/lib/filter/xmlrpcfilter.py
r95 r97 1 """ 2 Copyright (c) 2004, CherryPy Team (team@cherrypy.org) 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 * Neither the name of the CherryPy Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 """ 1 13 ########################################################################## 2 ##3 ## xmlrpcfilter is as open as it can be. Do whatever you like,4 ## but understand that i take no responsibility for the code itself,5 ## nor for wat it does and especially any derivatives and when you use6 ## it, keep a copyright somewhere of me, or make notice of CherryPy7 ##8 14 ## Remco Boerma 9 15 ## 10 16 ## History: 17 ## 1.0.0 : 2004-12-29 Released with CP2 11 18 ## 0.0.9 : 2004-12-23 made it CP2 #59 compatible (returns an iterable) 12 19 ## Please note: as the xmlrpc doesn't know what you would want to return … … 53 60 ## EXAMPLE CODE FOR THE SERVER: 54 61 ## from cherrypy import cpg 55 ## import xmlrpcfilter62 ## import cherrypy.lib.xmlrpcfilter as xmlrpcfilter 56 63 ## class Root: 57 ## _cpFilterList = [xmlrpcfilter.XmlRpcFilter( mimeTypeList = ['text/xml'])]64 ## _cpFilterList = [xmlrpcfilter.XmlRpcFilter()] 58 65 ## 59 66 ## def test(self): … … 83 90 PLEASE NOTE: 84 91 85 86 -- IN CASE TICKET #28 IS NOT RESOLVED87 ANY XMLRPC FUNCTION NEEDS TO RETURN A PYTHON SOURCE STRING88 use89 return `result`90 insted of91 return result92 .93 94 -- AS ALL REQUESTS MUST RETURN A STRING (UNTIL THE FIX IS THERE)95 ALL METHODS ARE CALLABLE USING A REGULAR WEBBROWSER AS WELL!!96 97 92 afterRequestHeader: 98 93 Unmarshalls the posted data to a methodname and parameters. … … 117 112 def afterRequestHeader(self): 118 113 """ Called after the request header has been read/parsed""" 119 ## try:120 ## x = cpg.request.isRPC # should fail!121 ## print "error: afterRequestHeader is called twice!"122 ## return123 ## except:124 ## pass125 114 cpg.request.isRPC = self.testValidityOfRequest() 126 115 if not cpg.request.isRPC: 127 print 'not a valid xmlrpc call' 116 # used for debugging or more info 117 # print 'not a valid xmlrpc call' 128 118 return # break this if it's not for this filter!! 129 print "xmlrpcmethod...", 119 # used for debugging, or more info: 120 # print "xmlrpcmethod...", 130 121 cpg.request.parsePostData = 0 131 122 dataLength = int(cpg.request.headerMap.get('Content-Length',0)) 132 # ought to be true:133 # if cpg.request.method == 'POST':134 # if not, it's probabely a webbrowser requesting the url135 123 data = cpg.request.rfile.read(dataLength) 136 #else:137 # data = None138 139 # for testing: an exception may be raised as well. . an xmlrpc 'Fault' would be better though.140 124 try: 141 125 params, method = xmlrpclib.loads(data) … … 153 137 cpg.request.path+=str(method).replace('.','/') 154 138 cpg.request.paramList = list(params) 155 print "XMLRPC Filter: calling '%s' with args: '%s' " % (cpg.request.path,params) 139 # used for debugging and more info 140 # print "XMLRPC Filter: calling '%s' with args: '%s' " % (cpg.request.path,params) 156 141 157 142 def beforeResponse(self): … … 160 145 return # it's not an RPC call, so just let it go with the normal flow 161 146 try: 162 print 'beforeResponse: cpg.response.body ==',`cpg.response.body` 147 # use this for debugging and more info: 148 # print 'beforeResponse: cpg.response.body ==',`cpg.response.body` 163 149 cpg.response.body = xmlrpclib.dumps((cpg.response.body[0],), methodresponse=1,allow_none=1) 164 150 except xmlrpclib.Fault,fault:

