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