@contextmanager
def xml_writer(response, fields, name=None, bom=False):
 if hasattr(response, u'headers'):
  response.headers['Content-Type'] = 'text/xml; charset=utf-8'
  if name:
   response.headers['Content-disposition'] = 'attachment; filename="{name}.xml"'.format(name=encode_rfc2231(name))
 if bom:
  response.write(UTF8_BOM)
 response.write('<data>\n')
 (yield XMLWriter(response, [f['id'] for f in fields]))
 response.write('</data>\n')

@ contextmanager def xml_writer ( response , fields , name = None , bom = False ) : if hasattr ( response , u'headers' ) : response . headers [ 'Content-Type' ] = 'text/xml; charset=utf-8' if name : response . headers [ 'Content-disposition' ] = 'attachment; filename="{name}.xml"' . format ( name = encode_rfc2231 ( name ) ) if bom : response . write ( UTF8_BOM ) response . write ( '<data>\n' ) ( yield XMLWriter ( response , [ f [ 'id' ] for f in fields ] ) ) response . write ( '</data>\n' )
context manager for writing utf-8 xml data to response .