diff --git a/README.md b/README.md index 001f470..e400f6f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# str2bool v.1.1 +# str2bool v.1.2 ## About Convert string to boolean. -Library recognizes "yes", "true", "y", "t", "1" as True, and "no", "false", "n", "f", "0" as False. +Library recognizes "yes", "true", "y", "t", "1", "enabled" as True, and "no", "false", "n", "f", "0", "disabled" as False. Case insensitive. ## Installation diff --git a/setup.py b/setup.py index 4687965..5040d97 100644 --- a/setup.py +++ b/setup.py @@ -1,24 +1,25 @@ -from distutils.core import setup - - -setup( - name='str2bool', - packages=['str2bool'], - version='1.1', - description='Convert string to boolean', - author='SymonSoft', - author_email='symonsoft@gmail.com', - url='https://github.com/symonsoft/str2bool', - download_url='https://github.com/symonsoft/str2bool/tarball/1.1', - keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false'], - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Topic :: Utilities' - ], -) +from distutils.core import setup + +version = "1.2" + +setup( + name='str2bool', + packages=['str2bool'], + version=version, + description='Convert string to boolean', + author='SymonSoft', + author_email='symonsoft@gmail.com', + url='https://github.com/symonsoft/str2bool', + download_url="https://github.com/symonsoft/str2bool/tarball/{0}".format(version), + keywords=['str2bool', 'bool', 'boolean', 'convert', 'yes', 'no', 'true', 'false', 'enabled', 'disabled'], + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Topic :: Utilities' + ], +) diff --git a/str2bool/__init__.py b/str2bool/__init__.py index 4dc0017..afbf257 100644 --- a/str2bool/__init__.py +++ b/str2bool/__init__.py @@ -1,21 +1,20 @@ -import sys - -_true_set = {'yes', 'true', 't', 'y', '1'} -_false_set = {'no', 'false', 'f', 'n', '0'} - - -def str2bool(value, raise_exc=False): - if isinstance(value, str) or sys.version_info[0] < 3 and isinstance(value, basestring): - value = value.lower() - if value in _true_set: - return True - if value in _false_set: - return False - - if raise_exc: - raise ValueError('Expected "%s"' % '", "'.join(_true_set | _false_set)) - return None - - -def str2bool_exc(value): - return str2bool(value, raise_exc=True) +import sys + +_true_set = {'yes', 'true', 't', 'y', '1', 'enabled' } +_false_set = {'no', 'false', 'f', 'n', '0', 'disabled' } + + +def str2bool(value, raise_exc=False): + if isinstance(value, str) or sys.version_info[0] < 3 and isinstance(value, basestring): + value = value.lower() + if value in _true_set: + return True + if value in _false_set: + return False + if raise_exc: + raise ValueError('Expected "%s"' % '", "'.join(_true_set | _false_set)) + return None + + +def str2bool_exc(value): + return str2bool(value, raise_exc=True)