<s> from twisted . web import xmlrpc , server <EOL> class EchoHandler : <EOL> def echo ( self , x ) : <EOL> """<STR_LIT>""" <EOL> return x <EOL> class AddHandler : <EOL> def add ( self , a , b ) : <EOL> """<STR_LIT>""" <EOL> return a + b <EOL> class Example ( xmlrpc . XMLRPC ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> xmlrpc . XMLRPC . __init__ ( self ) <EOL> self . _addHandler = AddHandler ( ) <EOL> self . _echoHandler = EchoHandler ( ) <EOL> self . _procedureToCallable = { <EOL> '<STR_LIT>' : self . _addHandler . add , <EOL> '<STR_LIT>' : self . _echoHandler . echo <EOL> } <EOL> def lookupProcedure ( self , procedurePath ) : <EOL> try : <EOL> return self . _procedureToCallable [ procedurePath ] <EOL> except KeyError , e : <EOL> raise xmlrpc . NoSuchFunction ( self . NOT_FOUND , <EOL> "<STR_LIT>" % procedurePath ) <EOL> def listProcedures ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from twisted . internet import reactor <EOL> r = Example ( ) <EOL> reactor . listenTCP ( <NUM_LIT> , server . Site ( r ) ) <EOL> reactor . run ( ) </s>
