diff options
author | Lennart Regebro <regebro@gmail.com> | 2010-11-22 18:12:18 +0100 |
---|---|---|
committer | Lennart Regebro <regebro@gmail.com> | 2010-11-22 18:12:18 +0100 |
commit | d722bd3324c1d22541a8e8f924fa490fd7c1046f (patch) | |
tree | 34d5512287441fc853bafd7f7e367e709d85a3bb /setuptools/package_index.py | |
parent | a6f96e7709806a0211de70a0eb9089de77d000e2 (diff) | |
download | external_python_setuptools-d722bd3324c1d22541a8e8f924fa490fd7c1046f.tar.gz external_python_setuptools-d722bd3324c1d22541a8e8f924fa490fd7c1046f.tar.bz2 external_python_setuptools-d722bd3324c1d22541a8e8f924fa490fd7c1046f.zip |
We need to make sure that the result is always a str, even if the result is an error response. Otherwise
you get an error when trying to pattern match in line 206.
--HG--
branch : distribute
extra : rebase_source : dc5fe8b1365544fc763414b67227cc78dc1f8524
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 4ff96303..459cae2c 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -199,8 +199,12 @@ class PackageIndex(Environment): base = f.url # handle redirects page = f.read() - if sys.version_info >= (3,) and not isinstance(f, urllib2.HTTPError): - charset = f.headers.get_param('charset') or 'latin-1' + if not isinstance(page, str): # We are in Python 3 and got bytes. We want str. + if isinstance(f, urllib2.HTTPError): + # Errors have no charset, assume latin1: + charset = 'latin-1' + else: + charset = f.headers.get_param('charset') or 'latin-1' page = page.decode(charset, "ignore") f.close() for match in HREF.finditer(page): |