From 04436578c7ef1ea740558cb12ee1e43776511ac1 Mon Sep 17 00:00:00 2001 From: "vince.parker" Date: Wed, 24 Nov 2021 15:16:44 -0800 Subject: [PATCH 1/2] update selections for boolean false --- colander_tools/strict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colander_tools/strict.py b/colander_tools/strict.py index 28d2905..c2668b5 100644 --- a/colander_tools/strict.py +++ b/colander_tools/strict.py @@ -86,7 +86,7 @@ def deserialize(self, node, cstruct): raise Invalid(node, _('${val} is not a boolean', mapping={'val': cstruct})) result = result.lower() - if result in ('false', '0'): + if result in ('false', '0', 'disabled', 'untrue'): return False return True From 40d6d6d4fa69094add477b06c53245c887df7b35 Mon Sep 17 00:00:00 2001 From: "vince.parker" Date: Thu, 25 Nov 2021 14:28:52 -0800 Subject: [PATCH 2/2] Implementing false_choices like colander.Boolean --- colander_tools/strict.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/colander_tools/strict.py b/colander_tools/strict.py index c2668b5..419449d 100644 --- a/colander_tools/strict.py +++ b/colander_tools/strict.py @@ -67,6 +67,13 @@ class Boolean(SchemaType): On deserialize, accepts a boolean or a boolean represented as a string. """ + def __init__( + self, + false_choices=('false', '0', 'disabled', 'untrue'), + ): + + self.false_choices = false_choices + def serialize(self, node, appstruct): # noqa if appstruct is null: return null @@ -86,7 +93,7 @@ def deserialize(self, node, cstruct): raise Invalid(node, _('${val} is not a boolean', mapping={'val': cstruct})) result = result.lower() - if result in ('false', '0', 'disabled', 'untrue'): + if result in self.false_choices: return False return True