Clean up some no longer needed compatability code

This commit is contained in:
Donald Stufft 2014-06-26 22:44:42 -04:00
parent eb650bdef7
commit 53faeece34
5 changed files with 9 additions and 36 deletions

View File

@ -30,19 +30,6 @@ except NameError:
console_encoding = sys.__stdout__.encoding
try:
unicode
def binary(s):
if isinstance(s, unicode):
return s.encode('ascii')
return s
except NameError:
def binary(s):
if isinstance(s, str):
return s.encode('ascii')
if sys.version_info >= (3,):
from io import StringIO
from urllib.error import URLError, HTTPError
@ -54,12 +41,6 @@ if sys.version_info >= (3,):
def cmp(a, b):
return (a > b) - (a < b)
def b(s):
return s.encode('utf-8')
def u(s):
return s.decode('utf-8')
def console_to_str(s):
try:
return s.decode(console_encoding)
@ -77,12 +58,6 @@ else:
import urllib2
import urlparse
def b(s):
return s
def u(s):
return s
def console_to_str(s):
return s

View File

@ -3,7 +3,7 @@ import os
import sys
import tempfile
from pip.compat import uses_pycache, b
from pip.compat import uses_pycache
from pip.exceptions import UninstallationError
from pip.log import logger
from pip.util import (rmtree, ask, is_local, dist_is_local, renames,
@ -176,14 +176,14 @@ class UninstallPthEntries(object):
lines = fh.readlines()
self._saved_lines = lines
fh.close()
if any(b('\r\n') in line for line in lines):
if any(b'\r\n' in line for line in lines):
endline = '\r\n'
else:
endline = '\n'
for entry in self.entries:
try:
logger.info('Removing entry: %s' % entry)
lines.remove(b(entry + endline))
lines.remove((entry + endline).encode("utf-8"))
except ValueError:
pass
fh = open(self.file, 'wb')

View File

@ -10,9 +10,7 @@ import tarfile
import zipfile
from pip.exceptions import InstallationError, BadCommand
from pip.compat import(
console_to_str, stdlib_pkgs
)
from pip.compat import console_to_str, stdlib_pkgs
from pip.locations import (
site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
write_delete_marker_file

View File

@ -15,7 +15,7 @@ import sys
from base64 import urlsafe_b64encode
from email.parser import Parser
from pip.compat import StringIO, binary
from pip.compat import StringIO
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
from pip.locations import distutils_scheme
from pip.log import logger
@ -65,10 +65,10 @@ def fix_script(path):
script = open(path, 'rb')
try:
firstline = script.readline()
if not firstline.startswith(binary('#!python')):
if not firstline.startswith(b'#!python'):
return False
exename = sys.executable.encode(sys.getfilesystemencoding())
firstline = binary('#!') + exename + binary(os.linesep)
firstline = b'#!' + exename + os.linesep.encode("ascii")
rest = script.read()
finally:
script.close()

View File

@ -8,7 +8,7 @@ from mock import Mock, patch
import pytest
import pip
from pip.compat import b, pathname2url
from pip.compat import pathname2url
from pip.exceptions import HashMismatch
from pip.download import (
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):
If already-downloaded file has bad checksum, re-download.
"""
base_url = 'http://www.example.com/somepackage.tgz'
contents = b('downloaded')
contents = b'downloaded'
download_hash = hashlib.new('sha1', contents)
link = Link(base_url + '#sha1=' + download_hash.hexdigest())