[yams] Binary instance passwords should not be given to str()

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset3f34d69e0c22
branchdefault
phasepublic
hiddenno
parent revision#76c7149d9076 [ldapfeed] don't crash if entity is None. Closes (superficialy) #2341266
child revision#98782f17dd84 [datafeed] give a dictionary as sourceparams to avoid crash if attempt to import the user is done
files modified by this revision
__init__.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1336052849 -7200
# Thu May 03 15:47:29 2012 +0200
# Node ID 3f34d69e0c22158d407b7ea61dc0b39638804ce7
# Parent 76c7149d90768572f93048054eed34d25c80b7d1
[yams] Binary instance passwords should not be given to str()

diff --git a/__init__.py b/__init__.py
@@ -39,10 +39,11 @@
1 
2  import sys, os, logging
3  from StringIO import StringIO
4 
5  from logilab.common.logging_ext import set_log_methods
6 +from yams.constraints import BASE_CONVERTERS
7 
8 
9  if os.environ.get('APYCOT_ROOT'):
10      logging.basicConfig(level=logging.CRITICAL)
11  else:
@@ -118,10 +119,17 @@
12              else:
13                  binary.write(fobj.read())
14          binary.seek(0)
15          return binary
16 
17 +def str_or_binary(value):
18 +    if isinstance(value, Binary):
19 +        return value
20 +    return str(value)
21 +BASE_CONVERTERS['Password'] = str_or_binary
22 +
23 +
24 
25  # use this dictionary to rename entity types while keeping bw compat
26  ETYPE_NAME_MAP = {}
27 
28  # XXX cubic web cube migration map. See if it's worth keeping this mecanism