Example #1
0
def findFromNextToken( cmdMap, cmd):
    (cmdFirstToken, cmdRemainingTokens) = util.first_token(cmd)
    #print "next token: %s      remaining: %s" % (cmdFirstToken, cmdRemainingTokens)

    assert len(cmdFirstToken) > 0, "CmdMap.findFromNextToken received length 0 cmdFirstToken from util.firstToken. This should never happen... @Todo unless cmd is all whitespace"

    for char in cmdFirstToken:
        #print "next char %s" % char
        if char in cmdMap.possibleNext:
            cmdMap = cmdMap.possibleNext[ char ]
        else:
            #print "char not found in map, this token will be data, returning None"
            return None

    if len(cmdRemainingTokens) > 0 and cmdMap.nextTokenNode:
        result = findFromNextToken( cmdMap.nextTokenNode, cmdRemainingTokens )
        if result: return result

    #print "result was none"
    if not cmdMap.allowAbbrev:
        return None

    assert cmdMap.callback, "CmdMap.find found a match with a null callback"

    if len(cmdRemainingTokens) == 0:
        cmdRemainingTokens = None

    return (cmdMap.callback, cmdRemainingTokens)
Example #2
0
def logon_receive_account_name( logon_seq, account_name ):
    account_name = util.first_token(account_name)[0]
    account = get_account(account_name )
    if ( account ):
        logon_request_password( logon_seq, account )
    else:
        logon_account_doesnt_exist( logon_seq, account_name )
Example #3
0
def receive_new_account_password( logon_seq, account_pw, account):
    if ( account_pw != util.first_token( account_pw )[0] ):
        logon_seq.send("Passwords may not have whitespace.\n")
        logon_input_new_account_password( logon_seq, account )
        return

    account.password = account_pw
    logon_seq.send("Verify Password:")
    logon_seq.next_state( parser.empty(), lambda diff_logon_seq, password: verify_new_account_password( diff_logon_seq, password, account ) )
Example #4
0
    def add(self, kw):

        if len(kw) == 0:
            return False

        if len(kw) != len(util.first_token(kw)[0]):  # do nothing if kw isn't a single token
            return False

        return self.addKwToTrie( kw )
Example #5
0
    def has(self, kw):

        if len(kw) == 0:
            return False

        if len(kw) != len(util.first_token(kw)[0]):  # do nothing if kw isn't a single token
            return False

        return self.findKwInTrie( kw )
Example #6
0
    def add(self, kw):

        if len(kw) == 0:
            return False

        if len(kw) != len(util.first_token(kw)
                          [0]):  # do nothing if kw isn't a single token
            return False

        return self.addKwToTrie(kw)
Example #7
0
    def has(self, kw):

        if len(kw) == 0:
            return False

        if len(kw) != len(util.first_token(kw)
                          [0]):  # do nothing if kw isn't a single token
            return False

        return self.findKwInTrie(kw)
Example #8
0
def addCmdFromNextToken( cmdMap, cmd, callback, allowAbbrev ):
    (cmdFirstToken, cmdRemainingTokens) = util.first_token(cmd)

    if len(cmdRemainingTokens) > 0:
        assert allowAbbrev, "CmdMap currently supports only monotoken no-allowAbbreviate commands"

    #print "next token: %s      remaining: %s" % (cmdFirstToken, cmdRemainingTokens)
    assert len(cmdFirstToken) > 0, "CmdMap.addCmdFromNextToken received length 0 cmdFirstToken from util.firstToken. This should never happen... @Todo unless cmd is all whitespace"
        
    for char in cmdFirstToken:
        cmdMap = addCmdFromNextChar( cmdMap, char, cmdRemainingTokens, callback, allowAbbrev )

    if len(cmdRemainingTokens) == 0:
        cmdMap.allowAbbrev = True
Example #9
0
def zoneEditCmd(clientId, remaining):
    if remaining:
        (token, remaining) = first_token(remaining)
        templateId = toInt(token)

        if templateId:
            zoneTemplate = getZoneTemplate(templateId)

            if zoneTemplate:
                _editZone(clientId, zoneTemplate)
                return

        _invalidZoneId(clientId, token)

    # ZoneTemplateSelector
    sendToClient(clientId, "ZoneTemplateSelector not impl")
Example #10
0
def mobEditCmd(clientId, remaining):
    if remaining:
        (token, remaining) = first_token(remaining)
        templateId = toInt(token)

        if templateId:
            mobTemplate = getMobTemplate(templateId)

            if mobTemplate:
                _editMob(clientId, mobTemplate)
                return

        _invalidMobId(clientId, token)

    # MobTemplateSelector
    sendToClient(clientId, "MobTemplateSelector not impl")
Example #11
0
def zoneEditCmd( clientId, remaining):
    if remaining:
        (token, remaining) = first_token(remaining)
        templateId = toInt(token)

        if templateId:
            zoneTemplate = getZoneTemplate( templateId )

            if zoneTemplate:
                _editZone( clientId, zoneTemplate )
                return
            
        _invalidZoneId( clientId, token )

    # ZoneTemplateSelector
    sendToClient( clientId, "ZoneTemplateSelector not impl" )
Example #12
0
 def testepsilon(self):
     self.assertEquals(util.first_token(""), ("",""))
Example #13
0
 def testonly_whitespace(self):
     for char in string.whitespace:
         self.assertEquals(util.first_token(char), ("", ""))
Example #14
0
 def testepsilon(self):
     self.assertEquals(util.first_token(""), ("", ""))
Example #15
0
 def testone_token(self):
     self.assertEquals(util.first_token("fred"), ("fred", ""))
Example #16
0
 def testremainder_no_left_whitespace(self):
     self.assertEquals(util.first_token("jim   "), ("jim", ""))
     self.assertEquals(
         util.first_token("cast    \t\n\rfireball ted say hi omgz"),
         ("cast", "fireball ted say hi omgz"))
Example #17
0
 def testonly_whitespace(self):
     for char in string.whitespace:
         self.assertEquals(util.first_token( char ), ("",""))
Example #18
0
 def testremainder_no_left_whitespace(self):
     self.assertEquals(util.first_token("jim   "), ("jim",""))
     self.assertEquals(util.first_token("cast    \t\n\rfireball ted say hi omgz"), ("cast", "fireball ted say hi omgz"))
Example #19
0
 def testone_token(self):
     self.assertEquals(util.first_token("fred"), ("fred",""))