@contextmanager
def tsv_writer(response, fields, name=None, bom=False):
 if hasattr(response, u'headers'):
  response.headers['Content-Type'] = 'text/tab-separated-values; charset=utf-8'
  if name:
   response.headers['Content-disposition'] = 'attachment; filename="{name}.tsv"'.format(name=encode_rfc2231(name))
 wr = unicodecsv.writer(response, encoding=u'utf-8', dialect=unicodecsv.excel_tab)
 if bom:
  response.write(UTF8_BOM)
 wr.writerow((f['id'] for f in fields))
 (yield wr)

@ contextmanager def tsv_writer ( response , fields , name = None , bom = False ) : if hasattr ( response , u'headers' ) : response . headers [ 'Content-Type' ] = 'text/tab-separated-values; charset=utf-8' if name : response . headers [ 'Content-disposition' ] = 'attachment; filename="{name}.tsv"' . format ( name = encode_rfc2231 ( name ) ) wr = unicodecsv . writer ( response , encoding = u'utf-8' , dialect = unicodecsv . excel_tab ) if bom : response . write ( UTF8_BOM ) wr . writerow ( ( f [ 'id' ] for f in fields ) ) ( yield wr )
context manager for writing utf-8 tsv data to response .