提交 9b11ed23 编写于 作者: D Donald Stufft

Merge pull request #1854 from Ivoz/compat-cleaning

Remove unnecessary imports, move some to six
...@@ -6,7 +6,8 @@ import os ...@@ -6,7 +6,8 @@ import os
import textwrap import textwrap
from distutils.util import strtobool from distutils.util import strtobool
from pip.compat import ConfigParser, string_types from pip._vendor.six import string_types
from pip._vendor.six.moves import configparser
from pip.locations import ( from pip.locations import (
default_config_file, default_config_basename, running_under_virtualenv, default_config_file, default_config_basename, running_under_virtualenv,
) )
...@@ -128,7 +129,7 @@ class ConfigOptionParser(CustomOptionParser): ...@@ -128,7 +129,7 @@ class ConfigOptionParser(CustomOptionParser):
configuration files and environmental variables""" configuration files and environmental variables"""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.config = ConfigParser.RawConfigParser() self.config = configparser.RawConfigParser()
self.name = kwargs.pop('name') self.name = kwargs.pop('name')
self.files = self.get_config_files() self.files = self.get_config_files()
if self.files: if self.files:
......
...@@ -4,10 +4,11 @@ import textwrap ...@@ -4,10 +4,11 @@ import textwrap
from pip.basecommand import Command, SUCCESS from pip.basecommand import Command, SUCCESS
from pip.util import get_terminal_size from pip.util import get_terminal_size
from pip.log import logger from pip.log import logger
from pip.compat import xmlrpclib, reduce, cmp from pip.compat import reduce, cmp
from pip.exceptions import CommandError from pip.exceptions import CommandError
from pip.status_codes import NO_MATCHES_FOUND from pip.status_codes import NO_MATCHES_FOUND
from pip._vendor import pkg_resources from pip._vendor import pkg_resources
from pip._vendor.six.moves import xmlrpc_client
from distutils.version import StrictVersion, LooseVersion from distutils.version import StrictVersion, LooseVersion
...@@ -48,7 +49,7 @@ class SearchCommand(Command): ...@@ -48,7 +49,7 @@ class SearchCommand(Command):
return NO_MATCHES_FOUND return NO_MATCHES_FOUND
def search(self, query, index_url): def search(self, query, index_url):
pypi = xmlrpclib.ServerProxy(index_url) pypi = xmlrpc_client.ServerProxy(index_url)
hits = pypi.search({'name': query, 'summary': query}, 'or') hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits return hits
......
...@@ -44,18 +44,13 @@ except NameError: ...@@ -44,18 +44,13 @@ except NameError:
if sys.version_info >= (3,): if sys.version_info >= (3,):
from io import StringIO, BytesIO from io import StringIO
from functools import reduce from functools import reduce
from urllib.error import URLError, HTTPError from urllib.error import URLError, HTTPError
from queue import Queue, Empty
from urllib.request import url2pathname, urlretrieve, pathname2url from urllib.request import url2pathname, urlretrieve, pathname2url
from email import message as emailmessage
import urllib.parse as urllib import urllib.parse as urllib
import urllib.request as urllib2 import urllib.request as urllib2
import configparser as ConfigParser
import xmlrpc.client as xmlrpclib
import urllib.parse as urlparse import urllib.parse as urlparse
import http.client as httplib
def cmp(a, b): def cmp(a, b):
return (a > b) - (a < b) return (a > b) - (a < b)
...@@ -75,21 +70,13 @@ if sys.version_info >= (3,): ...@@ -75,21 +70,13 @@ if sys.version_info >= (3,):
def get_http_message_param(http_message, param, default_value): def get_http_message_param(http_message, param, default_value):
return http_message.get_param(param, default_value) return http_message.get_param(param, default_value)
bytes = bytes
string_types = (str,)
raw_input = input
else: else:
from cStringIO import StringIO from cStringIO import StringIO
from urllib2 import URLError, HTTPError from urllib2 import URLError, HTTPError
from Queue import Queue, Empty
from urllib import url2pathname, urlretrieve, pathname2url from urllib import url2pathname, urlretrieve, pathname2url
from email import Message as emailmessage
import urllib import urllib
import urllib2 import urllib2
import urlparse import urlparse
import ConfigParser
import xmlrpclib
import httplib
def b(s): def b(s):
return s return s
...@@ -104,12 +91,8 @@ else: ...@@ -104,12 +91,8 @@ else:
result = http_message.getparam(param) result = http_message.getparam(param)
return result or default_value return result or default_value
bytes = str
string_types = (basestring,)
reduce = reduce reduce = reduce
cmp = cmp cmp = cmp
raw_input = raw_input
BytesIO = StringIO
def get_path_uid(path): def get_path_uid(path):
......
...@@ -12,7 +12,7 @@ import tempfile ...@@ -12,7 +12,7 @@ import tempfile
import pip import pip
from pip.compat import urllib, urlparse, raw_input from pip.compat import urllib, urlparse
from pip.exceptions import InstallationError, HashMismatch from pip.exceptions import InstallationError, HashMismatch
from pip.util import (splitext, rmtree, format_size, display_path, from pip.util import (splitext, rmtree, format_size, display_path,
backup_dir, ask_path_exists, unpack_file) backup_dir, ask_path_exists, unpack_file)
...@@ -117,7 +117,7 @@ class MultiDomainBasicAuth(AuthBase): ...@@ -117,7 +117,7 @@ class MultiDomainBasicAuth(AuthBase):
parsed = urlparse.urlparse(resp.url) parsed = urlparse.urlparse(resp.url)
# Prompt the user for a new username and password # Prompt the user for a new username and password
username = raw_input("User for %s: " % parsed.netloc) username = six.moves.input("User for %s: " % parsed.netloc)
password = getpass.getpass("Password: ") password = getpass.getpass("Password: ")
# Store the new username and password to use for future requests # Store the new username and password to use for future requests
......
...@@ -10,9 +10,8 @@ from email.parser import FeedParser ...@@ -10,9 +10,8 @@ from email.parser import FeedParser
import pip.wheel import pip.wheel
from pip._vendor import pkg_resources, six from pip._vendor import pkg_resources, six
from pip.compat import ( from pip._vendor.six.moves import configparser
urllib, ConfigParser, string_types, from pip.compat import urllib
)
from pip.download import is_url, url_to_path, path_to_url, is_archive_file from pip.download import is_url, url_to_path, path_to_url, is_archive_file
from pip.exceptions import ( from pip.exceptions import (
InstallationError, UninstallationError, UnsupportedWheel, InstallationError, UninstallationError, UnsupportedWheel,
...@@ -38,7 +37,7 @@ class InstallRequirement(object): ...@@ -38,7 +37,7 @@ class InstallRequirement(object):
url=None, as_egg=False, update=True, prereleases=None, url=None, as_egg=False, update=True, prereleases=None,
editable_options=None, pycompile=True): editable_options=None, pycompile=True):
self.extras = () self.extras = ()
if isinstance(req, string_types): if isinstance(req, six.string_types):
req = pkg_resources.Requirement.parse(req) req = pkg_resources.Requirement.parse(req)
self.extras = req.extras self.extras = req.extras
self.req = req self.req = req
...@@ -168,7 +167,7 @@ class InstallRequirement(object): ...@@ -168,7 +167,7 @@ class InstallRequirement(object):
if self.satisfied_by is not None: if self.satisfied_by is not None:
s += ' in %s' % display_path(self.satisfied_by.location) s += ' in %s' % display_path(self.satisfied_by.location)
if self.comes_from: if self.comes_from:
if isinstance(self.comes_from, string_types): if isinstance(self.comes_from, six.string_types):
comes_from = self.comes_from comes_from = self.comes_from
else: else:
comes_from = self.comes_from.from_path() comes_from = self.comes_from.from_path()
...@@ -181,7 +180,7 @@ class InstallRequirement(object): ...@@ -181,7 +180,7 @@ class InstallRequirement(object):
return None return None
s = str(self.req) s = str(self.req)
if self.comes_from: if self.comes_from:
if isinstance(self.comes_from, string_types): if isinstance(self.comes_from, six.string_types):
comes_from = self.comes_from comes_from = self.comes_from
else: else:
comes_from = self.comes_from.from_path() comes_from = self.comes_from.from_path()
...@@ -619,7 +618,7 @@ exec(compile( ...@@ -619,7 +618,7 @@ exec(compile(
# find console_scripts # find console_scripts
if dist.has_metadata('entry_points.txt'): if dist.has_metadata('entry_points.txt'):
config = ConfigParser.SafeConfigParser() config = configparser.SafeConfigParser()
config.readfp( config.readfp(
FakeFile(dist.get_metadata_lines('entry_points.txt')) FakeFile(dist.get_metadata_lines('entry_points.txt'))
) )
......
...@@ -11,15 +11,16 @@ import zipfile ...@@ -11,15 +11,16 @@ import zipfile
from pip.exceptions import InstallationError, BadCommand from pip.exceptions import InstallationError, BadCommand
from pip.compat import( from pip.compat import(
string_types, raw_input, console_to_str, stdlib_pkgs console_to_str, stdlib_pkgs
) )
from pip.locations import ( from pip.locations import (
site_packages, user_site, running_under_virtualenv, virtualenv_no_global, site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
write_delete_marker_file write_delete_marker_file
) )
from pip.log import logger from pip.log import logger
from pip._vendor import pkg_resources from pip._vendor import pkg_resources, six
from pip._vendor.distlib import version from pip._vendor.distlib import version
from pip._vendor.six.moves import input
__all__ = ['rmtree', 'display_path', 'backup_dir', __all__ = ['rmtree', 'display_path', 'backup_dir',
'find_command', 'ask', 'Inf', 'find_command', 'ask', 'Inf',
...@@ -85,7 +86,7 @@ def find_command(cmd, paths=None, pathext=None): ...@@ -85,7 +86,7 @@ def find_command(cmd, paths=None, pathext=None):
"""Searches the PATH for the given command and returns its path""" """Searches the PATH for the given command and returns its path"""
if paths is None: if paths is None:
paths = os.environ.get('PATH', '').split(os.pathsep) paths = os.environ.get('PATH', '').split(os.pathsep)
if isinstance(paths, string_types): if isinstance(paths, six.string_types):
paths = [paths] paths = [paths]
# check if there are funny path extensions for executables, e.g. Windows # check if there are funny path extensions for executables, e.g. Windows
if pathext is None: if pathext is None:
...@@ -131,7 +132,7 @@ def ask(message, options): ...@@ -131,7 +132,7 @@ def ask(message, options):
'No input was expected ($PIP_NO_INPUT set); question: %s' % 'No input was expected ($PIP_NO_INPUT set); question: %s' %
message message
) )
response = raw_input(message) response = input(message)
response = response.strip().lower() response = response.strip().lower()
if response not in options: if response not in options:
print( print(
......
...@@ -7,7 +7,7 @@ from pip.util import display_path, rmtree ...@@ -7,7 +7,7 @@ from pip.util import display_path, rmtree
from pip.log import logger from pip.log import logger
from pip.vcs import vcs, VersionControl from pip.vcs import vcs, VersionControl
from pip.download import path_to_url from pip.download import path_to_url
from pip.compat import ConfigParser from pip._vendor.six.moves import configparser
class Mercurial(VersionControl): class Mercurial(VersionControl):
...@@ -29,14 +29,14 @@ class Mercurial(VersionControl): ...@@ -29,14 +29,14 @@ class Mercurial(VersionControl):
def switch(self, dest, url, rev_options): def switch(self, dest, url, rev_options):
repo_config = os.path.join(dest, self.dirname, 'hgrc') repo_config = os.path.join(dest, self.dirname, 'hgrc')
config = ConfigParser.SafeConfigParser() config = configparser.SafeConfigParser()
try: try:
config.read(repo_config) config.read(repo_config)
config.set('paths', 'default', url) config.set('paths', 'default', url)
config_file = open(repo_config, 'w') config_file = open(repo_config, 'w')
config.write(config_file) config.write(config_file)
config_file.close() config_file.close()
except (OSError, ConfigParser.NoSectionError) as exc: except (OSError, configparser.NoSectionError) as exc:
logger.warn( logger.warn(
'Could not switch Mercurial repository to %s: %s' 'Could not switch Mercurial repository to %s: %s'
% (url, exc)) % (url, exc))
......
...@@ -15,7 +15,7 @@ import sys ...@@ -15,7 +15,7 @@ import sys
from base64 import urlsafe_b64encode from base64 import urlsafe_b64encode
from email.parser import Parser from email.parser import Parser
from pip.compat import ConfigParser, StringIO, binary from pip.compat import StringIO, binary
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
from pip.locations import distutils_scheme from pip.locations import distutils_scheme
from pip.log import logger from pip.log import logger
...@@ -23,6 +23,7 @@ from pip import pep425tags ...@@ -23,6 +23,7 @@ from pip import pep425tags
from pip.util import call_subprocess, normalize_path, make_path_relative from pip.util import call_subprocess, normalize_path, make_path_relative
from pip._vendor.distlib.scripts import ScriptMaker from pip._vendor.distlib.scripts import ScriptMaker
from pip._vendor import pkg_resources from pip._vendor import pkg_resources
from pip._vendor.six.moves import configparser
wheel_ext = '.whl' wheel_ext = '.whl'
...@@ -114,7 +115,7 @@ def get_entrypoints(filename): ...@@ -114,7 +115,7 @@ def get_entrypoints(filename):
data.write("\n") data.write("\n")
data.seek(0) data.seek(0)
cp = ConfigParser.RawConfigParser() cp = configparser.RawConfigParser()
cp.readfp(data) cp.readfp(data)
console = {} console = {}
......
import hashlib import hashlib
import os import os
from io import BytesIO
from shutil import rmtree, copy from shutil import rmtree, copy
from tempfile import mkdtemp from tempfile import mkdtemp
...@@ -7,7 +8,7 @@ from mock import Mock, patch ...@@ -7,7 +8,7 @@ from mock import Mock, patch
import pytest import pytest
import pip import pip
from pip.compat import BytesIO, b, pathname2url from pip.compat import b, pathname2url
from pip.exceptions import HashMismatch from pip.exceptions import HashMismatch
from pip.download import ( from pip.download import (
PipSession, SafeFileCache, path_to_url, unpack_http_url, url_to_path, PipSession, SafeFileCache, path_to_url, unpack_http_url, url_to_path,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册