Current File : //lib/python2.7/site-packages/vdo/utils/Transaction.pyc
�
.�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����(twrapsNtTransactioncBsYeZdZiZed��Zd�Zdd�Zd�Z	ed��Z
d�ZRS(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.pyttransaction-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|<nX|S(s�Returns the transaction list for the current thread, creating it
       if need be.

       Returns:
         list of Transactions
    N(tNonet	threadingt
currentThreadtidentt_Transaction__transactionListstKeyError(RttransactionListtthreadId((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyR[s
cCs|jS(sgReturns the list of undo stages for the transaction.

       Returns:
         list of undo stages
    (R(R((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyt_undoStagesmsN(t__name__t
__module__t__doc__RtclassmethodRR	RR
RRR(((s9/usr/lib/python2.7/site-packages/vdo/utils/Transaction.pyR"s	
	cs>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.pytremoveTransaction�scSs�|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"(RRR((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.pyt<module>s
X