Commit 65ea99f4 authored by Robert Bradshaw's avatar Robert Bradshaw

multiple-choice directive type

parent 85ee8e60
...@@ -135,6 +135,15 @@ extra_warnings = { ...@@ -135,6 +135,15 @@ extra_warnings = {
'warn.unused': True, 'warn.unused': True,
} }
def one_of(*args):
def validate(name, value):
if value not in args:
raise ValueError("%s directive must be one of %s, got '%s'" % (
name, args, value))
else:
return value
return validate
# Override types possibilities above, if needed # Override types possibilities above, if needed
directive_types = { directive_types = {
'final' : bool, # final cdef classes and methods 'final' : bool, # final cdef classes and methods
...@@ -146,6 +155,7 @@ directive_types = { ...@@ -146,6 +155,7 @@ directive_types = {
'cclass' : None, 'cclass' : None,
'returns' : type, 'returns' : type,
'set_initial_path': str, 'set_initial_path': str,
'c_string_type': one_of('bytes', 'str', 'unicoode'),
} }
for key, val in directive_defaults.items(): for key, val in directive_defaults.items():
...@@ -203,6 +213,8 @@ def parse_directive_value(name, value, relaxed_bool=False): ...@@ -203,6 +213,8 @@ def parse_directive_value(name, value, relaxed_bool=False):
name, orig_value)) name, orig_value))
elif type is str: elif type is str:
return str(value) return str(value)
elif callable(type):
return type(name, value)
else: else:
assert False assert False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment