@decorator
def deflate(f, *args, **kwargs):
 data = f(*args, **kwargs)
 if isinstance(data, Response):
  content = data.data
 else:
  content = data
 deflater = zlib.compressobj()
 deflated_data = deflater.compress(content)
 deflated_data += deflater.flush()
 if isinstance(data, Response):
  data.data = deflated_data
  data.headers['Content-Encoding'] = 'deflate'
  data.headers['Content-Length'] = str(len(data.data))
  return data
 return deflated_data

@ decorator def deflate ( f , * args , ** kwargs ) : data = f ( * args , ** kwargs ) if isinstance ( data , Response ) : content = data . data else : content = data deflater = zlib . compressobj ( ) deflated_data = deflater . compress ( content ) deflated_data += deflater . flush ( ) if isinstance ( data , Response ) : data . data = deflated_data data . headers [ 'Content-Encoding' ] = 'deflate' data . headers [ 'Content-Length' ] = str ( len ( data . data ) ) return data return deflated_data
compress/base64 encode a string .