Example #1
0
def lookup(keylist):
	"""
	key is of type list
	"""
	args = []
	table = TABLE[str(keylist[0])]
	length = len(keylist)
	i = 1
	while i in range(1, length):

		if keylist[i] == WILDCARD:
			# allow for wildcard rolling
			randomkey = random.choice(table.keys())
			table = table[randomkey]
			keylist[i] = randomkey

		elif keylist[i] == ARG_BEGIN:
			# remove the "("
			keylist.pop(i)
			# we are in arguments
			while True:
				if keylist[i] != ARG_END:
					args.append(keylist[i])

				keylist.pop(i)
				length -= 1

				if keylist[i] == ARG_END:
					keylist.pop(i)
					length -= 1
					break

		else:
			table = table[keylist[i]]

		i += 1

	# find proper item subclass
	lastfound = ITEMCLASS
	for j in range(1, len(keylist)):
		keylist_ = keylist[0:j]
		if Item.list_to_dict_key(keylist_) in ITEMSUBCLASS:
			lastfound = ITEMSUBCLASS[Item.list_to_dict_key(keylist_)]

	# if no special class, use base class
	return lastfound(table, keylist, args=args)