<s> from twisted . python import util <EOL> from twisted . spread import pb <EOL> from twisted . cred import portal , checkers , credentials <EOL> class Avatar ( pb . Avatar ) : <EOL> def perspective_exception ( self , x ) : <EOL> return x / <NUM_LIT:0> <EOL> class Realm : <EOL> def requestAvatar ( self , interface , mind , * interfaces ) : <EOL> if pb . IPerspective in interfaces : <EOL> return pb . IPerspective , Avatar ( ) , lambda : None <EOL> def cbLogin ( avatar ) : <EOL> avatar . callRemote ( "<STR_LIT>" , <NUM_LIT:10> ) . addCallback ( str ) . addCallback ( util . println ) <EOL> def ebLogin ( failure ) : <EOL> print failure <EOL> def main ( ) : <EOL> c = checkers . InMemoryUsernamePasswordDatabaseDontUse ( user = "<STR_LIT>" ) <EOL> p = portal . Portal ( Realm ( ) , [ c ] ) <EOL> server = pb . PBServerFactory ( p ) <EOL> server . unsafeTracebacks = True <EOL> client = pb . PBClientFactory ( ) <EOL> login = client . login ( credentials . UsernamePassword ( "<STR_LIT:user>" , "<STR_LIT>" ) ) <EOL> login . addCallback ( cbLogin ) . addErrback ( ebLogin ) . addBoth ( lambda : reactor . stop ( ) ) <EOL> from twisted . internet import reactor <EOL> p = reactor . listenTCP ( <NUM_LIT:0> , server ) <EOL> c = reactor . connectTCP ( '<STR_LIT:127.0.0.1>' , p . getHost ( ) . port , client ) <EOL> reactor . run ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
