1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Fix #297 adding deflate and gzip handling

Tested on py24, py27 and py32 and the failing tests on 3.2 go away, the content
we're getting back is still gzipped so this is a valid manual test.  Add
BytesIO to backwardcompat, fallingback to StringIO on py2x.

I'd like to get the CI build green then comeback and improve the testing around
this.  I've not added tests at the moment, but want to come back to that. There is
quite a lot of complexity around downloads split between pip.index and
pip.download.
This commit is contained in:
Paul Nasrat 2011-06-03 15:26:21 +01:00
parent 48152adaad
commit e33be61bc3
2 changed files with 14 additions and 3 deletions

View file

@ -37,7 +37,7 @@ except NameError:
console_encoding = sys.__stdout__.encoding
if sys.version_info >= (3,):
from io import StringIO
from io import StringIO, BytesIO
from functools import reduce
from urllib.error import URLError, HTTPError
from queue import Queue, Empty
@ -91,6 +91,7 @@ else:
reduce = reduce
cmp = cmp
raw_input = raw_input
BytesIO = StringIO
try:
from email.parser import FeedParser

View file

@ -3,6 +3,7 @@
import sys
import os
import re
import gzip
import mimetypes
import threading
import posixpath
@ -10,11 +11,12 @@ import pkg_resources
import random
import socket
import string
import zlib
from pip.log import logger
from pip.util import Inf
from pip.util import normalize_name, splitext
from pip.exceptions import DistributionNotFound
from pip.backwardcompat import (WindowsError,
from pip.backwardcompat import (WindowsError, BytesIO,
Queue, httplib, urlparse,
URLError, HTTPError, u,
product, url2pathname)
@ -442,7 +444,15 @@ class HTMLPage(object):
real_url = geturl(resp)
headers = resp.info()
inst = cls(u(resp.read()), real_url, headers)
contents = resp.read()
encoding = headers.get('Content-Encoding', None)
#XXX need to handle exceptions and add testing for this
if encoding is not None:
if encoding == 'gzip':
contents = gzip.GzipFile(fileobj=BytesIO(contents)).read()
if encoding == 'deflate':
contents = zlib.decompress(contents)
inst = cls(u(contents), real_url, headers)
except (HTTPError, URLError, socket.timeout, socket.error, OSError, WindowsError):
e = sys.exc_info()[1]
desc = str(e)