#NEWLINE# @ contextmanager #NEWLINE# def json_lines( path , encoding = 'utf-8' ) : #NEWLINE# #INDENT# ' Return lines of a json-lines file\n\n    Handles compression like gzip ' #NEWLINE# if ( path . split ( os . path . extsep ) [ ( - 1 ) ] == 'gz' ) : #NEWLINE# #INDENT# f = gzip . open ( path ) #NEWLINE# lines = ( line . decode ( encoding ) for line in f ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f = open ( path ) #NEWLINE# lines = f #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( yield line ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# f . close ( )