#NEWLINE# def __init__( self , resource , read_header = True , dialect = None , delimiter = None , encoding = None , skip_rows = None , empty_as_null = True , fields = None , type_converters = None , **options ) : #NEWLINE# #INDENT# 'Creates a CSV data source stream.\n\n        * `resource`: file name, URL or a file handle with CVS data\n        * `read_header`: flag determining whether first line contains header\n          or not. ``True`` by default.\n        * `encoding`: source character encoding, by default no conversion is\n          performed.\n        * `fields`: optional `FieldList` object. If not specified then\n          `read_header` should be used.\n        * `skip_rows`: number of rows to be skipped. Default: ``None``\n        * `empty_as_null`: treat empty strings as ``Null`` values\n        * `type_converters`: dictionary of converters (functions). It has\n          to cover all known types.\n\n        Note: avoid auto-detection when you are reading from remote URL\n        stream.\n\n        Rules for fields:\n\n        * if `fields` are specified, then they are used, header is ignored\n          depending on `read_header` flag\n        * if `detect_types` is not requested, then each field is of type\n          `string` (this is the default)\n        ' #NEWLINE# self . file = None #NEWLINE# if ( not any ( ( fields , read_header ) ) ) : #NEWLINE# #INDENT# raise ArgumentError ( 'At least one of fields or read_header should be specified' ) #NEWLINE# #UNINDENT# self . read_header = read_header #NEWLINE# self . encoding = encoding #NEWLINE# self . empty_as_null = empty_as_null #NEWLINE# self . dialect = dialect #NEWLINE# self . delimiter = delimiter #NEWLINE# self . skip_rows = ( skip_rows or 0 ) #NEWLINE# self . fields = fields #NEWLINE# self . type_converters = ( type_converters or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# self . resource = Resource ( resource , encoding = self . encoding ) #NEWLINE# self . handle = self . resource . open ( ) #NEWLINE# options = ( dict ( options ) if options else { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if self . dialect : #NEWLINE# #INDENT# if isinstance ( self . dialect , str ) : #NEWLINE# #INDENT# options [ 'dialect' ] = csv . get_dialect ( self . dialect ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# options [ 'dialect' ] = self . dialect #NEWLINE# #UNINDENT# #UNINDENT# if self . delimiter : #NEWLINE# #INDENT# options [ 'delimiter' ] = self . delimiter #NEWLINE# #UNINDENT# self . options = options #NEWLINE# self . reader = csv . reader ( self . handle , ** options ) #NEWLINE# if self . skip_rows : #NEWLINE# #INDENT# for i in range ( 0 , self . skip_rows ) : #NEWLINE# #INDENT# next ( self . reader ) #NEWLINE# #UNINDENT# #UNINDENT# if self . read_header : #NEWLINE# #INDENT# field_names = next ( self . reader ) #NEWLINE# if ( not self . fields ) : #NEWLINE# #INDENT# fields = [ ( name , 'string' , 'default' ) for name in field_names ] #NEWLINE# self . fields = FieldList ( * fields ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . fields ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Fields are not initialized. Either read fields from CSV header or set them manually' ) #NEWLINE# #UNINDENT# self . set_fields ( self . fields )