From d722bd3324c1d22541a8e8f924fa490fd7c1046f Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Mon, 22 Nov 2010 18:12:18 +0100 Subject: 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 --- setuptools/package_index.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') 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): -- cgit v1.2.3