

def _immediateResponse(self, data, request):
    encoding = request.getHeader('accept-encoding')
    if (encoding and ('gzip' in encoding)):
        zbuf = cStringIO.StringIO()
        zfile = gzip.GzipFile(None, 'wb', 9, zbuf)
        if isinstance(data, unicode):
            zfile.write(unicode(data).encode('utf-8'))
        elif isinstance(data, str):
            zfile.write(unicode(data, 'utf-8').encode('utf-8'))
        else:
            zfile.write(unicode(data).encode('utf-8'))
        zfile.close()
        request.setHeader('Content-encoding', 'gzip')
        request.write(zbuf.getvalue())
    else:
        request.write(data)
    request.finish()

dataset/ETHPy150Open wehriam/awspider/awspider/resources/base.py BaseResource._immediateResponse/original