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

Revert "Spec compliance: handle top-level mappings in function calls" #6

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions jsonrpc_base/jsonrpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import inspect
import json
import logging
Expand Down Expand Up @@ -135,13 +134,6 @@ def __request(self, method_name, args=None, kwargs=None):
raise ProtocolError(
'JSON-RPC spec forbids mixing arguments and keyword arguments')

# from the specs:
# "If resent, parameters for the rpc call MUST be provided as a
# Structured value. Either by-position through an Array or by-name
# through an Object."
if len(args) == 1 and isinstance(args[0], collections.abc.Mapping):
args = dict(args[0])

return self.send_message(Request(method_name, args or kwargs, msg_id))

def __register(self, method_name, callback):
Expand Down
14 changes: 13 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def handler2(message):

# rpc call with a mapping type
def handler3(message):
assert message.params == {'foo': 'bar'}
assert message.params == [{'foo': 'bar'}]
return {
"jsonrpc": "2.0",
"result": None,
Expand All @@ -239,6 +239,18 @@ def handler3(message):
server._handler = handler3
server.foobar({'foo': 'bar'})

# rpc call with direct dict params
def handler3(message):
assert message.params == {'foo': 'bar'}
return {
"jsonrpc": "2.0",
"result": None,
"id": 1,
}

server._handler = handler3
server.foobar(**{'foo': 'bar'})


def test_notification(server):
# Verify that we ignore the server response
Expand Down