From 1ab7b8f97b12810c7d4679f3cd355e367b6d12d0 Mon Sep 17 00:00:00 2001 From: Rolux Date: Mon, 28 Apr 2008 11:55:30 +0200 Subject: [PATCH] adding gzip support to getUrl --- oxutils/net.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oxutils/net.py b/oxutils/net.py index 1b3f609..402b0f1 100644 --- a/oxutils/net.py +++ b/oxutils/net.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=2:sts=2:ts=2 +import gzip +import StringIO import urllib import urllib2 @@ -18,6 +20,8 @@ def getUrl(url, data=None, headers=DEFAULT_HEADERS): f = openUrl(url, data, headers) data = f.read() f.close() + if f.headers.get('content-encoding', None) == 'gzip': + data = gzip.GzipFile(fileobj=StringIO.StringIO(data)).read() return data def getUrlUnicode(url):