From: Darren S. <pha...@gm...> - 2015-01-10 05:57:43
|
I have a case in a script where I have a data structure defined in an external module, which is also a library we use in the script. I'd like to use that data in a DRY fashion in this script (which uses ConfigObj) by passing the structure (a list) as the argument to the option() validator. The reason for this is that the data in the target configuration field will ultimately be passed to the external module and will be validated against it, so the external module is essentially "authoritative" for the application. In the external module (mylib.py): CATEGORIES = ['WHITE', 'GREEN', 'AMBER', 'RED'] In the script: from mylib import CATEGORIES as allowed_categories CONFIGSPEC = '''\ logfile = string [foo] user = string pass = string [bar] [[__many__]] category = string ''' As shown I currently validate the 'category' option with string(), but I'd really like to use option() instead with the set of choices taken from the list imported from mylib; something like the following: category = option(allowed_categories) That syntax doesn't work and various attempts to coerce the list into a string that resembles a list of allowed values with join() hasn't done the trick. Is there currently a way to get this to function as I want? Any way to allow option() to accept a tuple or list as the arguments to ease working with structured data for that validator? -- Darren Spruell pha...@gm... |