Skip to content

Commit

Permalink
Update exasol/utils.py
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Coretti <[email protected]>
  • Loading branch information
ahsimb and Nicoretti authored Jan 8, 2024
1 parent fe612f7 commit f595167
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions exasol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ def optional_str_to_bool(value: Optional[str]) -> Optional[bool]:
Case-insensitive "n", "no", "false" => False
Any other value cause a ValueError exception.
"""
if value is None:
if not value:
return None
value_l = value.lower()
if value_l in ["y", "yes", "true"]:
return True
elif value_l in ["n", "no", "false"]:
return False
else:
raise ValueError("Invalid boolean value " + value)

mapping = {
'y': True,
'yes': True,
'true': True,
'n': False,
'no': False,
'false': False,
}
key = value.lower()

try:
result = mapping[key]
except KeyError as ex:
raise ValueError("Invalid boolean value " + value) from ex

return result

0 comments on commit f595167

Please sign in to comment.