Fix a python_bytes_to_unicode issue, fixes #107

This commit is contained in:
Dave Halter committed 2020-05-14 23:34:14 +02:00
1 parent 15403fd998
commit 1b4c75608a
2 files changed
+25 -2

No files matched your search

+11 -2
View File
@@ -105,8 +105,17 @@ def python_bytes_to_unicode(source, encoding='utf-8', errors='strict'):
if not isinstance(encoding, unicode):
encoding = unicode(encoding, 'utf-8', 'replace')
# Cast to unicode
return unicode(source, encoding, errors)
try:
# Cast to unicode
return unicode(source, encoding, errors)
except LookupError:
if errors == 'replace':
# This is a weird case that can happen if the given encoding is not
# a valid encoding. This usually shouldn't happen with provided
# encodings, but can happen if somebody uses encoding declarations
# like `# coding: foo-8`.
return unicode(source, 'utf-8', errors)
raise
def version_info():