Skip to content

Commit

Permalink
backslash unicode charcaters in _read()
Browse files Browse the repository at this point in the history
  • Loading branch information
lexming committed Oct 22, 2020
1 parent 7f64734 commit 22be9bc
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/vsc/install/shared_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,9 @@ def file_read(file_handle, read_lines):
with open(source) as file_handle:
txt = file_read(file_handle, read_lines)
except UnicodeDecodeError:
# Python 3 fails to read file encoded in utf-8, try again setting the encoding
with open(source, encoding='utf-8') as file_handle:
# file contains unicode characters, try again backslashing them
with open(source, encoding='ascii', errors="backslashreplace") as file_handle:
txt = file_read(file_handle, read_lines)
# decode to ASCII removing non-conformant characters
if read_lines:
txt = [line.encode('utf-8').decode('ascii', 'ignore') for line in txt]
else:
txt = txt.encode('utf-8').decode('ascii', 'ignore')

return txt

Expand Down

0 comments on commit 22be9bc

Please sign in to comment.