Skip to content

Commit

Permalink
Merge pull request #3132 from pypa/bugfix/3131-better-output-encoding
Browse files Browse the repository at this point in the history
Fix unicode encoding to replace non-ascii chars
  • Loading branch information
techalchemy authored Oct 31, 2018
2 parents 8bda09e + 8c659f1 commit e3ee806
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/3131.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added additional logic for ignoring and replacing non-ascii characters when formatting console output on non-UTF-8 systems.
5 changes: 3 additions & 2 deletions pipenv/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,12 @@ def decode_output(output):
return output
try:
output = output.encode(DEFAULT_ENCODING)
except (AttributeError, UnicodeDecodeError):
except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):
if six.PY2:
output = unicode.translate(vistir.misc.to_text(output),
UNICODE_TO_ASCII_TRANSLATION_MAP)
else:
output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)
output = output.decode(DEFAULT_ENCODING)
output = output.encode(DEFAULT_ENCODING, "replace")
return vistir.misc.to_text(output, encoding=DEFAULT_ENCODING, errors="replace")
return output

0 comments on commit e3ee806

Please sign in to comment.