diff options
Diffstat (limited to 'config_file/parsers/parse_value.py')
| -rw-r--r-- | config_file/parsers/parse_value.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/config_file/parsers/parse_value.py b/config_file/parsers/parse_value.py index 12032d6..b324a4b 100644 --- a/config_file/parsers/parse_value.py +++ b/config_file/parsers/parse_value.py @@ -1,7 +1,6 @@ """This module allows you to parse a string into its native type.""" import ast import re -from distutils.util import strtobool from typing import Any @@ -149,6 +148,22 @@ def can_be_parsed_as_bool(value: Any) -> bool: return value == "true" or value == "false" +# distutils strtobool backport: https://github.com/yukinarit/strtobool +def strtobool(val): + """Convert a string representation of truth to true (1) or false (0). + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values + are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + 'val' is anything else. + """ + val = val.lower() + if val in ('y', 'yes', 't', 'true', 'on', '1'): + return 1 + elif val in ('n', 'no', 'f', 'false', 'off', '0'): + return 0 + else: + raise ValueError("invalid truth value %r" % (val,)) + + def can_be_parsed_as_dict(value: Any) -> bool: """Checks whether a value can be parsed as a dictionary. |