summaryrefslogtreecommitdiff
path: root/webtest
diff options
context:
space:
mode:
authorGael Pasgrimaud <gael@gawel.org>2017-10-21 14:25:44 +0200
committerGael Pasgrimaud <gael@gawel.org>2017-10-21 14:40:59 +0200
commitad31ea8c3ed7b50cb98e5610c8dd6e644ef07c31 (patch)
tree66edefa6353ef5ac14e8d7617a519e0e1d363b3d /webtest
parent496e83f9e09717cc327178d32725a281b37a2006 (diff)
downloadwebtest-ad31ea8c3ed7b50cb98e5610c8dd6e644ef07c31.tar.gz
avoid UnicodeDecodeError in linter with py2; fixed #186
Diffstat (limited to 'webtest')
-rw-r--r--webtest/lint.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/webtest/lint.py b/webtest/lint.py
index 8462f36..d80c148 100644
--- a/webtest/lint.py
+++ b/webtest/lint.py
@@ -122,6 +122,7 @@ import warnings
from six import PY3
from six import binary_type
from six import string_types
+from six import text_type
header_re = re.compile(r'^[a-zA-Z][a-zA-Z0-9\-_]*$')
bad_header_value_re = re.compile(r'[\000-\037]')
@@ -415,10 +416,12 @@ def check_status(status):
def _assert_latin1_str(string, message):
assert type(string) is str, message
- try:
- string.encode('latin1')
- except UnicodeEncodeError:
- raise AssertionError(message)
+ if type(string) is text_type:
+ try:
+ string.encode('latin1')
+ except UnicodeEncodeError:
+ raise AssertionError(message)
+ return string
def check_headers(headers):