<s> '''<STR_LIT>''' <EOL> from haigha . frames . method_frame import MethodFrame <EOL> from haigha . classes . protocol_class import ProtocolClass <EOL> from collections import deque <EOL> class TransactionClass ( ProtocolClass ) : <EOL> '''<STR_LIT>''' <EOL> class TransactionsNotEnabled ( ProtocolClass . ProtocolError ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( TransactionClass , self ) . __init__ ( * args , ** kwargs ) <EOL> self . dispatch_map = { <EOL> <NUM_LIT:11> : self . _recv_select_ok , <EOL> <NUM_LIT> : self . _recv_commit_ok , <EOL> <NUM_LIT> : self . _recv_rollback_ok , <EOL> } <EOL> self . _enabled = False <EOL> self . _select_cb = deque ( ) <EOL> self . _commit_cb = deque ( ) <EOL> self . _rollback_cb = deque ( ) <EOL> @ property <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def enabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _enabled <EOL> def _cleanup ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . _select_cb = None <EOL> self . _commit_cb = None <EOL> self . _rollback_cb = None <EOL> super ( TransactionClass , self ) . _cleanup ( ) <EOL> def select ( self , cb = None ) : <EOL> '''<STR_LIT>''' <EOL> if not self . _enabled : <EOL> self . _enabled = True <EOL> self . send_frame ( MethodFrame ( self . channel_id , <NUM_LIT> , <NUM_LIT:10> ) ) <EOL> self . _select_cb . append ( cb ) <EOL> self . channel . add_synchronous_cb ( self . _recv_select_ok ) <EOL> def _recv_select_ok ( self , _method_frame ) : <EOL> cb = self . _select_cb . popleft ( ) <EOL> if cb : <EOL> cb ( ) <EOL> def commit ( self , cb = None ) : <EOL> '''<STR_LIT>''' <EOL> if not self . enabled : <EOL> raise self . TransactionsNotEnabled ( ) <EOL> self . send_frame ( MethodFrame ( self . channel_id , <NUM_LIT> , <NUM_LIT:20> ) ) <EOL> self . _commit_cb . append ( cb ) <EOL> self . channel . add_synchronous_cb ( self . _recv_commit_ok ) <EOL> def _recv_commit_ok ( self , _method_frame ) : <EOL> cb = self . _commit_cb . popleft ( ) <EOL> if cb : <EOL> cb ( ) <EOL> def rollback ( self , cb = None ) : <EOL> '''<STR_LIT>''' <EOL> if not self . enabled : <EOL> raise self . TransactionsNotEnabled ( ) <EOL> self . send_frame ( MethodFrame ( self . channel_id , <NUM_LIT> , <NUM_LIT:30> ) ) <EOL> self . _rollback_cb . append ( cb ) <EOL> self . channel . add_synchronous_cb ( self . _recv_rollback_ok ) <EOL> def _recv_rollback_ok ( self , _method_frame ) : <EOL> cb = self . _rollback_cb . popleft ( ) <EOL> if cb : <EOL> cb ( ) </s>
