diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2016-01-04 20:34:46 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-01-04 20:34:46 -0500 |
commit | de1ed61eb47d35ebc68ca4c6e33528ea505423ae (patch) | |
tree | 5c1874539b12cd7b7b9f79b0e7c0976dc5a9c08d | |
parent | 37751d0e8e216f808576f9481a05238d607f58ab (diff) | |
download | python-setuptools-bitbucket-feature/issue-229.tar.gz |
Use six in pkg_resources.feature/issue-229
-rw-r--r-- | pkg_resources/__init__.py | 31 | ||||
-rw-r--r-- | pkg_resources/tests/test_resources.py | 5 |
2 files changed, 11 insertions, 25 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index f55c8abe..7becc951 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -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 diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 141d63ad..4241765a 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -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 |