<s> from __future__ import absolute_import <EOL> import codecs <EOL> from contextlib import closing <EOL> import locale <EOL> import optparse <EOL> import os <EOL> import sys <EOL> import six <EOL> from . import grid <EOL> class OutputSaver : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . __text = "<STR_LIT>" <EOL> self . __old_stdout = sys . stdout <EOL> self . __old_stderr = sys . stderr <EOL> sys . stdout = self <EOL> sys . stderr = self <EOL> def write ( self , text ) : <EOL> self . __text += text <EOL> def close ( self ) : <EOL> sys . stdout = self . __old_stdout <EOL> sys . stderr = self . __old_stderr <EOL> six . print_ ( self . __text ) <EOL> def main ( ) : <EOL> locale . setlocale ( locale . LC_ALL , "<STR_LIT>" ) <EOL> parser = optparse . OptionParser ( ) <EOL> parser . set_defaults ( hasHeader = True , commentString = None ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( frozenCols = <NUM_LIT:1> ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = "<STR_LIT:int>" , dest = "<STR_LIT>" , <EOL> help = ( "<STR_LIT>" ) ) <EOL> parser . set_defaults ( bufferSize = <NUM_LIT:100> ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = "<STR_LIT:int>" , dest = "<STR_LIT>" , <EOL> help = ( "<STR_LIT>" ) ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> "<STR_LIT:-c>" , "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , dest = "<STR_LIT>" , <EOL> help = ( "<STR_LIT>" ) ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = ( "<STR_LIT>" ) ) <EOL> options , args = parser . parse_args ( ) <EOL> encoding = locale . getpreferredencoding ( ) <EOL> if encoding . lower ( ) == "<STR_LIT:utf-8>" : <EOL> encoding = "<STR_LIT>" <EOL> if len ( args ) < <NUM_LIT:1> : <EOL> if six . PY2 : <EOL> file = os . fdopen ( os . dup ( <NUM_LIT:0> ) , '<STR_LIT:r>' ) <EOL> file = codecs . getreader ( encoding ) ( file ) <EOL> else : <EOL> file = os . fdopen ( os . dup ( <NUM_LIT:0> ) , '<STR_LIT:r>' , encoding = encoding ) <EOL> os . close ( <NUM_LIT:0> ) <EOL> sys . stdin = os . open ( "<STR_LIT>" , os . O_RDONLY ) <EOL> filename = "<STR_LIT>" <EOL> else : <EOL> filename = args [ <NUM_LIT:0> ] <EOL> if six . PY2 : <EOL> file = open ( filename , "<STR_LIT:rb>" ) <EOL> file = codecs . getreader ( encoding ) ( file ) <EOL> else : <EOL> file = open ( filename , encoding = encoding ) <EOL> with closing ( file ) : <EOL> if options . dataframe : <EOL> import pandas <EOL> df = pandas . read_csv ( file ) <EOL> model = grid . DataFrameModel ( df , filename = filename ) <EOL> else : <EOL> model = grid . DelimitedFileModel ( <EOL> file , options . hasHeader , options . bufferSize , options . delim , <EOL> options . commentString , filename = filename ) <EOL> with closing ( OutputSaver ( ) ) : <EOL> grid . show_model ( model , num_frozen = options . frozenCols ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> main ( ) <EOL> except ( IOError , EOFError ) as exc : <EOL> six . print_ ( exc , file = sys . stderr ) <EOL> except KeyboardInterrupt : <EOL> pass </s>
