Пример #1
0
 def _dump_state(self):
     e = hdjson.Encoder()
     s = {}
     for attr, value in self.__dict__.iteritems():
         # dict. with non-string keys must be normalized for JSON encoding
         if attr in ["_portcounters", "_instances_by_bindings"]:
             s[attr] = e.normalizeDictKeys(value, hdjson.KEYS_TUPLE)
         elif attr in ["_instances_by_id", "_spaces_by_id", "_xfers_by_id"]:
             s[attr] = e.normalizeDictKeys(value, hdjson.KEYS_INT)
         else:
             s[attr] = value
     s['state_version'] = Coordinator.STATE_VERSION
     return hdjson.Encoder(**hdjson.HumanReadable).encode(s)
Пример #2
0
 def get_space(self, space):
     try:
         space = self._coordinator.get_space(space)
     except ValueError as e:
         return self._fail(str(e))
     except Coordinator.UnknownSpace as e:
         return self._fail("Space does not exist")
     s = hdjson.Encoder(**hdjson.HumanReadable).encode(space)
     self.outgoing += json.dumps({self._currreq: s}) + '\n'
Пример #3
0
 def get_status(self):
     status = self._coordinator.get_status()
     s = hdjson.Encoder(**hdjson.HumanReadable).encode(status)
     self.outgoing += json.dumps({self._currreq: s}) + '\n'
Пример #4
0
 def __repr__(self):
     return hdjson.Encoder().encode(self)