File: jsonrpc.py

package info (click to toggle)
python-jsonrpc 1.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 444 kB
  • sloc: python: 3,152; makefile: 154
file content (28 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)