| 1 |
"""Offers a simple XML-RPC dispatcher for django_xmlrpc |
| 2 |
|
| 3 |
Author:: |
| 4 |
Graham Binns |
| 5 |
|
| 6 |
Credit must go to Brendan W. McAdams <[email protected]>, who |
| 7 |
posted the original SimpleXMLRPCDispatcher to the Django wiki: |
| 8 |
http://code.djangoproject.com/wiki/XML-RPC |
| 9 |
|
| 10 |
New BSD License |
| 11 |
=============== |
| 12 |
Copyright (c) 2007, Graham Binns http://launchpad.net/~codedragon |
| 13 |
|
| 14 |
All rights reserved. |
| 15 |
|
| 16 |
Redistribution and use in source and binary forms, with or without |
| 17 |
modification, are permitted provided that the following conditions are met: |
| 18 |
|
| 19 |
* Redistributions of source code must retain the above copyright notice, |
| 20 |
this list of conditions and the following disclaimer. |
| 21 |
* Redistributions in binary form must reproduce the above copyright notice, |
| 22 |
this list of conditions and the following disclaimer in the documentation |
| 23 |
and/or other materials provided with the distribution. |
| 24 |
* Neither the name of the <ORGANIZATION> nor the names of its contributors |
| 25 |
may be used to endorse or promote products derived from this software |
| 26 |
without specific prior written permission. |
| 27 |
|
| 28 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 29 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 30 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 31 |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 32 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 33 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 34 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 35 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 36 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 37 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 38 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 39 |
""" |
| 40 |
from inspect import getargspec |
| 41 |
|
| 42 |
try: |
| 43 |
from xmlrpc.server import SimpleXMLRPCDispatcher |
| 44 |
except ImportError: |
| 45 |
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher |
| 46 |
|
| 47 |
|
| 48 |
class DjangoXMLRPCDispatcher(SimpleXMLRPCDispatcher): |
| 49 |
"""A simple XML-RPC dispatcher for Django. |
| 50 |
|
| 51 |
Subclassess SimpleXMLRPCServer.SimpleXMLRPCDispatcher for the purpose of |
| 52 |
overriding certain built-in methods (it's nicer than monkey-patching them, |
| 53 |
that's for sure). |
| 54 |
""" |
| 55 |
|
| 56 |
def system_methodSignature(self, method): |
| 57 |
"""Returns the signature details for a specified method |
| 58 |
|
| 59 |
method |
| 60 |
The name of the XML-RPC method to get the details for |
| 61 |
""" |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
func = self.funcs[method] |
| 66 |
|
| 67 |
try: |
| 68 |
sig = func._xmlrpc_signature |
| 69 |
except: |
| 70 |
sig = { |
| 71 |
'returns': 'string', |
| 72 |
'args': ['string' for arg in getargspec(func)[0]], |
| 73 |
} |
| 74 |
|
| 75 |
return [sig['returns']] + sig['args'] |
| 76 |
|
| 77 |
xmlrpc_dispatcher = DjangoXMLRPCDispatcher(allow_none=False, encoding=None) |