<s> import logging <EOL> from slumber . exceptions import HttpClientError <EOL> from arangodb . api import Client <EOL> from arangodb . transaction . api import TransactionCollection <EOL> from arangodb . transaction . javascript . code import Generator <EOL> logger = logging . getLogger ( name = '<STR_LIT>' ) <EOL> class TransactionController ( object ) : <EOL> """<STR_LIT:U+0020>""" <EOL> class InvalidTransactionException ( Exception ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def start ( self , transaction ) : <EOL> """<STR_LIT:U+0020>""" <EOL> statements = transaction . compile ( ) <EOL> client = Client . instance ( ) <EOL> api = client . api <EOL> query = { <EOL> '<STR_LIT>' : transaction . collections , <EOL> '<STR_LIT:action>' : statements , <EOL> } <EOL> logger . debug ( query ) <EOL> try : <EOL> val = api . transaction . post ( data = query ) <EOL> return val <EOL> except HttpClientError as err : <EOL> raise TransactionController . InvalidTransactionException ( err . content ) <EOL> class Transaction ( object ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def __init__ ( self , collections ) : <EOL> """<STR_LIT:U+0020>""" <EOL> self . collections = collections <EOL> self . js = Generator ( ) <EOL> self . actions = [ ] <EOL> def collection ( self , name ) : <EOL> """<STR_LIT:U+0020>""" <EOL> return TransactionCollection ( name = name , transaction = self ) <EOL> def add_action ( self , action ) : <EOL> self . actions . append ( action ) <EOL> def compile ( self ) : <EOL> """<STR_LIT:U+0020>""" <EOL> for action in self . actions : <EOL> self . js . compile_action ( action = action ) <EOL> return self . js . code ( ) </s>
