def _parse_cmd(self, cmd):
        """
        Parses a received command.

        :param cmd: String command received from Polyglot
        """
        if len(cmd) >= 2:
            # parse command
            try:
                cmd = json.loads(cmd)
            except __HOLE__:
                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)
dataset/ETHPy150Open UniversalDevicesInc/Polyglot/polyglot/nodeserver_api.py/PolyglotConnector._parse_cmd