Add custom checker for Password values
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 17 Oct 2014 12:14:58 +0200
changeset 10045 0a49d61c8cca
parent 10044 5907c2b0acd7
child 10066 313ce53a7232
Add custom checker for Password values We override the default converter to pass Binary values through, but don't do anything about the checker. This worked previously because yams allowed StringIO instances, although its converter didn't do the right thing for them. Fixing this in yams requires that we properly register a checker.
__init__.py
--- a/__init__.py	Wed Oct 22 15:59:52 2014 +0200
+++ b/__init__.py	Fri Oct 17 12:14:58 2014 +0200
@@ -42,7 +42,7 @@
 
 from logilab.common.deprecation import deprecated
 from logilab.common.logging_ext import set_log_methods
-from yams.constraints import BASE_CONVERTERS
+from yams.constraints import BASE_CONVERTERS, BASE_CHECKERS
 
 # pre python 2.7.2 safety
 logging.basicConfig()
@@ -140,6 +140,10 @@
         return cPickle.loads(zlib.decompress(self.getvalue()))
 
 
+def check_password(eschema, value):
+    return isinstance(value, (str, Binary))
+BASE_CHECKERS['Password'] = check_password
+
 def str_or_binary(value):
     if isinstance(value, Binary):
         return value