Last active
August 29, 2015 13:57
-
-
Save mjdorma/9756431 to your computer and use it in GitHub Desktop.
Revisions
-
mjdorma revised this gist
Mar 25, 2014 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,10 +17,10 @@ def assert_wrapper(value): if value not in options: raise TypeError("'%s' choices are: '%s'" % (name, "', '".join(options))) return value new_kwargs = {} for name, options in kwargs.items(): new_kwargs[name] = assert_choice(name, options) return begin.convert(**new_kwargs) -
mjdorma renamed this gist
Mar 25, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mjdorma created this gist
Mar 25, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ """Assert a choice for the value of an argument. Example:: @begin.start @choices(foo=['meh', 'one']) def main(foo): print(foo) """ import begin def choices(**kwargs): "Validate arguments values are in a set" def assert_choice(name, options): def assert_wrapper(value): if value not in options: raise TypeError("'%s' choices are: '%s'" % (name, "', '".join(options))) return value new_kwargs = {} for name, options in kwargs.items(): new_kwargs[name] = assert_choice(name, options) return begin.convert(**new_kwargs)