#NEWLINE# @ wq . command ( ) #NEWLINE# @ click . argument ( 'source' ) #NEWLINE# @ click . argument ( 'source_options' , required = False ) #NEWLINE# @ click . option ( '--format' , '-f' , default = 'csv' , help = 'Output format' ) #NEWLINE# def cat( source , source_options , format ) : #NEWLINE# #INDENT# '\n    Display contents of a file or wq.io class.  SOURCE can be either a filename\n    or a Python path.  SOURCE_OPTIONS is an optional string specifying init\n    options in "name=value" format, separated by commas.\n\n    The data will be printed to the terminal in CSV form, unless the format is\n    set to JSON.\n\n    Examples:\n\n    \x08\n    wq cat example.json\n    wq cat example.xlsx "start_row=5"\n    wq cat wq.io.CsvNetIO "url=http://example.com/example.csv"\n    ' #NEWLINE# options = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if source_options : #NEWLINE# #INDENT# for opt in source_options . split ( ',' ) : #NEWLINE# #INDENT# ( key , val ) = opt . split ( '=' ) #NEWLINE# if val . isdigit ( ) : #NEWLINE# #INDENT# val = int ( val ) #NEWLINE# #UNINDENT# options [ key ] = val #NEWLINE# #UNINDENT# #UNINDENT# if os . path . exists ( source ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# input = load_file ( source , options = options ) #NEWLINE# #UNINDENT# except IoException as e : #NEWLINE# #INDENT# raise click . ClickException ( str ( e ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# parts = source . split ( '.' ) #NEWLINE# class_name = parts [ ( - 1 ) ] #NEWLINE# module_name = '.' . join ( parts [ : ( - 1 ) ] ) #NEWLINE# try : #NEWLINE# #INDENT# module = importlib . import_module ( module_name ) #NEWLINE# IO = getattr ( module , class_name ) #NEWLINE# input = flattened ( IO , ** options ) #NEWLINE# #UNINDENT# except ( ImportError , ValueError , AttributeError , IoException ) as e : #NEWLINE# #INDENT# raise click . ClickException ( str ( e ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( format == 'json' ) : #NEWLINE# #INDENT# OutputIO = JsonStringIO #NEWLINE# init = '[]' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# OutputIO = CsvStringIO #NEWLINE# init = '' #NEWLINE# #UNINDENT# output = OutputIO ( data = input . data , string = init ) #NEWLINE# output . data = input . data #NEWLINE# output . save ( ) #NEWLINE# result = output . string #NEWLINE# if output . binary : #NEWLINE# #INDENT# result = result . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# print ( result )