#NEWLINE# @ idiokit . stream #NEWLINE# def distribute_encode( socks ) : #NEWLINE# #INDENT# writable = [ ] #NEWLINE# while True : #NEWLINE# #INDENT# ( to_all , msg ) = ( yield idiokit . next ( ) ) #NEWLINE# msg_bytes = cPickle . dumps ( msg , cPickle . HIGHEST_PROTOCOL ) #NEWLINE# data = ( struct . pack ( '!I' , len ( msg_bytes ) ) + msg_bytes ) #NEWLINE# if to_all : #NEWLINE# #INDENT# for sock in sock : #NEWLINE# #INDENT# ( yield sock . sendall ( data ) ) #NEWLINE# #UNINDENT# writable = [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# while ( not writable ) : #NEWLINE# #INDENT# ( _ , writable , _ ) = ( yield select . select ( ( ) , socks , ( ) ) ) #NEWLINE# writable = list ( writable ) #NEWLINE# #UNINDENT# ( yield writable . pop ( ) . sendall ( data ) )