Py3: Handle bytes case in inner_repr

This commit is contained in:
Shadab Zafar 2016-05-08 16:20:27 +05:30
parent e5cebb81fb
commit 22e4bc1938
2 changed files with 3 additions and 1 deletions

View File

@ -60,7 +60,8 @@ def inner_repr(s):
Returns the inner portion of a string or unicode repr (i.e. without the Returns the inner portion of a string or unicode repr (i.e. without the
quotes) quotes)
""" """
if six.PY2 and isinstance(s, unicode): if (six.PY2 and isinstance(s, unicode)) or \
(six.PY3 and isinstance(s, bytes)):
return repr(s)[2:-1] return repr(s)[2:-1]
else: else:
return repr(s)[1:-1] return repr(s)[1:-1]

View File

@ -30,6 +30,7 @@ def test_data_path():
def test_inner_repr(): def test_inner_repr():
assert utils.inner_repr("\x66") == "\x66" assert utils.inner_repr("\x66") == "\x66"
assert utils.inner_repr(u"foo") == "foo" assert utils.inner_repr(u"foo") == "foo"
assert utils.inner_repr(b"foo") == "foo"
def test_escape_unprintables(): def test_escape_unprintables():