mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Merge branch 'master' into quote-carets
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Handle alternate names for UTF-8 encoding.
|
||||
+21
-8
@@ -26,8 +26,8 @@ warnings.filterwarnings("ignore", category=ResourceWarning)
|
||||
|
||||
__all__ = [
|
||||
"NamedTemporaryFile", "Path", "ResourceWarning", "TemporaryDirectory",
|
||||
"get_terminal_size", "getpreferredencoding", "DEFAULT_ENCODING", "force_encoding",
|
||||
"UNICODE_TO_ASCII_TRANSLATION_MAP", "decode_output", "fix_utf8"
|
||||
"get_terminal_size", "getpreferredencoding", "DEFAULT_ENCODING", "canonical_encoding_name",
|
||||
"force_encoding", "UNICODE_TO_ASCII_TRANSLATION_MAP", "decode_output", "fix_utf8"
|
||||
]
|
||||
|
||||
|
||||
@@ -46,6 +46,16 @@ def getpreferredencoding():
|
||||
DEFAULT_ENCODING = getpreferredencoding()
|
||||
|
||||
|
||||
def canonical_encoding_name(name):
|
||||
import codecs
|
||||
try:
|
||||
codec = codecs.lookup(name)
|
||||
except LookupError:
|
||||
return name
|
||||
else:
|
||||
return codec.name
|
||||
|
||||
|
||||
# From https://github.com/CarlFK/veyepar/blob/5c5de47/dj/scripts/fixunicode.py
|
||||
# MIT LIcensed, thanks Carl!
|
||||
def force_encoding():
|
||||
@@ -57,20 +67,23 @@ def force_encoding():
|
||||
else:
|
||||
if not (stdout_isatty() and stderr_isatty()):
|
||||
return DEFAULT_ENCODING, DEFAULT_ENCODING
|
||||
stdout_encoding = sys.stdout.encoding
|
||||
stderr_encoding = sys.stderr.encoding
|
||||
stdout_encoding = canonical_encoding_name(sys.stdout.encoding)
|
||||
stderr_encoding = canonical_encoding_name(sys.stderr.encoding)
|
||||
if sys.platform == "win32" and sys.version_info >= (3, 1):
|
||||
return DEFAULT_ENCODING, DEFAULT_ENCODING
|
||||
if stdout_encoding.lower() != "utf-8" or stderr_encoding.lower() != "utf-8":
|
||||
if stdout_encoding != "utf-8" or stderr_encoding != "utf-8":
|
||||
|
||||
from ctypes import pythonapi, py_object, c_char_p
|
||||
try:
|
||||
from ctypes import pythonapi, py_object, c_char_p
|
||||
except ImportError:
|
||||
return DEFAULT_ENCODING, DEFAULT_ENCODING
|
||||
try:
|
||||
PyFile_SetEncoding = pythonapi.PyFile_SetEncoding
|
||||
except AttributeError:
|
||||
return DEFAULT_ENCODING, DEFAULT_ENCODING
|
||||
else:
|
||||
PyFile_SetEncoding.argtypes = (py_object, c_char_p)
|
||||
if stdout_encoding.lower() != "utf-8":
|
||||
if stdout_encoding != "utf-8":
|
||||
try:
|
||||
was_set = PyFile_SetEncoding(sys.stdout, "utf-8")
|
||||
except OSError:
|
||||
@@ -80,7 +93,7 @@ def force_encoding():
|
||||
else:
|
||||
stdout_encoding = "utf-8"
|
||||
|
||||
if stderr_encoding.lower() != "utf-8":
|
||||
if stderr_encoding != "utf-8":
|
||||
try:
|
||||
was_set = PyFile_SetEncoding(sys.stderr, "utf-8")
|
||||
except OSError:
|
||||
|
||||
Reference in New Issue
Block a user