The following optional settings can go into settings.py to change the functionality of RPC4Django
By default RPC4Django will log (using the python logging module) all requests and responses. This can be disabled by setting this to False.
By default RPC4Django registers the standard XMLRPC and JSONRPC introspection functions. This can be disabled by setting this to True.
If True, RPC4Django will never serve a JSONRPC request. Instead, either XMLRPC will be tried or status code 404 will be returned. Defaults to False.
If True, RPC4Django will never serve an XMLRPC request. Instead, either JSONRPC will be tried or status code 404 will be returned. Defaults to False.
If True, status code 404 will be returned instead of serving the method summary as a response to a GET request. Defaults to False.
If True, the method summary will not allow testing via JSONRPC from the generated method summary page. Defaults to False
If True, RPC4Django does not attempt to convert any of the method summary docstrings to restructured text. Defaults to False.
If False, enables out of the box authentication via the RPC methods system.login and system.logout. Out of the box authentication should NOT be considered secure when used without SSL or TLS. Defaults to True.
If True, RPC4Django will respond to OPTIONS requests with the HTTP header Access-Control-Allow-Credentials set to the given value. This pertains to allowing cross site requests with cookies. See the Mozilla documentation on requests with credentials for more details. Defaults to False.
RPC4Django will respond to OPTIONS requests with the HTTP header Access-Control-Allow-Origin set to the given value. This pertains to allowing cross site requests. See the Mozilla documentation on preflighted requests for more details. Defaults to the empty string.
Subclass of rpc4django.jsonrpcdispatcher.json.JSONEncoder or string pointing to the subclass. It can be used to serialize objects that can’t otherwise be serialized. Defaults to django.core.serializers.json.DjangoJSONEncoder.
The main entry point for RPC4Django. Usually, the user simply puts serve_rpc_request into urls.py
urlpatterns = patterns('',
# rpc4django will need to be in your Python path
(r'^RPC2$', 'rpc4django.views.serve_rpc_request'),
)
Checks whether this user has permission to call a particular method This method does not check method call validity. That is done later
Parameters
Returns False if permission is denied and True otherwise
Determines whether this request should be served by XMLRPC or JSONRPC
Returns True if this is an XML request and false for JSON
Handles rpc calls based on the content type of the request or returns the method documentation page if the request was a GET.
Parameters
This module contains the classes necessary to handle both JSONRPC and XMLRPC requests. It also contains a decorator to mark methods as rpc methods.
Keeps track of the methods available to be called and then dispatches method calls to either the XMLRPCDispatcher or the JSONRPCDispatcher
Disables RPC introspection methods (eg. system.list_methods() if restrict_introspection is set to True. Disables out of the box authentication if restrict_ootb_auth is True.
Attributes
Gets the name of the method to be called given the post data and the format of the data
Sends the post data to rpc4django.jsonrpcdispatcher.JSONRPCDispatcher.dispatch()
Returns a list of RPCMethod objects supported by the server
Instantiates an RPCMethod object and adds it to rpcmethods so that it can be called by RPC requests
Parameters
Scans the installed apps for methods with the rpcmethod decorator Adds these methods to the list of methods callable via RPC
Returns a simple method description of the methods supported
Returns a list of supported methods
Authorizes a user to enable sending protected RPC requests
Deauthorizes a user
Returns documentation for a specified method
Returns the signature for a specified method
Sends the post data to rpc4django.xmlrpcdispatcher.XMLRPCDispatcher.dispatch()
A method available to be called via the rpc dispatcher
Attributes
Returns a list of dictionaries containing name and type of the params
Returns the return value which is the first element of the signature
Returns JSON for a JSONRPC request for this method
This is used to generate the introspection method output
Accepts keyword based arguments that describe the method’s rpc aspects
Parameters
Examples
@rpcmethod()
@rpcmethod(name='myns.myFuncName', signature=['int','int'])
@rpcmethod(permission='add_group')
@rpcmethod(login_required=True)
Implements an XMLRPC dispatcher
Encodes and decodes XMLRPC messages, dispatches to the requested method and returns any responses or errors in encoded XML.
Subclasses SimpleXMLRPCDispatcher so that it can also pass the Django HttpRequest object from the underlying RPC request
Extracts the xml marshaled parameters and method name and calls the underlying method and returns either an xml marshaled response or an XMLRPC fault
Although very similar to the superclass’ _marshaled_dispatch, this method has a different name due to the different parameters it takes from the superclass method.
This module implements a JSON 1.0 compatible dispatcher
see http://json-rpc.org/wiki/specification
This class can be used encode and decode jsonrpc messages, dispatch the requested method with the passed parameters, and return any response or error.
Verifies that the passed json encoded string is in the correct form according to the json-rpc spec and calls the appropriate Python method
Checks
- that the string encodes into a javascript Object (dictionary)
- that ‘method’ and ‘params’ are present
- ‘method’ must be a javascript String type
- ‘params’ must be a javascript Array type
Returns the JSON encoded response
Registers a method with the jsonrpc dispatcher.
This method can be called later via the dispatch method.
Creates a template tag that can handle restructured text (reST)
Returns text in reST format or plain text if resttext fails to import docutils or fails for any other reason
If RPC4DJANGO_RESTRICT_REST is True, just return text