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)
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 )
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 ) )
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 )
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 )
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)
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)
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
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")
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")
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" )
def testepsilon(self): self.assertEquals(util.first_token(""), ("",""))
def testonly_whitespace(self): for char in string.whitespace: self.assertEquals(util.first_token(char), ("", ""))
def testepsilon(self): self.assertEquals(util.first_token(""), ("", ""))
def testone_token(self): self.assertEquals(util.first_token("fred"), ("fred", ""))
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"))
def testonly_whitespace(self): for char in string.whitespace: self.assertEquals(util.first_token( char ), ("",""))
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"))
def testone_token(self): self.assertEquals(util.first_token("fred"), ("fred",""))