<s> """<STR_LIT>""" <EOL> def as_filetype ( data , filetype , * a , ** kw ) : <EOL> handler = { <EOL> "<STR_LIT>" : as_csv , <EOL> } [ filetype ] <EOL> return handler ( data , * a , ** kw ) <EOL> def as_csv ( data , sheet_name = None , filename = "<STR_LIT:data>" ) : <EOL> """<STR_LIT>""" <EOL> from django . http import HttpResponse <EOL> httpresponse = HttpResponse ( mimetype = '<STR_LIT>' ) <EOL> httpresponse [ '<STR_LIT>' ] = '<STR_LIT>' % filename . encode ( "<STR_LIT:ascii>" , "<STR_LIT:replace>" ) <EOL> rowstrs = [ ] <EOL> for row in data : <EOL> rowstr = u"<STR_LIT>" <EOL> for cell in row : <EOL> if isinstance ( cell , ( tuple , list ) ) : <EOL> rowstr += unicode ( cell [ <NUM_LIT:0> ] ) + "<STR_LIT:U+002C>" <EOL> else : <EOL> rowstr += unicode ( cell ) + "<STR_LIT:U+002C>" <EOL> rowstrs . append ( rowstr [ : - <NUM_LIT:1> ] ) <EOL> httpresponse . write ( "<STR_LIT:\n>" . join ( rowstrs ) ) <EOL> return httpresponse </s>
