def getDict(self, option, default = noDefault, parser = lambda x: x, strfun = lambda x: x, **kwargs):
		def obj2str(value):
			(srcdict, srckeys) = value
			getmax = lambda src: max(map(lambda x: len(str(x)), src) + [0])
			result = ''
			if srcdict.get(None) != None:
				result = strfun(srcdict.get(None, parser('')))
			fmt = '\n\t%%%ds => %%%ds' % (getmax(srckeys), getmax(srcdict.values()))
			return result + str.join('', map(lambda k: fmt % (k, strfun(srcdict[k])), srckeys))
		str2obj = lambda value: utils.parseDict(value, parser)
		def2obj = lambda value: (value, value.keys())
		return self._getInternal('dictionary', obj2str, str2obj, def2obj, option, default, **kwargs)
Beispiel #2
0
	def getDict(self, *args, **kwargs): # Default key is accessed via key == None (None is never in keys!)
		parser = kwargs.pop('parser', lambda x: x) # currently only support value parsers
		strfun = kwargs.pop('str', lambda x: x)    # currently only support value handling
		def obj2str(value):
			(srcdict, srckeys) = value
			getmax = lambda src: max(map(lambda x: len(str(x)), src) + [0])
			result = strfun(srcdict.get(None, parser('')))
			fmt = '\n\t%%%ds => %%%ds' % (getmax(srckeys), getmax(srcdict.values()))
			return result + str.join('', map(lambda k: fmt % (k, strfun(srcdict[k])), srckeys))
		str2obj = lambda value: utils.parseDict(value, parser)
		def2obj = lambda value: (value, value.keys())
		(selector, args, kwargs) = self._selectorFilter(*args, **kwargs)
		return self._getTyped('dictionary', obj2str, str2obj, def2obj, selector, *args, **kwargs)
Beispiel #3
0
	def parseDict(self, varName, value, valueParser):
		keyTupleDelimeter = self.get(self.getParameterOption(varName), 'key delimeter', ',')
		return utils.parseDict(value, valueParser, lambda k: parseTuple(k, keyTupleDelimeter))