mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-28 04:13:52 +08:00
Merge pyextra subtree
This commit is contained in:
28
pyextra/jsonrpc/jsonrpc.py
Normal file
28
pyextra/jsonrpc/jsonrpc.py
Normal file
@@ -0,0 +1,28 @@
|
||||
""" JSON-RPC wrappers for version 1.0 and 2.0.
|
||||
|
||||
Objects diring init operation try to choose JSON-RPC 2.0 and in case of error
|
||||
JSON-RPC 1.0.
|
||||
from_json methods could decide what format is it by presence of 'jsonrpc'
|
||||
attribute.
|
||||
|
||||
"""
|
||||
from .utils import JSONSerializable
|
||||
from .jsonrpc1 import JSONRPC10Request
|
||||
from .jsonrpc2 import JSONRPC20Request
|
||||
|
||||
|
||||
class JSONRPCRequest(JSONSerializable):
|
||||
|
||||
""" JSONRPC Request."""
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str):
|
||||
data = cls.deserialize(json_str)
|
||||
return cls.from_data(data)
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, data):
|
||||
if isinstance(data, dict) and "jsonrpc" not in data:
|
||||
return JSONRPC10Request.from_data(data)
|
||||
else:
|
||||
return JSONRPC20Request.from_data(data)
|
||||
Reference in New Issue
Block a user