Skip to content

Commit 889f13d

Browse files
committed
Merge pull request #1901 from dstufft/cleanup-compat-wtf
Use b"" instead of b()
2 parents eb650bd + 53faeec commit 889f13d

File tree

5 files changed

+9
-36
lines changed

5 files changed

+9
-36
lines changed

pip/compat.py

-25
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@ class NeverUsedException(Exception):
3030
console_encoding = sys.__stdout__.encoding
3131

3232

33-
try:
34-
unicode
35-
36-
def binary(s):
37-
if isinstance(s, unicode):
38-
return s.encode('ascii')
39-
return s
40-
except NameError:
41-
def binary(s):
42-
if isinstance(s, str):
43-
return s.encode('ascii')
44-
45-
4633
if sys.version_info >= (3,):
4734
from io import StringIO
4835
from urllib.error import URLError, HTTPError
@@ -54,12 +41,6 @@ def binary(s):
5441
def cmp(a, b):
5542
return (a > b) - (a < b)
5643

57-
def b(s):
58-
return s.encode('utf-8')
59-
60-
def u(s):
61-
return s.decode('utf-8')
62-
6344
def console_to_str(s):
6445
try:
6546
return s.decode(console_encoding)
@@ -77,12 +58,6 @@ def get_http_message_param(http_message, param, default_value):
7758
import urllib2
7859
import urlparse
7960

80-
def b(s):
81-
return s
82-
83-
def u(s):
84-
return s
85-
8661
def console_to_str(s):
8762
return s
8863

pip/req/req_uninstall.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import tempfile
55

6-
from pip.compat import uses_pycache, b
6+
from pip.compat import uses_pycache
77
from pip.exceptions import UninstallationError
88
from pip.log import logger
99
from pip.util import (rmtree, ask, is_local, dist_is_local, renames,
@@ -176,14 +176,14 @@ def remove(self):
176176
lines = fh.readlines()
177177
self._saved_lines = lines
178178
fh.close()
179-
if any(b('\r\n') in line for line in lines):
179+
if any(b'\r\n' in line for line in lines):
180180
endline = '\r\n'
181181
else:
182182
endline = '\n'
183183
for entry in self.entries:
184184
try:
185185
logger.info('Removing entry: %s' % entry)
186-
lines.remove(b(entry + endline))
186+
lines.remove((entry + endline).encode("utf-8"))
187187
except ValueError:
188188
pass
189189
fh = open(self.file, 'wb')

pip/util.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import zipfile
1111

1212
from pip.exceptions import InstallationError, BadCommand
13-
from pip.compat import(
14-
console_to_str, stdlib_pkgs
15-
)
13+
from pip.compat import console_to_str, stdlib_pkgs
1614
from pip.locations import (
1715
site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
1816
write_delete_marker_file

pip/wheel.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from base64 import urlsafe_b64encode
1616
from email.parser import Parser
1717

18-
from pip.compat import StringIO, binary
18+
from pip.compat import StringIO
1919
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
2020
from pip.locations import distutils_scheme
2121
from pip.log import logger
@@ -65,10 +65,10 @@ def fix_script(path):
6565
script = open(path, 'rb')
6666
try:
6767
firstline = script.readline()
68-
if not firstline.startswith(binary('#!python')):
68+
if not firstline.startswith(b'#!python'):
6969
return False
7070
exename = sys.executable.encode(sys.getfilesystemencoding())
71-
firstline = binary('#!') + exename + binary(os.linesep)
71+
firstline = b'#!' + exename + os.linesep.encode("ascii")
7272
rest = script.read()
7373
finally:
7474
script.close()

tests/unit/test_download.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
import pip
11-
from pip.compat import b, pathname2url
11+
from pip.compat import pathname2url
1212
from pip.exceptions import HashMismatch
1313
from pip.download import (
1414
PipSession, SafeFileCache, path_to_url, unpack_http_url, url_to_path,
@@ -84,7 +84,7 @@ def test_unpack_http_url_bad_downloaded_checksum(mock_unpack_file):
8484
If already-downloaded file has bad checksum, re-download.
8585
"""
8686
base_url = 'http://www.example.com/somepackage.tgz'
87-
contents = b('downloaded')
87+
contents = b'downloaded'
8888
download_hash = hashlib.new('sha1', contents)
8989
link = Link(base_url + '#sha1=' + download_hash.hexdigest())
9090

0 commit comments

Comments
 (0)