We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Incompatibility with pypy3


### Issue description

Recent versions of pipenv no longer work with pypy3.


### Expected result

Expected pipenv to work.

### Actual result

```
❯ PYENV_VERSION=pypy3.5-6.0.0 pyenv exec pipenv --verbose
Traceback (most recent call last):
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/bin/pipenv", line 7, in <module>
    from pipenv import cli
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/__init__.py", line 47, in <module>
    from .cli import cli
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/__init__.py", line 3, in <module>
    from .command import cli
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/command.py", line 19, in <module>
    from .options import (
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/options.py", line 11, in <module>
    from .. import environments
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/environments.py", line 7, in <module>
    from ._compat import fix_utf8
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/_compat.py", line 98, in <module>
    OUT_ENCODING, ERR_ENCODING = force_encoding()
  File "/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/_compat.py", line 68, in force_encoding
    from ctypes import pythonapi, py_object, c_char_p
ImportError: cannot import name 'pythonapi'
```


### Steps to replicate

Simply install pipenv with PyPy3, then try to run any pipenv command.

-------------------------------------------------------------------------------

`pipenv --support` won't work either.

PyPy doesn't support `ctypes.pythonapi`, but the root cause of the issue is that it shouldn't even try to import this module in the first place. I've investigated a bit and it looks with PyPy3, `sys.stdout.encoding` returns `"utf8"` instead of `"utf-8"`. I'm unsure whether this is a PyPy bug or not, but since pipenv used to work fine with PyPy3 prior to (I think) #3096, can we relax the condition on [this line](https://github.com/pypa/pipenv/blob/b03983e61ef284157c725dfedef02fef5829341f/pipenv/_compat.py#L64) to allow for `"utf8"` as well as `"utf-8"`?



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pipenv/_compat.py`
Content:
```
1 # -*- coding=utf-8 -*-
2 """A compatibility module for pipenv's backports and manipulations.
3 
4 Exposes a standard API that enables compatibility across python versions,
5 operating systems, etc.
6 """
7 
8 import functools
9 import importlib
10 import io
11 import os
12 import six
13 import sys
14 import warnings
15 import vistir
16 from .vendor.vistir.compat import NamedTemporaryFile, Path, ResourceWarning, TemporaryDirectory
17 
18 # Backport required for earlier versions of Python.
19 if sys.version_info < (3, 3):
20     from .vendor.backports.shutil_get_terminal_size import get_terminal_size
21 else:
22     from shutil import get_terminal_size
23 
24 warnings.filterwarnings("ignore", category=ResourceWarning)
25 
26 
27 __all__ = [
28     "NamedTemporaryFile", "Path", "ResourceWarning", "TemporaryDirectory",
29     "get_terminal_size", "getpreferredencoding", "DEFAULT_ENCODING", "force_encoding",
30     "UNICODE_TO_ASCII_TRANSLATION_MAP", "decode_output", "fix_utf8"
31 ]
32 
33 
34 def getpreferredencoding():
35     import locale
36     # Borrowed from Invoke
37     # (see https://github.com/pyinvoke/invoke/blob/93af29d/invoke/runners.py#L881)
38     _encoding = locale.getpreferredencoding(False)
39     if six.PY2 and not sys.platform == "win32":
40         _default_encoding = locale.getdefaultlocale()[1]
41         if _default_encoding is not None:
42             _encoding = _default_encoding
43     return _encoding
44 
45 
46 DEFAULT_ENCODING = getpreferredencoding()
47 
48 
49 # From https://github.com/CarlFK/veyepar/blob/5c5de47/dj/scripts/fixunicode.py
50 # MIT LIcensed, thanks Carl!
51 def force_encoding():
52     try:
53         stdout_isatty = sys.stdout.isatty
54         stderr_isatty = sys.stderr.isatty
55     except AttributeError:
56         return DEFAULT_ENCODING, DEFAULT_ENCODING
57     else:
58         if not (stdout_isatty() and stderr_isatty()):
59             return DEFAULT_ENCODING, DEFAULT_ENCODING
60     stdout_encoding = sys.stdout.encoding
61     stderr_encoding = sys.stderr.encoding
62     if sys.platform == "win32" and sys.version_info >= (3, 1):
63         return DEFAULT_ENCODING, DEFAULT_ENCODING
64     if stdout_encoding.lower() != "utf-8" or stderr_encoding.lower() != "utf-8":
65 
66         from ctypes import pythonapi, py_object, c_char_p
67         try:
68             PyFile_SetEncoding = pythonapi.PyFile_SetEncoding
69         except AttributeError:
70             return DEFAULT_ENCODING, DEFAULT_ENCODING
71         else:
72             PyFile_SetEncoding.argtypes = (py_object, c_char_p)
73             if stdout_encoding.lower() != "utf-8":
74                 try:
75                     was_set = PyFile_SetEncoding(sys.stdout, "utf-8")
76                 except OSError:
77                     was_set = False
78                 if not was_set:
79                     stdout_encoding = DEFAULT_ENCODING
80                 else:
81                     stdout_encoding = "utf-8"
82 
83             if stderr_encoding.lower() != "utf-8":
84                 try:
85                     was_set = PyFile_SetEncoding(sys.stderr, "utf-8")
86                 except OSError:
87                     was_set = False
88                 if not was_set:
89                     stderr_encoding = DEFAULT_ENCODING
90                 else:
91                     stderr_encoding = "utf-8"
92 
93     return stdout_encoding, stderr_encoding
94 
95 
96 OUT_ENCODING, ERR_ENCODING = force_encoding()
97 
98 
99 UNICODE_TO_ASCII_TRANSLATION_MAP = {
100     8230: u"...",
101     8211: u"-",
102     10004: u"OK",
103     10008: u"x",
104 }
105 
106 
107 def decode_output(output):
108     if not isinstance(output, six.string_types):
109         return output
110     try:
111         output = output.encode(DEFAULT_ENCODING)
112     except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):
113         if six.PY2:
114             output = unicode.translate(vistir.misc.to_text(output),
115                                        UNICODE_TO_ASCII_TRANSLATION_MAP)
116         else:
117             output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)
118         output = output.encode(DEFAULT_ENCODING, "replace")
119     return vistir.misc.to_text(output, encoding=DEFAULT_ENCODING, errors="replace")
120 
121 
122 def fix_utf8(text):
123     if not isinstance(text, six.string_types):
124         return text
125     try:
126         text = decode_output(text)
127     except UnicodeDecodeError:
128         if six.PY2:
129             text = unicode.translate(vistir.misc.to_text(text), UNICODE_TO_ASCII_TRANSLATION_MAP)
130     return text
131
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pipenv/_compat.py b/pipenv/_compat.py
--- a/pipenv/_compat.py
+++ b/pipenv/_compat.py
@@ -26,8 +26,8 @@
 
 __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 @@
 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 @@
     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 @@
                 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:

{"golden_diff": "diff --git a/pipenv/_compat.py b/pipenv/_compat.py\n--- a/pipenv/_compat.py\n+++ b/pipenv/_compat.py\n@@ -26,8 +26,8 @@\n \n __all__ = [\n     \"NamedTemporaryFile\", \"Path\", \"ResourceWarning\", \"TemporaryDirectory\",\n-    \"get_terminal_size\", \"getpreferredencoding\", \"DEFAULT_ENCODING\", \"force_encoding\",\n-    \"UNICODE_TO_ASCII_TRANSLATION_MAP\", \"decode_output\", \"fix_utf8\"\n+    \"get_terminal_size\", \"getpreferredencoding\", \"DEFAULT_ENCODING\", \"canonical_encoding_name\",\n+    \"force_encoding\", \"UNICODE_TO_ASCII_TRANSLATION_MAP\", \"decode_output\", \"fix_utf8\"\n ]\n \n \n@@ -46,6 +46,16 @@\n DEFAULT_ENCODING = getpreferredencoding()\n \n \n+def canonical_encoding_name(name):\n+    import codecs\n+    try:\n+        codec = codecs.lookup(name)\n+    except LookupError:\n+        return name\n+    else:\n+        return codec.name\n+\n+\n # From https://github.com/CarlFK/veyepar/blob/5c5de47/dj/scripts/fixunicode.py\n # MIT LIcensed, thanks Carl!\n def force_encoding():\n@@ -57,20 +67,23 @@\n     else:\n         if not (stdout_isatty() and stderr_isatty()):\n             return DEFAULT_ENCODING, DEFAULT_ENCODING\n-    stdout_encoding = sys.stdout.encoding\n-    stderr_encoding = sys.stderr.encoding\n+    stdout_encoding = canonical_encoding_name(sys.stdout.encoding)\n+    stderr_encoding = canonical_encoding_name(sys.stderr.encoding)\n     if sys.platform == \"win32\" and sys.version_info >= (3, 1):\n         return DEFAULT_ENCODING, DEFAULT_ENCODING\n-    if stdout_encoding.lower() != \"utf-8\" or stderr_encoding.lower() != \"utf-8\":\n+    if stdout_encoding != \"utf-8\" or stderr_encoding != \"utf-8\":\n \n-        from ctypes import pythonapi, py_object, c_char_p\n+        try:\n+            from ctypes import pythonapi, py_object, c_char_p\n+        except ImportError:\n+            return DEFAULT_ENCODING, DEFAULT_ENCODING\n         try:\n             PyFile_SetEncoding = pythonapi.PyFile_SetEncoding\n         except AttributeError:\n             return DEFAULT_ENCODING, DEFAULT_ENCODING\n         else:\n             PyFile_SetEncoding.argtypes = (py_object, c_char_p)\n-            if stdout_encoding.lower() != \"utf-8\":\n+            if stdout_encoding != \"utf-8\":\n                 try:\n                     was_set = PyFile_SetEncoding(sys.stdout, \"utf-8\")\n                 except OSError:\n@@ -80,7 +93,7 @@\n                 else:\n                     stdout_encoding = \"utf-8\"\n \n-            if stderr_encoding.lower() != \"utf-8\":\n+            if stderr_encoding != \"utf-8\":\n                 try:\n                     was_set = PyFile_SetEncoding(sys.stderr, \"utf-8\")\n                 except OSError:\n", "issue": "Incompatibility with pypy3\n\r\n\r\n### Issue description\r\n\r\nRecent versions of pipenv no longer work with pypy3.\r\n\r\n\r\n### Expected result\r\n\r\nExpected pipenv to work.\r\n\r\n### Actual result\r\n\r\n```\r\n\u276f PYENV_VERSION=pypy3.5-6.0.0 pyenv exec pipenv --verbose\r\nTraceback (most recent call last):\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/bin/pipenv\", line 7, in <module>\r\n    from pipenv import cli\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/__init__.py\", line 47, in <module>\r\n    from .cli import cli\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/__init__.py\", line 3, in <module>\r\n    from .command import cli\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/command.py\", line 19, in <module>\r\n    from .options import (\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/cli/options.py\", line 11, in <module>\r\n    from .. import environments\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/environments.py\", line 7, in <module>\r\n    from ._compat import fix_utf8\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/_compat.py\", line 98, in <module>\r\n    OUT_ENCODING, ERR_ENCODING = force_encoding()\r\n  File \"/Users/ob/.pyenv/versions/pypy3.5-6.0.0/site-packages/pipenv/_compat.py\", line 68, in force_encoding\r\n    from ctypes import pythonapi, py_object, c_char_p\r\nImportError: cannot import name 'pythonapi'\r\n```\r\n\r\n\r\n### Steps to replicate\r\n\r\nSimply install pipenv with PyPy3, then try to run any pipenv command.\r\n\r\n-------------------------------------------------------------------------------\r\n\r\n`pipenv --support` won't work either.\r\n\r\nPyPy doesn't support `ctypes.pythonapi`, but the root cause of the issue is that it shouldn't even try to import this module in the first place. I've investigated a bit and it looks with PyPy3, `sys.stdout.encoding` returns `\"utf8\"` instead of `\"utf-8\"`. I'm unsure whether this is a PyPy bug or not, but since pipenv used to work fine with PyPy3 prior to (I think) #3096, can we relax the condition on [this line](https://github.com/pypa/pipenv/blob/b03983e61ef284157c725dfedef02fef5829341f/pipenv/_compat.py#L64) to allow for `\"utf8\"` as well as `\"utf-8\"`?\r\n\r\n\n", "before_files": [{"content": "# -*- coding=utf-8 -*-\n\"\"\"A compatibility module for pipenv's backports and manipulations.\n\nExposes a standard API that enables compatibility across python versions,\noperating systems, etc.\n\"\"\"\n\nimport functools\nimport importlib\nimport io\nimport os\nimport six\nimport sys\nimport warnings\nimport vistir\nfrom .vendor.vistir.compat import NamedTemporaryFile, Path, ResourceWarning, TemporaryDirectory\n\n# Backport required for earlier versions of Python.\nif sys.version_info < (3, 3):\n    from .vendor.backports.shutil_get_terminal_size import get_terminal_size\nelse:\n    from shutil import get_terminal_size\n\nwarnings.filterwarnings(\"ignore\", category=ResourceWarning)\n\n\n__all__ = [\n    \"NamedTemporaryFile\", \"Path\", \"ResourceWarning\", \"TemporaryDirectory\",\n    \"get_terminal_size\", \"getpreferredencoding\", \"DEFAULT_ENCODING\", \"force_encoding\",\n    \"UNICODE_TO_ASCII_TRANSLATION_MAP\", \"decode_output\", \"fix_utf8\"\n]\n\n\ndef getpreferredencoding():\n    import locale\n    # Borrowed from Invoke\n    # (see https://github.com/pyinvoke/invoke/blob/93af29d/invoke/runners.py#L881)\n    _encoding = locale.getpreferredencoding(False)\n    if six.PY2 and not sys.platform == \"win32\":\n        _default_encoding = locale.getdefaultlocale()[1]\n        if _default_encoding is not None:\n            _encoding = _default_encoding\n    return _encoding\n\n\nDEFAULT_ENCODING = getpreferredencoding()\n\n\n# From https://github.com/CarlFK/veyepar/blob/5c5de47/dj/scripts/fixunicode.py\n# MIT LIcensed, thanks Carl!\ndef force_encoding():\n    try:\n        stdout_isatty = sys.stdout.isatty\n        stderr_isatty = sys.stderr.isatty\n    except AttributeError:\n        return DEFAULT_ENCODING, DEFAULT_ENCODING\n    else:\n        if not (stdout_isatty() and stderr_isatty()):\n            return DEFAULT_ENCODING, DEFAULT_ENCODING\n    stdout_encoding = sys.stdout.encoding\n    stderr_encoding = sys.stderr.encoding\n    if sys.platform == \"win32\" and sys.version_info >= (3, 1):\n        return DEFAULT_ENCODING, DEFAULT_ENCODING\n    if stdout_encoding.lower() != \"utf-8\" or stderr_encoding.lower() != \"utf-8\":\n\n        from ctypes import pythonapi, py_object, c_char_p\n        try:\n            PyFile_SetEncoding = pythonapi.PyFile_SetEncoding\n        except AttributeError:\n            return DEFAULT_ENCODING, DEFAULT_ENCODING\n        else:\n            PyFile_SetEncoding.argtypes = (py_object, c_char_p)\n            if stdout_encoding.lower() != \"utf-8\":\n                try:\n                    was_set = PyFile_SetEncoding(sys.stdout, \"utf-8\")\n                except OSError:\n                    was_set = False\n                if not was_set:\n                    stdout_encoding = DEFAULT_ENCODING\n                else:\n                    stdout_encoding = \"utf-8\"\n\n            if stderr_encoding.lower() != \"utf-8\":\n                try:\n                    was_set = PyFile_SetEncoding(sys.stderr, \"utf-8\")\n                except OSError:\n                    was_set = False\n                if not was_set:\n                    stderr_encoding = DEFAULT_ENCODING\n                else:\n                    stderr_encoding = \"utf-8\"\n\n    return stdout_encoding, stderr_encoding\n\n\nOUT_ENCODING, ERR_ENCODING = force_encoding()\n\n\nUNICODE_TO_ASCII_TRANSLATION_MAP = {\n    8230: u\"...\",\n    8211: u\"-\",\n    10004: u\"OK\",\n    10008: u\"x\",\n}\n\n\ndef decode_output(output):\n    if not isinstance(output, six.string_types):\n        return output\n    try:\n        output = output.encode(DEFAULT_ENCODING)\n    except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):\n        if six.PY2:\n            output = unicode.translate(vistir.misc.to_text(output),\n                                       UNICODE_TO_ASCII_TRANSLATION_MAP)\n        else:\n            output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)\n        output = output.encode(DEFAULT_ENCODING, \"replace\")\n    return vistir.misc.to_text(output, encoding=DEFAULT_ENCODING, errors=\"replace\")\n\n\ndef fix_utf8(text):\n    if not isinstance(text, six.string_types):\n        return text\n    try:\n        text = decode_output(text)\n    except UnicodeDecodeError:\n        if six.PY2:\n            text = unicode.translate(vistir.misc.to_text(text), UNICODE_TO_ASCII_TRANSLATION_MAP)\n    return text\n", "path": "pipenv/_compat.py"}], "after_files": [{"content": "# -*- coding=utf-8 -*-\n\"\"\"A compatibility module for pipenv's backports and manipulations.\n\nExposes a standard API that enables compatibility across python versions,\noperating systems, etc.\n\"\"\"\n\nimport functools\nimport importlib\nimport io\nimport os\nimport six\nimport sys\nimport warnings\nimport vistir\nfrom .vendor.vistir.compat import NamedTemporaryFile, Path, ResourceWarning, TemporaryDirectory\n\n# Backport required for earlier versions of Python.\nif sys.version_info < (3, 3):\n    from .vendor.backports.shutil_get_terminal_size import get_terminal_size\nelse:\n    from shutil import get_terminal_size\n\nwarnings.filterwarnings(\"ignore\", category=ResourceWarning)\n\n\n__all__ = [\n    \"NamedTemporaryFile\", \"Path\", \"ResourceWarning\", \"TemporaryDirectory\",\n    \"get_terminal_size\", \"getpreferredencoding\", \"DEFAULT_ENCODING\", \"canonical_encoding_name\",\n    \"force_encoding\", \"UNICODE_TO_ASCII_TRANSLATION_MAP\", \"decode_output\", \"fix_utf8\"\n]\n\n\ndef getpreferredencoding():\n    import locale\n    # Borrowed from Invoke\n    # (see https://github.com/pyinvoke/invoke/blob/93af29d/invoke/runners.py#L881)\n    _encoding = locale.getpreferredencoding(False)\n    if six.PY2 and not sys.platform == \"win32\":\n        _default_encoding = locale.getdefaultlocale()[1]\n        if _default_encoding is not None:\n            _encoding = _default_encoding\n    return _encoding\n\n\nDEFAULT_ENCODING = getpreferredencoding()\n\n\ndef canonical_encoding_name(name):\n    import codecs\n    try:\n        codec = codecs.lookup(name)\n    except LookupError:\n        return name\n    else:\n        return codec.name\n\n\n# From https://github.com/CarlFK/veyepar/blob/5c5de47/dj/scripts/fixunicode.py\n# MIT LIcensed, thanks Carl!\ndef force_encoding():\n    try:\n        stdout_isatty = sys.stdout.isatty\n        stderr_isatty = sys.stderr.isatty\n    except AttributeError:\n        return DEFAULT_ENCODING, DEFAULT_ENCODING\n    else:\n        if not (stdout_isatty() and stderr_isatty()):\n            return DEFAULT_ENCODING, DEFAULT_ENCODING\n    stdout_encoding = canonical_encoding_name(sys.stdout.encoding)\n    stderr_encoding = canonical_encoding_name(sys.stderr.encoding)\n    if sys.platform == \"win32\" and sys.version_info >= (3, 1):\n        return DEFAULT_ENCODING, DEFAULT_ENCODING\n    if stdout_encoding != \"utf-8\" or stderr_encoding != \"utf-8\":\n\n        try:\n            from ctypes import pythonapi, py_object, c_char_p\n        except ImportError:\n            return DEFAULT_ENCODING, DEFAULT_ENCODING\n        try:\n            PyFile_SetEncoding = pythonapi.PyFile_SetEncoding\n        except AttributeError:\n            return DEFAULT_ENCODING, DEFAULT_ENCODING\n        else:\n            PyFile_SetEncoding.argtypes = (py_object, c_char_p)\n            if stdout_encoding != \"utf-8\":\n                try:\n                    was_set = PyFile_SetEncoding(sys.stdout, \"utf-8\")\n                except OSError:\n                    was_set = False\n                if not was_set:\n                    stdout_encoding = DEFAULT_ENCODING\n                else:\n                    stdout_encoding = \"utf-8\"\n\n            if stderr_encoding != \"utf-8\":\n                try:\n                    was_set = PyFile_SetEncoding(sys.stderr, \"utf-8\")\n                except OSError:\n                    was_set = False\n                if not was_set:\n                    stderr_encoding = DEFAULT_ENCODING\n                else:\n                    stderr_encoding = \"utf-8\"\n\n    return stdout_encoding, stderr_encoding\n\n\nOUT_ENCODING, ERR_ENCODING = force_encoding()\n\n\nUNICODE_TO_ASCII_TRANSLATION_MAP = {\n    8230: u\"...\",\n    8211: u\"-\",\n    10004: u\"OK\",\n    10008: u\"x\",\n}\n\n\ndef decode_output(output):\n    if not isinstance(output, six.string_types):\n        return output\n    try:\n        output = output.encode(DEFAULT_ENCODING)\n    except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):\n        if six.PY2:\n            output = unicode.translate(vistir.misc.to_text(output),\n                                       UNICODE_TO_ASCII_TRANSLATION_MAP)\n        else:\n            output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)\n        output = output.encode(DEFAULT_ENCODING, \"replace\")\n    return vistir.misc.to_text(output, encoding=DEFAULT_ENCODING, errors=\"replace\")\n\n\ndef fix_utf8(text):\n    if not isinstance(text, six.string_types):\n        return text\n    try:\n        text = decode_output(text)\n    except UnicodeDecodeError:\n        if six.PY2:\n            text = unicode.translate(vistir.misc.to_text(text), UNICODE_TO_ASCII_TRANSLATION_MAP)\n    return text\n", "path": "pipenv/_compat.py"}]}