Update for an Issue #182

This commit is contained in:
Miroslav Stampar 2012-09-11 12:08:34 +02:00
parent 12d33c7a38
commit 10b671d625

View File

@ -180,18 +180,19 @@ def decodePage(page, contentEncoding, contentType):
return getUnicode(page)
if isinstance(contentEncoding, basestring) and contentEncoding.lower() in ("gzip", "x-gzip", "deflate"):
if contentEncoding == "deflate":
# http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
data = StringIO.StringIO(zlib.decompress(page, -15))
else:
data = gzip.GzipFile("", "rb", 9, StringIO.StringIO(page))
try:
if contentEncoding == "deflate":
# http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
data = StringIO.StringIO(zlib.decompress(page, -15))
else:
data = gzip.GzipFile("", "rb", 9, StringIO.StringIO(page))
page = data.read()
except Exception, msg:
errMsg = "detected invalid data for declared content "
errMsg += "encoding '%s' ('%s')" % (contentEncoding, msg)
singleTimeLogMessage(errMsg, logging.ERROR)
return page
if not conf.charset:
httpCharset, metaCharset = None, None