File: Interface.py

package info (click to toggle)
raritan-json-rpc-sdk 4.0.20%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 57,236 kB
  • sloc: cs: 223,121; perl: 117,786; python: 26,872; javascript: 6,544; makefile: 27
file content (48 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright 2010 Raritan Inc. All rights reserved.

import raritan.rpc

class Interface(object):
    """IDL interface reference = base class of all proxies
    """
    class Method():
        def __init__(self, parent):
            self.parent = parent

        def __call__(self, *args):
            encArgs = self.encode(*args)
            rsp = self.parent.agent.json_rpc(self.parent.target, self.name, encArgs)
            return self.decode(rsp, self.parent.agent)

    def __init__(self, target, agent):
        self.target = target
        self.agent = agent

    @staticmethod
    def decode(json, agent):
        if (not json):
            return None
        target = json['rid']
        class_ = raritan.rpc.TypeInfo.decode(json['type'])
        obj = class_(target, agent)
        return obj

    @staticmethod
    def encode(obj):
      if not obj:
        return None
      json = {}
      json['rid'] = obj.target
      json['type'] = obj.idlType
      return json

    def __str__(self):
        return "%s: %s" % (raritan.rpc.TypeInfo.typeBaseName(self.idlType), self.target)

    def __eq__(self, other):
        return other and self.idlType == other.idlType and self.target == other.target

    def __hash__(self):
        return hash((self.idlType, self.target))