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 ...@@ -37,7 +37,6 @@ import plistlib
import email.parser import email.parser
import tempfile import tempfile
import textwrap import textwrap
import itertools
from pkgutil import get_importer from pkgutil import get_importer
try: try:
...@@ -46,23 +45,8 @@ except ImportError: ...@@ -46,23 +45,8 @@ except ImportError:
# Python 3.2 compatibility # Python 3.2 compatibility
import imp as _imp import imp as _imp
PY3 = sys.version_info > (3,) from pkg_resources.extern import six
PY2 = not PY3 from pkg_resources.extern.six.moves import urllib
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()
# capture these to bypass sandboxing # capture these to bypass sandboxing
from os import utime from os import utime
...@@ -92,6 +76,9 @@ __import__('pkg_resources.extern.packaging.version') ...@@ -92,6 +76,9 @@ __import__('pkg_resources.extern.packaging.version')
__import__('pkg_resources.extern.packaging.specifiers') __import__('pkg_resources.extern.packaging.specifiers')
filter = six.moves.filter
map = six.moves.map
if (3, 0) < sys.version_info < (3, 3): if (3, 0) < sys.version_info < (3, 3):
msg = ( msg = (
"Support for Python 3.0-3.2 has been dropped. Future versions " "Support for Python 3.0-3.2 has been dropped. Future versions "
...@@ -549,7 +536,7 @@ run_main = run_script ...@@ -549,7 +536,7 @@ run_main = run_script
def get_distribution(dist): def get_distribution(dist):
"""Return a current distribution object for a Requirement or string""" """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) dist = Requirement.parse(dist)
if isinstance(dist, Requirement): if isinstance(dist, Requirement):
dist = get_provider(dist) dist = get_provider(dist)
...@@ -2297,7 +2284,7 @@ def _set_parent_ns(packageName): ...@@ -2297,7 +2284,7 @@ def _set_parent_ns(packageName):
def yield_lines(strs): def yield_lines(strs):
"""Yield non-empty/non-comment lines of a string or sequence""" """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(): for s in strs.splitlines():
s = s.strip() s = s.strip()
# skip blank lines/comments # skip blank lines/comments
...@@ -2464,9 +2451,9 @@ class EntryPoint(object): ...@@ -2464,9 +2451,9 @@ class EntryPoint(object):
def _remove_md5_fragment(location): def _remove_md5_fragment(location):
if not location: if not location:
return '' return ''
parsed = urlparse(location) parsed = urllib.parse.urlparse(location)
if parsed[-1].startswith('md5='): if parsed[-1].startswith('md5='):
return urlunparse(parsed[:-1] + ('',)) return urllib.parse.urlunparse(parsed[:-1] + ('',))
return location return location
......
...@@ -244,9 +244,8 @@ class TestWorkingSet: ...@@ -244,9 +244,8 @@ class TestWorkingSet:
with pytest.raises(VersionConflict) as vc: with pytest.raises(VersionConflict) as vc:
ws.resolve(parse_requirements("Foo\nBar\n")) ws.resolve(parse_requirements("Foo\nBar\n"))
msg = "Baz 1.0 is installed but Baz==2.0 is required by {'Bar'}" msg = "Baz 1.0 is installed but Baz==2.0 is required by "
if pkg_resources.PY2: msg += repr(set(['Bar']))
msg = msg.replace("{'Bar'}", "set(['Bar'])")
assert vc.value.report() == msg 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