Skip to content

Commit

Permalink
Cutting off XML
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Samsula committed Jun 11, 2012
1 parent 1a82c9a commit 07e85d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 127 deletions.
20 changes: 7 additions & 13 deletions rpc4django/jsonrpcdispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class JSONRPCDispatcher:

# indent the json output by this many characters
# 0 does newlines only and None does most compact
# This is consistent with SimpleXMLRPCServer output
JSON_INDENT = 4

def __init__(self, json_encoder=None):
Expand Down Expand Up @@ -102,20 +101,15 @@ def dispatch(self, json_data, **kwargs):

api_call_id = jsondict.get('id', '')

if not 'method' in jsondict or not 'params' in jsondict:
# verify the dictionary contains the correct keys
# for a proper jsonrpc call
raise BadDataException('JSON must contain attributes method and params', api_call_id=api_call_id)
params = jsondict.get('params', [])
if not isinstance(params, list):
raise BadDataException('JSON method params has to be a list', api_call_id=api_call_id)

if not isinstance(jsondict['method'], StringTypes):
try:
method = self.methods[jsondict.get('method')]
except:
raise BadMethodException('JSON Wrong parameter method', api_call_id=api_call_id)

if not isinstance(jsondict['params'], list):
raise BadMethodException('JSON method params has to be Array', api_call_id=api_call_id)

if jsondict['method'] not in self.methods:
raise BadMethodException('Called method %s does not exist in this api, see system.listMethods' % jsondict['method'], api_call_id=api_call_id)

result = self.methods[jsondict.get('method')](*jsondict.get('params'), **kwargs)
result = method(*params, **kwargs)
return self._encode_result(api_call_id, result=result)

46 changes: 7 additions & 39 deletions rpc4django/rpcdispatcher.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
'''
This module contains the classes necessary to handle both
This module contains the classes necessary to handle
`JSONRPC <http://json-rpc.org/>`_ and
`XMLRPC <http://www.xmlrpc.com/>`_ requests.
It also contains a decorator to mark methods as rpc methods.
'''

import inspect
import platform
import pydoc
from rpc4django.exceptions import BadMethodException
import types
import xmlrpclib
from xmlrpclib import Fault
from django.contrib.auth import authenticate, login, logout
from jsonrpcdispatcher import JSONRPCDispatcher, json
from xmlrpcdispatcher import XMLRPCDispatcher

# this error code is taken from xmlrpc-epi
# http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
Expand Down Expand Up @@ -203,9 +200,7 @@ def get_params(self):
class RPCDispatcher:
'''
Keeps track of the methods available to be called and then
dispatches method calls to either the
:class:`XMLRPCDispatcher <rpc4django.xmlrpcdispatcher.XMLRPCDispatcher>`
or the
dispatches method calls to
:class:`JSONRPCDispatcher <rpc4django.jsonrpcdispatcher.JSONRPCDispatcher>`
Disables RPC introspection methods (eg. ``system.list_methods()`` if
Expand All @@ -220,9 +215,6 @@ class RPCDispatcher:
``rpcmethods``
A list of :class:`RPCMethod<rpc4django.rpcdispatcher.RPCMethod>` instances
available to be called by the dispatcher
``xmlrpcdispatcher``
An instance of :class:`XMLRPCDispatcher <rpc4django.xmlrpcdispatcher.XMLRPCDispatcher>`
where XMLRPC calls are dispatched to using :meth:`xmldispatch`
``jsonrpcdispatcher``
An instance of :class:`JSONRPCDispatcher <rpc4django.jsonrpcdispatcher.JSONRPCDispatcher>`
where JSONRPC calls are dispatched to using :meth:`jsondispatch`
Expand All @@ -235,7 +227,6 @@ def __init__(self, url='', apps=[], restrict_introspection=False,
self.url = url
self.rpcmethods = [] # a list of RPCMethod objects
self.jsonrpcdispatcher = JSONRPCDispatcher(json_encoder)
self.xmlrpcdispatcher = XMLRPCDispatcher()

if not restrict_introspection:
self.register_method(self.system_listmethods)
Expand All @@ -258,7 +249,6 @@ def check_request_permission(self, request):
**Parameters**
- ``request`` - a django HttpRequest object
- ``request_format`` - the request type: 'json' or 'xml'
Returns ``False`` if permission is denied and ``True`` otherwise
'''
Expand Down Expand Up @@ -287,7 +277,7 @@ def system_describe(self, **kwargs):
'''

description = {}
description['serviceType'] = 'RPC4Django JSONRPC+XMLRPC'
description['serviceType'] = 'RPC4Django JSONRPC'
description['serviceURL'] = self.url,
description['methods'] = [{'name': method.name,
'summary': method.help,
Expand Down Expand Up @@ -317,11 +307,7 @@ def system_methodhelp(self, method_name, **kwargs):
if method.name == method_name:
return method.help

# this differs from what implementation in SimpleXMLRPCServer does
# this will report via a fault or error while SimpleXMLRPCServer
# just returns an empty string
raise Fault(APPLICATION_ERROR, 'No method found with name: ' + \
str(method_name))
raise BadMethodException('Method %s not registered here' % method_name)

@rpcmethod(name='system.methodSignature', signature=['array', 'string'])
def system_methodsignature(self, method_name, **kwargs):
Expand All @@ -332,8 +318,8 @@ def system_methodsignature(self, method_name, **kwargs):
for method in self.rpcmethods:
if method.name == method_name:
return method.signature
raise Fault(APPLICATION_ERROR, 'No method found with name: ' + \
str(method_name))

raise BadMethodException('Method %s not registered here' % method_name)

@rpcmethod(name='system.login', signature=['boolean', 'string', 'string'])
def system_login(self, username, password, **kwargs):
Expand Down Expand Up @@ -381,8 +367,6 @@ def register_rpcmethods(self, apps):

for obj in dir(app):
method = getattr(app, obj)
if isinstance(method, xmlrpclib.ServerProxy):
continue
if callable(method) and \
hasattr(method, 'is_rpcmethod') and \
method.is_rpcmethod == True:
Expand All @@ -395,21 +379,6 @@ def register_rpcmethods(self, apps):
self.register_rpcmethods(["%s.%s" % (appname, obj)])



def jsondispatch(self, raw_post_data, **kwargs):
'''
Sends the post data to :meth:`rpc4django.jsonrpcdispatcher.JSONRPCDispatcher.dispatch`
'''

return self.jsonrpcdispatcher.dispatch(raw_post_data, **kwargs)

def xmldispatch(self, raw_post_data, **kwargs):
'''
Sends the post data to :meth:`rpc4django.xmlrpcdispatcher.XMLRPCDispatcher.dispatch`
'''

return self.xmlrpcdispatcher.dispatch(raw_post_data, **kwargs)

def get_method_name(self, raw_post_data):
'''
Gets the name of the method to be called given the post data
Expand Down Expand Up @@ -456,7 +425,6 @@ def register_method(self, method, name=None, signature=None, helpmsg=None):
meth = RPCMethod(method, name, signature, helpmsg)

if meth.name not in self.system_listmethods():
self.xmlrpcdispatcher.register_function(method, meth.name)
self.jsonrpcdispatcher.register_function(method, meth.name)
self.rpcmethods.append(meth)

1 change: 0 additions & 1 deletion rpc4django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
RESTRICT_INTROSPECTION = getattr(settings, 'RPC4DJANGO_RESTRICT_INTROSPECTION', False)
RESTRICT_OOTB_AUTH = getattr(settings, 'RPC4DJANGO_RESTRICT_OOTB_AUTH', True)
RESTRICT_JSON = getattr(settings, 'RPC4DJANGO_RESTRICT_JSONRPC', False)
RESTRICT_XML = getattr(settings, 'RPC4DJANGO_RESTRICT_XMLRPC', False)
RESTRICT_METHOD_SUMMARY = getattr(settings, 'RPC4DJANGO_RESTRICT_METHOD_SUMMARY', False)
RESTRICT_RPCTEST = getattr(settings, 'RPC4DJANGO_RESTRICT_RPCTEST', False)
RESTRICT_RPCTEST = getattr(settings, 'RPC4DJANGO_RESTRICT_RPCTEST', False)
Expand Down
74 changes: 0 additions & 74 deletions rpc4django/xmlrpcdispatcher.py

This file was deleted.

0 comments on commit 07e85d2

Please sign in to comment.