48 lines
1.1 KiB
Diff
48 lines
1.1 KiB
Diff
From afc63cafd4388310f865fb0fba3165a228796049 Mon Sep 17 00:00:00 2001
|
|
From: Angie Wang <Angie.Wang@windriver.com>
|
|
Date: Mon, 28 May 2018 20:12:43 -0400
|
|
Subject: [PATCH 1/1] add NotIn validation
|
|
|
|
---
|
|
voluptuous.py | 24 ++++++++++++++++++++++++
|
|
1 file changed, 24 insertions(+)
|
|
|
|
diff --git a/voluptuous.py b/voluptuous.py
|
|
index 5b561b1..b4ed666 100644
|
|
--- a/voluptuous.py
|
|
+++ b/voluptuous.py
|
|
@@ -1584,6 +1584,30 @@ def In(container, msg=None):
|
|
return validator
|
|
|
|
|
|
+class NotInInvalid(Invalid):
|
|
+ pass
|
|
+
|
|
+
|
|
+class NotIn(object):
|
|
+ """Validate that a value is not in a collection."""
|
|
+
|
|
+ def __init__(self, container, msg=None):
|
|
+ self.container = container
|
|
+ self.msg = msg
|
|
+
|
|
+ def __call__(self, v):
|
|
+ try:
|
|
+ check = v in self.container
|
|
+ except TypeError:
|
|
+ check = True
|
|
+ if check:
|
|
+ raise NotInInvalid(self.msg or 'value is not allowed')
|
|
+ return v
|
|
+
|
|
+ def __repr__(self):
|
|
+ return 'NotIn(%s)' % (self.container,)
|
|
+
|
|
+
|
|
def Lower(v):
|
|
"""Transform a string to lower case.
|
|
|
|
--
|
|
1.8.3.1
|
|
|