[constraints] update check_password for py3k

We require a byte array or some kind of stream. (Mostly used with cubicweb's Binary type.)

I'm not sure this check makes all that much sense, or that it shouldn't be implemented some other way, but that's something for another day.

Related to #267910.

authorJulien Cristau <julien.cristau@logilab.fr>
changesete1e4ba4e19e3
branchdefault
phasedraft
hiddenyes
parent revision#8091838787e8 [test] don't rely on a particular ordering for unsorted lists
child revision<not specified>
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 e1e4ba4e19e39d6877a10200c52cd84184669c0b
# Parent 8091838787e802ab9d07e7188b80cf303cc1f027
[constraints] update check_password for py3k

We require a byte array or some kind of stream. (Mostly used with
cubicweb's Binary type.)

I'm not sure this check makes all that much sense, or that it shouldn't
be implemented some other way, but that's something for another day.

Related to #267910.

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