Commit d722bd33 authored by Lennart Regebro's avatar Lennart Regebro

We need to make sure that the result is always a str, even if the result is an...

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
parent a6f96e77
......@@ -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):
......
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