<s> """<STR_LIT>""" <EOL> from roles import RoleType , clone <EOL> from roles . context import context <EOL> class Account ( object ) : <EOL> def __init__ ( self , amount ) : <EOL> print "<STR_LIT>" + str ( amount ) <EOL> self . balance = amount <EOL> super ( Account , self ) . __init__ ( ) <EOL> def withdraw ( self , amount ) : <EOL> print "<STR_LIT>" + str ( amount ) + "<STR_LIT>" + str ( self ) <EOL> self . balance -= amount <EOL> def deposit ( self , amount ) : <EOL> print "<STR_LIT>" + str ( amount ) + "<STR_LIT>" + str ( self ) <EOL> self . balance += amount <EOL> class MoneySource ( object ) : <EOL> __metaclass__ = RoleType <EOL> def transfer ( self , amount ) : <EOL> if self . balance >= amount : <EOL> self . withdraw ( amount ) <EOL> context . sink . receive ( amount ) <EOL> class MoneySink ( object ) : <EOL> __metaclass__ = RoleType <EOL> def receive ( self , amount ) : <EOL> self . deposit ( amount ) <EOL> class TransferMoney ( object ) : <EOL> def __init__ ( self , source , sink ) : <EOL> self . source = source <EOL> self . sink = sink <EOL> self . transfer_context = context ( self , <EOL> source = MoneySource , <EOL> sink = MoneySink ) <EOL> def perform_transfer ( self , amount ) : <EOL> with self . transfer_context as ctx : <EOL> ctx . source . transfer ( amount ) <EOL> print "<STR_LIT>" , self . sink . balance <EOL> print "<STR_LIT>" , isinstance ( self . sink , Account ) <EOL> assert isinstance ( self . sink , Account ) <EOL> print "<STR_LIT>" , dst == self . sink <EOL> src = Account ( <NUM_LIT:1000> ) <EOL> dst = Account ( <NUM_LIT:0> ) <EOL> t = TransferMoney ( src , dst ) <EOL> t . perform_transfer ( <NUM_LIT:100> ) <EOL> print src , src . balance <EOL> assert src . balance == <NUM_LIT> <EOL> print dst , dst . balance <EOL> assert dst . balance == <NUM_LIT:100> </s>
