Exemple #1
0
    def test_cmdparser(self):
        a_cmdset = _CmdSetTest()
        bcmd = [cmd for cmd in a_cmdset.commands if cmd.key == "test1"][0]

        self.assertEqual(
            cmdparser.cmdparser("test1hello", a_cmdset, None),
            [("test1", "hello", bcmd, 5, 0.5, "test1")],
        )
Exemple #2
0
def cmdparser(raw_string, cmdset, caller, match_index=None):
    """
    This function is called by the cmdhandler once it has
    gathered and merged all valid cmdsets valid for this particular parsing.

    raw_string - the unparsed text entered by the caller.
    cmdset - the merged, currently valid cmdset
    caller - the caller triggering this parsing
    match_index - an optional integer index to pick a given match in a
                  list of same-named command matches.

    Returns:
     list of tuples: [(cmdname, args, cmdobj, cmdlen, mratio), ...]
            where cmdname is the matching command name and args is
            everything not included in the cmdname. Cmdobj is the actual
            command instance taken from the cmdset, cmdlen is the length
            of the command name and the mratio is some quality value to
            (possibly) separate multiple matches.

    """
    try:
        if raw_string == CMD_LOGINSTART:
            cmd = CMD_LOGINSTART
            args = ""
        else:
            # Parse JSON formated command.
            data = json.loads(raw_string)
            cmd = data["cmd"]
            args = data["args"]

        # Find the matching command in cmdset.
        for cmdobj in cmdset:
            if cmdobj.key == cmd:
                return [(
                    cmd,
                    args,
                    cmdobj,
                )]

        # can not find
        return []
    except Exception:
        # Command is not in JSON, call evennia's cmdparser.
        return evennia_cmdparser.cmdparser(raw_string, cmdset, caller,
                                           match_index)
Exemple #3
0
def cmdparser(raw_string, cmdset, caller, match_index=None):
    """
    This function is called by the cmdhandler once it has
    gathered and merged all valid cmdsets valid for this particular parsing.

    raw_string - the unparsed text entered by the caller.
    cmdset - the merged, currently valid cmdset
    caller - the caller triggering this parsing
    match_index - an optional integer index to pick a given match in a
                  list of same-named command matches.

    Returns:
     list of tuples: [(cmdname, args, cmdobj, cmdlen, mratio), ...]
            where cmdname is the matching command name and args is
            everything not included in the cmdname. Cmdobj is the actual
            command instance taken from the cmdset, cmdlen is the length
            of the command name and the mratio is some quality value to
            (possibly) separate multiple matches.

    """
    try:
        if raw_string == CMD_LOGINSTART:
            cmd = CMD_LOGINSTART
            args = ""
        else:
            # Parse JSON formated command.
            data = json.loads(raw_string)
            cmd = data["cmd"]
            args = data["args"]

        # Find the matching command in cmdset.
        for cmdobj in cmdset:
            if cmdobj.key == cmd:
                return [(cmd, args, cmdobj,)]

        # can not find
        return []
    except Exception:
        # Command is not in JSON, call evennia's cmdparser.
        return evennia_cmdparser.cmdparser(raw_string, cmdset, caller, match_index)