.t_c@sjdZddlmZddlZddlZddlZejddefdYZdZ dS(s~ Transaction - provides transactional support $Id: //eng/vdo-releases/magnesium/src/python/vdo/utils/Transaction.py#1 $ i(twrapsNt TransactioncBsYeZdZiZedZdZddZdZ edZ dZ RS(s%Client-visible transaction object. cCs|jdS(s<Returns the current transaction for the current thread. i(t_threadTransactionList(tcls((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyt transaction-scCs|jj|dS(sAdds callable undoStage to transaction stages. Arguments: undoStage (callable) - callable to execute as part of transaction roll-back N(t_Transaction__undoStagestappend(tselft undoStage((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyt addUndoStage4scCs tdS(s+Sets the message to handle if there is an exception. If message is specified and an exception occurs the exception will be appended to the message using "; {0}" where "{0}" represents the exception. If message is not specified, the exception will be coerced to a string and passed to handleMessage. Specifying handleMessage as None will clear both handleMessage and message. Arguments: handleMessage (callable) - method to handle message message (string) - message N(tNotImplementedError(Rt handleMessagetmessage((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyt setMessage>scCs tt|jg|_dS(N(tsuperRt__init__R(R((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyRTscCsQd}tjj}y|j|}Wn$tk rLg}||j|dtffdYtfd}|S(sGMethod decorator providing transactional capabilities to the method. t _TransactioncsPeZdZedZedZdZfdZddZ RS(sYDecorator-local transaction object providing actual transaction capabilities. cSs |jj||jS(s`Adds, and returns, a transaction to the transaction list for the current thread. (RRR(R((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pytaddTransactionscSs|jjdS(sBRemoves the current transaction for for the current thread. N(Rtpop(R((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pytremoveTransactionscSs|jdk r_|jdk rI|jtdj|jt|q_|jt|n|j}|jx-|D]%}y |Wq}tk rq}Xq}WdS(sPerforms the undo processing of the transaction. Exceptions from the undo stages are ignored. Arguments: exception - the exception which resulted in undo being called s{0}; {1}N( t_Transaction__handleMessageRt_Transaction__messaget_tformattstrRtreverset Exception(Rt exceptiont undoStagesR((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pytundos      cs)t|jd|_d|_dS(N(RRRR!R"(R(R(s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyRs cSs1||_|jdkr$d|_n ||_dS(N(R!RR"(RR R ((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyR s  N( RRRRRR R*RRR ((R(s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyRs   cszj}d}zVy||}Wn<tk rf}|j|t||tjdnXWdjX|S(sDWrapper method providing transactional processing capabilities. iN(RRR'R*ttypetsystexc_infoR (targstkwargsRtresulttex(Rtfunc(s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pytwraps  $ (RR(R2R3((RR2s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyt transactionalzsJ( Rt functoolsRtgettextR,RtinstalltobjectRR4(((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyts    X