adding gzip support to getUrl
This commit is contained in:
parent
f0927aea2e
commit
1ab7b8f97b
1 changed files with 4 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=2:sts=2:ts=2
|
# vi:si:et:sw=2:sts=2:ts=2
|
||||||
|
import gzip
|
||||||
|
import StringIO
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
@ -18,6 +20,8 @@ def getUrl(url, data=None, headers=DEFAULT_HEADERS):
|
||||||
f = openUrl(url, data, headers)
|
f = openUrl(url, data, headers)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
if f.headers.get('content-encoding', None) == 'gzip':
|
||||||
|
data = gzip.GzipFile(fileobj=StringIO.StringIO(data)).read()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def getUrlUnicode(url):
|
def getUrlUnicode(url):
|
||||||
|
|
Loading…
Reference in a new issue