[yams] Binary instance passwords should not be given to str()
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 03 May 2012 15:47:29 +0200
changeset 8383 3f34d69e0c22
parent 8382 76c7149d9076
child 8384 98782f17dd84
[yams] Binary instance passwords should not be given to str()
__init__.py
--- a/__init__.py	Thu May 03 15:45:58 2012 +0200
+++ b/__init__.py	Thu May 03 15:47:29 2012 +0200
@@ -41,6 +41,7 @@
 from StringIO import StringIO
 
 from logilab.common.logging_ext import set_log_methods
+from yams.constraints import BASE_CONVERTERS
 
 
 if os.environ.get('APYCOT_ROOT'):
@@ -120,6 +121,13 @@
         binary.seek(0)
         return binary
 
+def str_or_binary(value):
+    if isinstance(value, Binary):
+        return value
+    return str(value)
+BASE_CONVERTERS['Password'] = str_or_binary
+
+
 
 # use this dictionary to rename entity types while keeping bw compat
 ETYPE_NAME_MAP = {}