def decorate(self, app):
from functools import wraps<EOL>@wraps(app)<EOL>def decorated(environ, start_response):<EOL><INDENT>app_response = {}<EOL>app_response['<STR_LIT:status>'] = "<STR_LIT>"<EOL>app_response['<STR_LIT>'] = []<EOL>app_response['<STR_LIT>'] = BytesIO()<EOL>def custom_start_response(status, headers, *args, **kwargs):<EOL><INDENT>app_response['<STR_LIT:status>'] = status<EOL>app_response['<STR_LIT>'] = headers<EOL>app_response['<STR_LIT:args>'] = args<EOL>app_response['<STR_LIT>'] = kwargs<EOL>return app_response['<STR_LIT>'].write<EOL><DEDENT>returned = app(environ, custom_start_response)<EOL>def set_http_code(status):<EOL><INDENT>app_response['<STR_LIT:status>'] = str(status)<EOL><DEDENT>def set_header(header, value):<EOL><INDENT>app_response['<STR_LIT>'] = [(h,v) for (h,v) in app_response['<STR_LIT>'] if h.lower() != header.lower()]<EOL>app_response['<STR_LIT>'].append((header, value))<EOL><DEDENT>def set_content_type(content_type):<EOL><INDENT>set_header('<STR_LIT:Content-Type>', content_type)<EOL><DEDENT>accept = environ.get('<STR_LIT>', '<STR_LIT>')<EOL>new_return = self.output(returned, accept, set_http_code, set_content_type)<EOL>vary_headers = (v for (h,v) in app_response['<STR_LIT>'] if h.lower() == '<STR_LIT>')<EOL>vary_elements = list(itertools.chain(*[v.split('<STR_LIT:U+002C>') for v in vary_headers]))<EOL>vary_elements = list(set([v.strip() for v in vary_elements]))<EOL>if '<STR_LIT:*>' not in vary_elements and '<STR_LIT>' not in (v.lower() for v in vary_elements):<EOL><INDENT>vary_elements.append('<STR_LIT>')<EOL>set_header('<STR_LIT>', '<STR_LIT:U+002CU+0020>'.join(vary_elements))<EOL><DEDENT>parent_writer = start_response(app_response['<STR_LIT:status>'],<EOL>app_response['<STR_LIT>'],<EOL>*app_response.get('<STR_LIT:args>', []),<EOL>**app_response.get('<STR_LIT>', {}))<EOL>written = app_response['<STR_LIT>'].getvalue()<EOL>if len(written) > <NUM_LIT:0>:<EOL><INDENT>parent_writer(written)<EOL><DEDENT>return new_return<EOL><DEDENT>return decorated<EOL>
Wraps a WSGI application to return formatted RDF graphs
            Uses content negotiation to serialize the graph to the client-preferred format
            Passes other content through unmodified