def gzip_compress(data):
    """
    Compress a string. Same as gzip.compress in Python3.
    """
    buf = BytesIO()
    with gzip.GzipFile(fileobj=buf, mode='wb') as fd:
        fd.write(data)
    return buf.getvalue()
def gzip_compress ( data ) : buf = BytesIO ( ) with gzip . GzipFile ( fileobj = buf , mode = 'wb' ) as fd : fd . write ( data ) return buf . getvalue ( )
Compress a string. Same as gzip.compress in Python3.