<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function , with_statement <EOL> import select <EOL> from tornado . ioloop import IOLoop , PollIOLoop <EOL> class _Select ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . read_fds = set ( ) <EOL> self . write_fds = set ( ) <EOL> self . error_fds = set ( ) <EOL> self . fd_sets = ( self . read_fds , self . write_fds , self . error_fds ) <EOL> def close ( self ) : <EOL> pass <EOL> def register ( self , fd , events ) : <EOL> if fd in self . read_fds or fd in self . write_fds or fd in self . error_fds : <EOL> raise IOError ( "<STR_LIT>" % fd ) <EOL> if events & IOLoop . READ : <EOL> self . read_fds . add ( fd ) <EOL> if events & IOLoop . WRITE : <EOL> self . write_fds . add ( fd ) <EOL> if events & IOLoop . ERROR : <EOL> self . error_fds . add ( fd ) <EOL> self . read_fds . add ( fd ) <EOL> def modify ( self , fd , events ) : <EOL> self . unregister ( fd ) <EOL> self . register ( fd , events ) <EOL> def unregister ( self , fd ) : <EOL> self . read_fds . discard ( fd ) <EOL> self . write_fds . discard ( fd ) <EOL> self . error_fds . discard ( fd ) <EOL> def poll ( self , timeout ) : <EOL> readable , writeable , errors = select . select ( <EOL> self . read_fds , self . write_fds , self . error_fds , timeout ) <EOL> events = { } <EOL> for fd in readable : <EOL> events [ fd ] = events . get ( fd , <NUM_LIT:0> ) | IOLoop . READ <EOL> for fd in writeable : <EOL> events [ fd ] = events . get ( fd , <NUM_LIT:0> ) | IOLoop . WRITE <EOL> for fd in errors : <EOL> events [ fd ] = events . get ( fd , <NUM_LIT:0> ) | IOLoop . ERROR <EOL> return events . items ( ) <EOL> class SelectIOLoop ( PollIOLoop ) : <EOL> def initialize ( self , ** kwargs ) : <EOL> super ( SelectIOLoop , self ) . initialize ( impl = _Select ( ) , ** kwargs ) </s>
