<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from os import getpid <EOL> from optparse import OptionParser <EOL> from circuits . node import Node <EOL> from circuits import Component , Debugger <EOL> __version__ = "<STR_LIT>" <EOL> USAGE = "<STR_LIT>" <EOL> VERSION = "<STR_LIT>" + __version__ <EOL> def parse_options ( ) : <EOL> parser = OptionParser ( usage = USAGE , version = VERSION ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , <EOL> default = "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> parser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> opts , args = parser . parse_args ( ) <EOL> return opts , args <EOL> class NodeServer ( Component ) : <EOL> def init ( self , args , opts ) : <EOL> """<STR_LIT>""" <EOL> self . args = args <EOL> self . opts = opts <EOL> self . clients = { } <EOL> if opts . debug : <EOL> Debugger ( ) . register ( self ) <EOL> if "<STR_LIT::>" in opts . bind : <EOL> address , port = opts . bind . split ( "<STR_LIT::>" ) <EOL> port = int ( port ) <EOL> else : <EOL> address , port = opts . bind , <NUM_LIT> <EOL> Node ( port = port , server_ip = address ) . register ( self ) <EOL> def connect ( self , sock , host , port ) : <EOL> """<STR_LIT>""" <EOL> self . clients [ sock ] = { <EOL> "<STR_LIT:host>" : sock , <EOL> "<STR_LIT:port>" : port , <EOL> } <EOL> def disconnect ( self , sock ) : <EOL> """<STR_LIT>""" <EOL> if sock not in self . clients : <EOL> return <EOL> del self . clients [ sock ] <EOL> def ready ( self , server , bind ) : <EOL> print ( "<STR_LIT>" . format ( * bind ) ) <EOL> print ( "<STR_LIT>" ) <EOL> def hello ( self ) : <EOL> return "<STR_LIT>" . format ( getpid ( ) ) <EOL> def main ( ) : <EOL> opts , args = parse_options ( ) <EOL> NodeServer ( args , opts ) . run ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
