diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2014-09-18 07:21:24 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-09-18 07:21:24 -0400 |
commit | 8f56e928f03f69a5e787f830c04714467307601e (patch) | |
tree | 051fe9ef18f2e7b756fc3e99d36d5cfc79acafe4 | |
parent | 26e4f9534a35fc13ec2c5e111e639d4af03e5644 (diff) | |
download | external_python_setuptools-8f56e928f03f69a5e787f830c04714467307601e.tar.gz external_python_setuptools-8f56e928f03f69a5e787f830c04714467307601e.tar.bz2 external_python_setuptools-8f56e928f03f69a5e787f830c04714467307601e.zip |
Use PY3/PY2 indicators to reliably select behavior. Fixes #237
--HG--
extra : amend_source : 33f3d298acd39933ccf60810902feb2a5d51c793
-rw-r--r-- | CHANGES.txt | 8 | ||||
-rw-r--r-- | pkg_resources.py | 17 |
2 files changed, 17 insertions, 8 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 83b05bbe..185052fb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,14 @@ CHANGES ======= --- +5.8 +--- + +* Issue #237: ``pkg_resources`` now uses explicit detection of Python 2 vs. + Python 3, supporting environments where builtins have been patched to make + Python 3 look more like Python 2. + +--- 5.7 --- diff --git a/pkg_resources.py b/pkg_resources.py index a0566688..5dcfd66e 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -38,16 +38,13 @@ from pkgutil import get_importer PY3 = sys.version_info > (3,) PY2 = not PY3 -try: - from urlparse import urlparse, urlunparse -except ImportError: +if PY3: from urllib.parse import urlparse, urlunparse -try: - basestring - next = lambda o: o.next() - from cStringIO import StringIO as BytesIO -except NameError: +if PY2: + from urlparse import urlparse, urlunparse + +if PY3: basestring = str from io import BytesIO def execfile(fn, globs=None, locs=None): @@ -57,6 +54,10 @@ except NameError: locs = globs exec(compile(open(fn).read(), fn, 'exec'), globs, locs) +if PY2: + next = lambda o: o.next() + from cStringIO import StringIO as BytesIO + # capture these to bypass sandboxing from os import utime try: |