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,
|
||||
string_types,
|
||||
xrange,
|
||||
is_nonstr_iter,
|
||||
)
|
||||
|
||||
from . import iso8601
|
||||
@@ -75,9 +76,9 @@ class Invalid(Exception):
|
||||
``msg`` attribute is iterable, it is returned. If it is not
|
||||
iterable, a single-element list containing the ``msg`` value
|
||||
is returned."""
|
||||
if isinstance(self.msg, string_types):
|
||||
return [self.msg]
|
||||
if is_nonstr_iter(self.msg):
|
||||
return self.msg
|
||||
return [self.msg]
|
||||
|
||||
def add(self, exc, pos=None):
|
||||
""" 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 # 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:
|
||||
xrange = xrange
|
||||
except NameError: # pragma: no cover
|
||||
|
Reference in New Issue
Block a user