<s> from twisted . internet . protocol import Factory <EOL> from twisted . internet import reactor <EOL> from Cli_session import Cli_session <EOL> from os import chown , unlink <EOL> from os . path import exists <EOL> class Cli_server_local ( Factory ) : <EOL> command_cb = None <EOL> def __init__ ( self , command_cb , address = None , sock_owner = None ) : <EOL> self . command_cb = command_cb <EOL> self . protocol = Cli_session <EOL> if address == None : <EOL> address = '<STR_LIT>' <EOL> if exists ( address ) : <EOL> unlink ( address ) <EOL> reactor . listenUNIX ( address , self ) <EOL> if sock_owner != None : <EOL> chown ( address , sock_owner [ <NUM_LIT:0> ] , sock_owner [ <NUM_LIT:1> ] ) <EOL> def buildProtocol ( self , addr ) : <EOL> p = Factory . buildProtocol ( self , addr ) <EOL> p . command_cb = self . command_cb <EOL> return p <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> def callback ( clm , cmd ) : <EOL> print cmd <EOL> return False <EOL> f = Cli_server_local ( callback ) <EOL> reactor . run ( ) </s>
