def _generate_side(typeof): '''Internal usage only.''' source = random.randrange(2) if (source == 0): side = literal.generate(typeof) else: side = command.generate_with_type(typeof) return side
def generate_with_type(typeof): ''' Static method for generating a command with specific return type. The new generated command is randomly selected from all registered commands that have the given return type. ''' new_command = command() while True: cmd = command.registered_commands[random.randrange(len(command.registered_commands))] if (cmd[1] == typeof): break new_command.command = cmd #create parameters to command if needed new_command.parameters = [] if (len(new_command.command[3]) > 0): for param in new_command.command[3]: new_command.parameters.append(literal.generate(param)) return new_command
def generate(): ''' Static method for generating a command instance. Generated command instance will be randomly selected from the all registered commands. Returns the generated command. ''' new_command = command() #Find a command that is not a status command while (True): new_command.command = command.registered_commands[random.randrange(len(command.registered_commands))] if (new_command.command[4] == False): break #create parameters to command if needed new_command.parameters = [] if (len(new_command.command[3]) > 0): for param in new_command.command[3]: new_command.parameters.append(literal.generate(param)) return new_command
def generate_with_type(typeof): ''' Static method for generating a command with specific return type. The new generated command is randomly selected from all registered commands that have the given return type. ''' new_command = command() while True: cmd = command.registered_commands[random.randrange( len(command.registered_commands))] if (cmd[1] == typeof): break new_command.command = cmd #create parameters to command if needed new_command.parameters = [] if (len(new_command.command[3]) > 0): for param in new_command.command[3]: new_command.parameters.append(literal.generate(param)) return new_command
def generate(): ''' Static method for generating a command instance. Generated command instance will be randomly selected from the all registered commands. Returns the generated command. ''' new_command = command() #Find a command that is not a status command while (True): new_command.command = command.registered_commands[random.randrange( len(command.registered_commands))] if (new_command.command[4] == False): break #create parameters to command if needed new_command.parameters = [] if (len(new_command.command[3]) > 0): for param in new_command.command[3]: new_command.parameters.append(literal.generate(param)) return new_command