Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding extra fields to JSON RPC request structure (try 2) #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions jsonrpclib/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,15 @@ def __init__(self, uri, transport=None, encoding=None,
self.__transport = transport
self.__encoding = encoding
self.__verbose = verbose
self.__extra = None

def _set_extra(self, extra):
self.__extra = extra

def _request(self, methodname, params, rpcid=None):
request = dumps(params, methodname, encoding=self.__encoding,
rpcid=rpcid, version=self.__version)
rpcid=rpcid, version=self.__version,
extra=self.__extra)
response = self._run_request(request)
check_for_errors(response)
return response['result']
Expand Down Expand Up @@ -415,7 +420,7 @@ def __init__(self, rpcid=None, version=None):
self.id = rpcid
self.version = float(version)

def request(self, method, params=[]):
def request(self, method, params=[], extra=None):
if type(method) not in types.StringTypes:
raise ValueError('Method name must be a string.')
if not self.id:
Expand All @@ -425,6 +430,8 @@ def request(self, method, params=[]):
request['params'] = params
if self.version >= 2:
request['jsonrpc'] = str(self.version)
if extra:
request.update(extra)
return request

def notify(self, method, params=[]):
Expand Down Expand Up @@ -453,7 +460,8 @@ def error(self, code=-32000, message='Server error.'):
return error

def dumps(params=[], methodname=None, methodresponse=None,
encoding=None, rpcid=None, version=None, notify=None):
encoding=None, rpcid=None, version=None, notify=None,
extra=None):
"""
This differs from the Python implementation in that it implements
the rpcid argument since the 2.0 spec requires it for responses.
Expand Down Expand Up @@ -492,7 +500,7 @@ def dumps(params=[], methodname=None, methodresponse=None,
if notify == True:
request = payload.notify(methodname, params)
else:
request = payload.request(methodname, params)
request = payload.request(methodname, params, extra)
return jdumps(request, encoding=encoding)

def loads(data):
Expand Down