<s> import csv <EOL> import cffi <EOL> def _make_ffi_from_dialect ( dialect_name ) : <EOL> dialect = csv . get_dialect ( dialect_name ) <EOL> ffi = cffi . FFI ( ) <EOL> ffi . cdef ( """<STR_LIT>""" ) <EOL> d = { '<STR_LIT>' : ord ( dialect . quotechar ) , <EOL> '<STR_LIT>' : int ( dialect . quoting ) , <EOL> '<STR_LIT>' : int ( dialect . skipinitialspace ) , <EOL> '<STR_LIT>' : ord ( dialect . delimiter ) , <EOL> '<STR_LIT>' : int ( dialect . doublequote ) , <EOL> '<STR_LIT:strict>' : int ( dialect . strict ) , <EOL> } <EOL> if dialect . escapechar is not None : <EOL> d [ '<STR_LIT>' ] = '<STR_LIT>' % ord ( dialect . escapechar ) <EOL> else : <EOL> d [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ffi . set_source ( '<STR_LIT>' + dialect_name , r'''<STR_LIT>''' % d ) <EOL> ffi . compile ( ) <EOL> def fastcsv_reader ( f , dialect_name ) : <EOL> try : <EOL> module = __import__ ( '<STR_LIT>' + dialect_name ) <EOL> except ImportError : <EOL> _make_ffi_from_dialect ( dialect_name ) <EOL> module = __import__ ( '<STR_LIT>' + dialect_name ) <EOL> ffi , lib = module . ffi , module . lib <EOL> linelen = - <NUM_LIT:1> <EOL> for line in f : <EOL> if linelen <= len ( line ) : <EOL> linelen = <NUM_LIT:2> * len ( line ) <EOL> rawline = ffi . new ( "<STR_LIT>" , linelen ) <EOL> ffi . buffer ( rawline , len ( line ) ) [ : ] = line <EOL> n = lib . parse_line ( rawline , len ( line ) ) <EOL> assert n >= <NUM_LIT:0> <EOL> yield ffi . buffer ( rawline , n ) [ : ] . split ( '<STR_LIT:\x00>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> csv . register_dialect ( '<STR_LIT>' , delimiter = '<STR_LIT::>' , quoting = csv . QUOTE_NONE ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as f : <EOL> reader = fastcsv_reader ( f , '<STR_LIT>' ) <EOL> for row in reader : <EOL> print row </s>
