[constraints] fix check_password

Our converter for Password fields is 'str' (python2) or 'bytes' (python3). It makes no sense for the checker to allow StringIO values, whose conversion yields strings like '<StringIO.StringIO instance at 0xdeadbeef>', since that's going to end in tears. CubicWeb overrides the converter to pass its Binary type unmodified, so it could just as well override the checker to match.

Related to #267910.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset280621720b4e
branchdefault
phasepublic
hiddenno
parent revision#8091838787e8 [test] don't rely on a particular ordering for unsorted lists
child revision#ea96af284a53 Typo fix
files modified by this revision
constraints.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1413451890 -7200
# Thu Oct 16 11:31:30 2014 +0200
# Node ID 280621720b4e683a5de605413fa4764e66595c16
# Parent 8091838787e802ab9d07e7188b80cf303cc1f027
[constraints] fix check_password

Our converter for Password fields is 'str' (python2) or 'bytes'
(python3). It makes no sense for the checker to allow StringIO values,
whose conversion yields strings like '<StringIO.StringIO instance at
0xdeadbeef>', since that's going to end in tears.
CubicWeb overrides the converter to pass its Binary type unmodified, so
it could just as well override the checker to match.

Related to #267910.

diff --git a/constraints.py b/constraints.py
@@ -20,11 +20,10 @@
1  __docformat__ = "restructuredtext en"
2 
3  import re
4  import decimal
5  import operator
6 -from StringIO import StringIO
7 
8  from six import string_types, text_type, binary_type
9 
10  from logilab.common.deprecation import class_renamed
11 
@@ -471,11 +470,11 @@
12      """check value is an unicode string"""
13      return isinstance(value, text_type)
14 
15  def check_password(eschema, value):
16      """check value is an encoded string"""
17 -    return isinstance(value, (binary_type, StringIO))
18 +    return isinstance(value, binary_type)
19 
20  def check_int(eschema, value):
21      """check value is an integer"""
22      try:
23          int(value)