Skip to content

Commit

Permalink
Implement smarter boolean support
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Nov 3, 2015
1 parent 694def4 commit c91e59c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hug/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def comma_separated_list(value):

def smart_boolean(input_value):
'''Accepts a true or false value'''
if type(input_value) == bool or input_value is None:
if type(input_value) == bool or input_value in (None, 1, 0):
return bool(input_value)

value = input_value.lower()
if value == 'true':
if value in ('true', 't', '1'):
return True
elif value in ('false', ''):
elif value in ('false', 'f', '0', ''):
return False

raise KeyError('Invalid value passed in for true/false field')
Expand Down

0 comments on commit c91e59c

Please sign in to comment.