borrow is_nonstr_iter from pyramid and use it instead of simple isinstance check
This commit is contained in:
@@ -11,6 +11,7 @@ from .compat import (
|
|||||||
text_type,
|
text_type,
|
||||||
string_types,
|
string_types,
|
||||||
xrange,
|
xrange,
|
||||||
|
is_nonstr_iter,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import iso8601
|
from . import iso8601
|
||||||
@@ -75,9 +76,9 @@ class Invalid(Exception):
|
|||||||
``msg`` attribute is iterable, it is returned. If it is not
|
``msg`` attribute is iterable, it is returned. If it is not
|
||||||
iterable, a single-element list containing the ``msg`` value
|
iterable, a single-element list containing the ``msg`` value
|
||||||
is returned."""
|
is returned."""
|
||||||
if isinstance(self.msg, string_types):
|
if is_nonstr_iter(self.msg):
|
||||||
return [self.msg]
|
return self.msg
|
||||||
return self.msg
|
return [self.msg]
|
||||||
|
|
||||||
def add(self, exc, pos=None):
|
def add(self, exc, pos=None):
|
||||||
""" Add a child exception; ``exc`` must be an instance of
|
""" Add a child exception; ``exc`` must be an instance of
|
||||||
|
@@ -16,6 +16,15 @@ def text_(s, encoding='latin-1', errors='strict'):
|
|||||||
return s.decode(encoding, errors)
|
return s.decode(encoding, errors)
|
||||||
return s # pragma: no cover
|
return s # pragma: no cover
|
||||||
|
|
||||||
|
if PY3: # pragma: no cover
|
||||||
|
def is_nonstr_iter(v):
|
||||||
|
if isinstance(v, str):
|
||||||
|
return False
|
||||||
|
return hasattr(v, '__iter__')
|
||||||
|
else:
|
||||||
|
def is_nonstr_iter(v):
|
||||||
|
return hasattr(v, '__iter__')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xrange = xrange
|
xrange = xrange
|
||||||
except NameError: # pragma: no cover
|
except NameError: # pragma: no cover
|
||||||
|
Reference in New Issue
Block a user