Commit b639cf0f authored by Jason R. Coombs's avatar Jason R. Coombs

Use six in pkg_resources.

--HG--
branch : feature/issue-229
parent a2484bd0
......@@ -37,7 +37,6 @@ import plistlib
import email.parser
import tempfile
import textwrap
import itertools
from pkgutil import get_importer
try:
......@@ -46,23 +45,8 @@ except ImportError:
# Python 3.2 compatibility
import imp as _imp
PY3 = sys.version_info > (3,)
PY2 = not PY3
if PY3:
from urllib.parse import urlparse, urlunparse
if PY2:
from urlparse import urlparse, urlunparse
filter = itertools.ifilter
map = itertools.imap
if PY3:
string_types = str,
else:
string_types = str, eval('unicode')
iteritems = (lambda i: i.items()) if PY3 else lambda i: i.iteritems()
from pkg_resources.extern import six
from pkg_resources.extern.six.moves import urllib
# capture these to bypass sandboxing
from os import utime
......@@ -92,6 +76,9 @@ __import__('pkg_resources.extern.packaging.version')
__import__('pkg_resources.extern.packaging.specifiers')
filter = six.moves.filter
map = six.moves.map
if (3, 0) < sys.version_info < (3, 3):
msg = (
"Support for Python 3.0-3.2 has been dropped. Future versions "
......@@ -549,7 +536,7 @@ run_main = run_script
def get_distribution(dist):
"""Return a current distribution object for a Requirement or string"""
if isinstance(dist, string_types):
if isinstance(dist, six.string_types):
dist = Requirement.parse(dist)
if isinstance(dist, Requirement):
dist = get_provider(dist)
......@@ -2297,7 +2284,7 @@ def _set_parent_ns(packageName):
def yield_lines(strs):
"""Yield non-empty/non-comment lines of a string or sequence"""
if isinstance(strs, string_types):
if isinstance(strs, six.string_types):
for s in strs.splitlines():
s = s.strip()
# skip blank lines/comments
......@@ -2464,9 +2451,9 @@ class EntryPoint(object):
def _remove_md5_fragment(location):
if not location:
return ''
parsed = urlparse(location)
parsed = urllib.parse.urlparse(location)
if parsed[-1].startswith('md5='):
return urlunparse(parsed[:-1] + ('',))
return urllib.parse.urlunparse(parsed[:-1] + ('',))
return location
......
......@@ -244,9 +244,8 @@ class TestWorkingSet:
with pytest.raises(VersionConflict) as vc:
ws.resolve(parse_requirements("Foo\nBar\n"))
msg = "Baz 1.0 is installed but Baz==2.0 is required by {'Bar'}"
if pkg_resources.PY2:
msg = msg.replace("{'Bar'}", "set(['Bar'])")
msg = "Baz 1.0 is installed but Baz==2.0 is required by "
msg += repr(set(['Bar']))
assert vc.value.report() == msg
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment