#NEWLINE# @ idiokit . stream #NEWLINE# def roomgraph( ) : #NEWLINE# #INDENT# srcs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# while True : #NEWLINE# #INDENT# ( type_id , args ) = ( yield idiokit . next ( ) ) #NEWLINE# if ( type_id == 'event' ) : #NEWLINE# #INDENT# ( src , event ) = args #NEWLINE# if ( src in srcs ) : #NEWLINE# #INDENT# dsts = set ( srcs [ src ] . classify ( event ) ) #NEWLINE# if dsts : #NEWLINE# #INDENT# ( yield idiokit . send ( src , event , dsts ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( type_id == 'inc_rule' ) : #NEWLINE# #INDENT# ( src , rule , dst ) = args #NEWLINE# if ( src not in srcs ) : #NEWLINE# #INDENT# srcs [ src ] = rules . Classifier ( ) #NEWLINE# #UNINDENT# srcs [ src ] . inc ( rule , dsts ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type_id == 'dec_rule' ) : #NEWLINE# #INDENT# ( src , rule , dst ) = args #NEWLINE# if ( src in srcs ) : #NEWLINE# #INDENT# srcs [ src ] . dec ( rule , dst ) #NEWLINE# if srcs [ src ] . is_empty ( ) : #NEWLINE# #INDENT# del srcs [ src ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise RuntimeError ( 'unknown type id {0!r}' . format ( type_id ) )