def gzipped(f):
@functools.wraps(f)<EOL>def view_func(*args, **kwargs):<EOL><INDENT>@after_this_request<EOL>def zipper(response):<EOL><INDENT>accept_encoding = request.headers.get('<STR_LIT>', '<STR_LIT>')<EOL>if '<STR_LIT>' not in accept_encoding.lower():<EOL><INDENT>return response<EOL><DEDENT>response.direct_passthrough = False<EOL>if (response.status_code < <NUM_LIT:200> or response.status_code >= <NUM_LIT> or<EOL>'<STR_LIT>' in response.headers):<EOL><INDENT>return response<EOL><DEDENT>gzip_buffer = IO()<EOL>gzip_file = gzip.GzipFile(mode='<STR_LIT:wb>',<EOL>fileobj=gzip_buffer)<EOL>gzip_file.write(response.data)<EOL>gzip_file.close()<EOL>response.data = gzip_buffer.getvalue()<EOL>response.headers['<STR_LIT>'] = '<STR_LIT>'<EOL>response.headers['<STR_LIT>'] = '<STR_LIT>'<EOL>response.headers['<STR_LIT>'] = len(response.data)<EOL>return response<EOL><DEDENT>return f(*args, **kwargs)<EOL><DEDENT>return view_func<EOL>
Decorator to make a view compressed