From 1b3a758f280bd9330e0b08bfd055852aac314cc3 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 8 Jan 2013 21:30:43 +0200 Subject: [PATCH] Search plugins: Properly uncompress gzipped responses in retrieve_url() --- src/searchengine/nova/helpers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/searchengine/nova/helpers.py b/src/searchengine/nova/helpers.py index 97a30974c..7aa53b1d6 100644 --- a/src/searchengine/nova/helpers.py +++ b/src/searchengine/nova/helpers.py @@ -22,7 +22,7 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -#VERSION: 1.31 +#VERSION: 1.32 # Author: # Christophe DUMEZ (chris@qbittorrent.org) @@ -64,6 +64,13 @@ def retrieve_url(url): req = urllib2.Request(url) response = urllib2.urlopen(req) dat = response.read() + # Check if it is gzipped + if dat[:2] == '\037\213': + # Data is gzip encoded, decode it + compressedstream = StringIO.StringIO(dat) + gzipper = gzip.GzipFile(fileobj=compressedstream) + extracted_data = gzipper.read() + dat = extracted_data info = response.info() charset = 'utf-8' try: