JSON-RPC protocol error base class Subclasses of this class also exist for specific types of errors; the set of all subclasses is by no means complete.
| 73 | |
| 74 | |
| 75 | class JSONRPCError(Exception): |
| 76 | """JSON-RPC protocol error base class |
| 77 | |
| 78 | Subclasses of this class also exist for specific types of errors; the set |
| 79 | of all subclasses is by no means complete. |
| 80 | """ |
| 81 | |
| 82 | SUBCLS_BY_CODE = {} |
| 83 | |
| 84 | @classmethod |
| 85 | def _register_subcls(cls, subcls): |
| 86 | cls.SUBCLS_BY_CODE[subcls.RPC_ERROR_CODE] = subcls |
| 87 | return subcls |
| 88 | |
| 89 | def __new__(cls, rpc_error): |
| 90 | assert cls is JSONRPCError |
| 91 | cls = JSONRPCError.SUBCLS_BY_CODE.get(rpc_error['code'], cls) |
| 92 | |
| 93 | self = Exception.__new__(cls) |
| 94 | |
| 95 | super(JSONRPCError, self).__init__( |
| 96 | 'msg: %r code: %r' % |
| 97 | (rpc_error['message'], rpc_error['code'])) |
| 98 | self.error = rpc_error |
| 99 | |
| 100 | return self |
| 101 | |
| 102 | @JSONRPCError._register_subcls |
| 103 | class ForbiddenBySafeModeError(JSONRPCError): |
no outgoing calls
no test coverage detected