mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Handle sys.__stderr__.encoding not existing (#4599)
Handle sys.__stderr__.encoding not existing
This commit is contained in:
parent
ed60cdf10c
commit
d3f040e120
2 changed files with 9 additions and 1 deletions
1
news/3356.bugfix
Normal file
1
news/3356.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Don't assume sys.__stderr__.encoding exists
|
|
@ -96,7 +96,14 @@ def console_to_str(data):
|
||||||
# redirected and if we don't find an encoding we skip this
|
# redirected and if we don't find an encoding we skip this
|
||||||
# step (on the assumption that output is wrapped by something
|
# step (on the assumption that output is wrapped by something
|
||||||
# that won't fail).
|
# that won't fail).
|
||||||
output_encoding = sys.__stderr__.encoding
|
# The double getattr is to deal with the possibility that we're
|
||||||
|
# being called in a situation where sys.__stderr__ doesn't exist,
|
||||||
|
# or doesn't have an encoding attribute. Neither of these cases
|
||||||
|
# should occur in normal pip use, but there's no harm in checking
|
||||||
|
# in case people use pip in (unsupported) unusual situations.
|
||||||
|
output_encoding = getattr(getattr(sys, "__stderr__", None),
|
||||||
|
"encoding", None)
|
||||||
|
|
||||||
if output_encoding:
|
if output_encoding:
|
||||||
s = s.encode(output_encoding, errors="backslashreplace")
|
s = s.encode(output_encoding, errors="backslashreplace")
|
||||||
s = s.decode(output_encoding)
|
s = s.decode(output_encoding)
|
||||||
|
|
Loading…
Reference in a new issue