ó .Åt_c@sjdZddlmZddlZddlZddlZejdƒdefd„ƒYZd„Z dS(s~ Transaction - provides transactional support $Id: //eng/vdo-releases/magnesium/src/python/vdo/utils/Transaction.py#1 $ iÿÿÿÿ(twrapsNt TransactioncBsYeZdZiZed„ƒZd„Zdd„Zd„Z ed„ƒZ d„Z RS(s%Client-visible transaction object. cCs|jƒdS(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(sÇAdds 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 t‚dS(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|ƒjƒg|_dS(N(tsuperRt__init__R(R((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyRTscCsQd}tjƒj}y|j|}Wn$tk rLg}||j|dtf‡fd†ƒY‰tˆƒ‡‡fd†ƒ}|S(sGMethod decorator providing transactional capabilities to the method. t _TransactioncsPeZdZed„ƒZed„ƒZd„Z‡fd†Zdd„Z RS(sYDecorator-local transaction object providing actual transaction capabilities. cSs |jƒj|ƒƒ|jƒS(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.pytaddTransaction‡scSs|jƒjƒdS(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|jtdƒj|jt|ƒƒƒq_|jt|ƒƒn|jƒ}|jƒx-|D]%}y |ƒWq}tk r¡q}Xq}WdS(sÍPerforms 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.pytundo—s      cs)tˆ|ƒjƒd|_d|_dS(N(RRRR!R"(R(R(s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyR³s 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   cszˆjƒ}d}zVyˆ||Ž}Wn<tk rf}|j|ƒt|ƒ|tjƒd‚nXWdˆjƒX|S(sDWrapper method providing transactional processing capabilities. iN(RRR'R*ttypetsystexc_infoR (targstkwargsRtresulttex(Rtfunc(s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pytwrapÉs  $ (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