#NEWLINE# def stream_in( p , data ) : #NEWLINE# #INDENT# '\n  Streams to dat from the given command into python\n\n  Parameters\n  ----------\n  cmd: str\n    the command to execute\n  parse: boolean\n    TODO: if true, will try to parse the output from python generator or list\n\n  ' #NEWLINE# if isinstance ( data , str ) : #NEWLINE# #INDENT# data = data . encode ( ) #NEWLINE# #UNINDENT# ( stdout , stderr ) = p . communicate ( input = data ) #NEWLINE# if ( p . returncode == 1 ) : #NEWLINE# #INDENT# raise DatException ( ( 'Node.js error: ' + stderr ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( p . returncode == 127 ) : #NEWLINE# #INDENT# raise DatException ( 'It looks like `dat` commandline is missing from PATH.\n' , 'Are you sure you installed it?\nCheck http://dat-data.com for instructions' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# res = json . loads ( stdout . decode ( ) ) #NEWLINE# if ( ( type ( data ) == dict ) and res . get ( 'error' ) ) : #NEWLINE# #INDENT# return on_error ( res ) #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# res = { #NEWLINE# #INDENT# 'stdout' : stdout , #NEWLINE# 'stderr' : stderr , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# return res