def _parse_cmd(self, cmd):
        if len(cmd) >= 2:
            # parse command
            try:
                cmd = json.loads(cmd)
            except ValueError:
                self.send_error('Received badly formatted command ' +
                                '(not json): {}'.format(cmd))
                return False

            # split command
            try:
                cmd_code = list(cmd.keys())[0]
                args = cmd[cmd_code]
            except (KeyError, IndexError):
                self.send_error('Received badly formatted command: {} '
                                .format(cmd))
                return False

            # validate command
            if cmd_code not in self.commands:
                self.send_error('Received invalid command: {}'.format(cmd))
                return False

            # execute command
            return self._recv(cmd_code, args)
Parses a received command.
dataset/ETHPy150Open UniversalDevicesInc/Polyglot/polyglot/nodeserver_api.py/PolyglotConnector._parse_cmd