[tor-commits] [sbws/master] Add funcs for validating enums
pastly at torproject.org
pastly at torproject.org
Wed Jul 11 15:05:40 UTC 2018
commit 11fac0c6581158586f26e94a1ac2dfe6e4ca140d
Author: Matt Traudt <sirmatt at ksu.edu>
Date: Mon Jun 25 09:57:49 2018 -0400
Add funcs for validating enums
---
sbws/util/config.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/sbws/util/config.py b/sbws/util/config.py
index faedbd5..0bfa072 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -368,6 +368,27 @@ def _validate_section_urls(conf, sec, urls, tmpl):
return errors
+def _validate_section_enums(conf, sec, enums, tmpl):
+ errors = []
+ section = conf[sec]
+ for key in enums:
+ choices = enums[key]['choices']
+ valid, error = _validate_enum(section, key, choices)
+ if not valid:
+ errors.append(tmpl.substitute(
+ sec=sec, key=key, val=section[key],
+ e='Not a valid enum choice ({})'.format(', '.join(choices))))
+ return errors
+
+
+def _validate_enum(section, key, choices):
+ value = section[key]
+ if value not in choices:
+ return False, '{} not in allowed choices: {}'.format(
+ value, ', '.join(choices))
+ return True, ''
+
+
def _validate_url(section, key):
value = section[key]
if not value.startswith(('http://', 'https://')):
More information about the tor-commits
mailing list