9
9
import shutil
10
10
import sys
11
11
12
- from pip ._vendor .six import PY3 , text_type
12
+ from pip ._vendor .six import PY2 , text_type
13
13
from pip ._vendor .urllib3 .util import IS_PYOPENSSL
14
14
15
15
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
47
47
48
48
HAS_TLS = (ssl is not None ) or IS_PYOPENSSL
49
49
50
- if PY3 :
51
- uses_pycache = True
52
- from importlib .util import cache_from_source
53
- else :
50
+ if PY2 :
54
51
import imp
55
52
56
53
try :
60
57
cache_from_source = None
61
58
62
59
uses_pycache = cache_from_source is not None
60
+ else :
61
+ uses_pycache = True
62
+ from importlib .util import cache_from_source
63
63
64
64
65
- if PY3 :
66
- backslashreplace_decode = "backslashreplace"
67
- else :
65
+ if PY2 :
68
66
# In version 3.4 and older, backslashreplace exists
69
67
# but does not support use for decoding.
70
68
# We implement our own replace handler for this
@@ -80,7 +78,8 @@ def backslashreplace_decode_fn(err):
80
78
backslashreplace_decode_fn ,
81
79
)
82
80
backslashreplace_decode = "backslashreplace_decode"
83
-
81
+ else :
82
+ backslashreplace_decode = "backslashreplace"
84
83
85
84
def str_to_display (data , desc = None ):
86
85
# type: (Union[bytes, Text], Optional[str]) -> Text
@@ -155,19 +154,19 @@ def console_to_str(data):
155
154
return str_to_display (data , desc = 'Subprocess output' )
156
155
157
156
158
- if PY3 :
157
+ if PY2 :
159
158
def native_str (s , replace = False ):
160
159
# type: (str, bool) -> str
161
- if isinstance (s , bytes ):
162
- return s .decode ('utf-8' , 'replace' if replace else 'strict' )
160
+ # Replace is ignored -- unicode to UTF-8 can't fail
161
+ if isinstance (s , text_type ):
162
+ return s .encode ('utf-8' )
163
163
return s
164
164
165
165
else :
166
166
def native_str (s , replace = False ):
167
167
# type: (str, bool) -> str
168
- # Replace is ignored -- unicode to UTF-8 can't fail
169
- if isinstance (s , text_type ):
170
- return s .encode ('utf-8' )
168
+ if isinstance (s , bytes ):
169
+ return s .decode ('utf-8' , 'replace' if replace else 'strict' )
171
170
return s
172
171
173
172
@@ -201,16 +200,17 @@ def get_path_uid(path):
201
200
return file_uid
202
201
203
202
204
- if PY3 :
205
- from importlib . machinery import EXTENSION_SUFFIXES
203
+ if PY2 :
204
+ from imp import get_suffixes
206
205
207
206
def get_extension_suffixes ():
208
- return EXTENSION_SUFFIXES
207
+ return [suffix [0 ] for suffix in get_suffixes ()]
208
+
209
209
else :
210
- from imp import get_suffixes
210
+ from importlib . machinery import EXTENSION_SUFFIXES
211
211
212
212
def get_extension_suffixes ():
213
- return [ suffix [ 0 ] for suffix in get_suffixes ()]
213
+ return EXTENSION_SUFFIXES
214
214
215
215
216
216
def expanduser (path ):
0 commit comments