@decorator
def gzip(f, *args, **kwargs):
 data = f(*args, **kwargs)
 if isinstance(data, Response):
  content = data.data
 else:
  content = data
 gzip_buffer = BytesIO()
 gzip_file = gzip2.GzipFile(mode='wb', compresslevel=4, fileobj=gzip_buffer)
 gzip_file.write(content)
 gzip_file.close()
 gzip_data = gzip_buffer.getvalue()
 if isinstance(data, Response):
  data.data = gzip_data
  data.headers['Content-Encoding'] = 'gzip'
  data.headers['Content-Length'] = str(len(data.data))
  return data
 return gzip_data

@ decorator def gzip ( f , * args , ** kwargs ) : data = f ( * args , ** kwargs ) if isinstance ( data , Response ) : content = data . data else : content = data gzip_buffer = BytesIO ( ) gzip_file = gzip2 . GzipFile ( mode = 'wb' , compresslevel = 4 , fileobj = gzip_buffer ) gzip_file . write ( content ) gzip_file . close ( ) gzip_data = gzip_buffer . getvalue ( ) if isinstance ( data , Response ) : data . data = gzip_data data . headers [ 'Content-Encoding' ] = 'gzip' data . headers [ 'Content-Length' ] = str ( len ( data . data ) ) return data return gzip_data
uses the gzip command to create gzip files template : none can be set to jinja or another supported template engine to render the command arguments before execution: .