<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import select <EOL> from spockbot . plugins . base import PluginBase , pl_announce <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> @ pl_announce ( '<STR_LIT>' ) <EOL> class SelectPlugin ( PluginBase ) : <EOL> requires = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , ploader , settings ) : <EOL> super ( SelectPlugin , self ) . __init__ ( ploader , settings ) <EOL> self . sockets = set ( ) <EOL> self . sending = set ( ) <EOL> ploader . provides ( '<STR_LIT>' , self ) <EOL> def register_socket ( self , sock ) : <EOL> """<STR_LIT>""" <EOL> self . sockets . add ( sock ) <EOL> def unregister_socket ( self , sock ) : <EOL> self . sockets . remove ( sock ) <EOL> def schedule_sending ( self , sock ) : <EOL> """<STR_LIT>""" <EOL> self . sending . add ( sock ) <EOL> def poll ( self ) : <EOL> timeout = self . timers . get_timeout ( ) <EOL> if timeout < <NUM_LIT:0> : <EOL> timeout = <NUM_LIT:5> <EOL> select_args = [ <EOL> tuple ( self . sockets ) , <EOL> tuple ( self . sending ) , <EOL> tuple ( self . sockets ) , <EOL> timeout , <EOL> ] <EOL> self . sending . clear ( ) <EOL> try : <EOL> ready_lists = select . select ( * select_args ) <EOL> except select . error as e : <EOL> logger . error ( '<STR_LIT>' , str ( e ) , e . args ) <EOL> return <EOL> for ready_socks , kind in zip ( ready_lists , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> for sock in ready_socks : <EOL> self . event . emit ( '<STR_LIT>' % kind , sock . fileno ( ) ) <EOL> self . event . emit ( '<STR_LIT>' % ( kind , sock . fileno ( ) ) , <EOL> sock . fileno ( ) ) </s>
