Commit 5d56fa79 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by Vincent A

to_unicode: Handle memoryview

Otherwise unicode() on a memoryview will not actually read the text
I've encountered this type while making a Codec class calling
parent 74133769
......@@ -29,7 +29,7 @@ from .compat import unicode
__all__ = ['get_backtrace', 'get_bytes_size', 'iter_fields',
'to_unicode', 'input', 'limit', 'find_exe']
'to_unicode', 'input', 'limit', 'find_exe']
def get_backtrace(empty="Empty backtrace."):
......@@ -88,6 +88,9 @@ def to_unicode(text):
if isinstance(text, unicode):
return text
if isinstance(text, memoryview):
text = text.tobytes()
if not isinstance(text, bytes):
if sys.version_info.major >= 3:
return unicode(text)
......@@ -197,4 +200,3 @@ def find_exe(basename):
fpath = os.path.join(path, ex)
if os.path.exists(fpath) and os.access(fpath, os.X_OK):
return fpath
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment