<s> r'''<STR_LIT>''' <EOL> import select <EOL> class MitmLoop ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , blame_server , connection_server ) : <EOL> self . _servers = [ blame_server , connection_server ] <EOL> def run ( self , only_once = False , timeout = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> servers = self . _servers <EOL> while True : <EOL> fds = { server : set ( [ sock for fds in server . select_fds for sock in fds ] ) <EOL> for server in servers } <EOL> r , w , x = [ set ( ) . union ( * l ) for l in zip ( * [ server . select_fds for server in servers ] ) ] <EOL> r , w , x = select . select ( r , w , x , timeout ) <EOL> for server in servers : <EOL> filter_func = lambda fd : fd in fds [ server ] <EOL> server . on_select ( filter ( filter_func , r ) , <EOL> filter ( filter_func , w ) , <EOL> filter ( filter_func , x ) ) <EOL> if only_once : <EOL> return </s>
