adding gzip support to getUrl

This commit is contained in:
Rolux 2008-04-28 11:55:30 +02:00
parent f0927aea2e
commit 1ab7b8f97b

View file

@ -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):