³ò
+e|Mc           @   s  d  Z  d d k l Z d d k l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 „  Z	 d d g Z
 d e j ow e op d d k l Z e e d d ƒZ e ƒ  Z e i ƒ  Z e i d e i d ƒ ƒ e i ƒ  \ Z Z e Ge GHn d S(   só   
Middleware related to transactions and database connections.

At this time it is very basic; but will eventually sprout all that
two-phase commit goodness that I don't need.

.. note::

   This is experimental, and will change in the future.
iÿÿÿÿ(   t   HTTPException(   t   catch_errorst   TransactionManagerMiddlewarec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   application(   t   selfR   (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   __init__   s    c         C   s@   t  ƒ  | d <} t | d <t |  i | | d | i d | i ƒS(   Ns   paste.transaction_managers   paste.throw_errorst   error_callbackt   ok_callback(   t   Managert   TrueR   R   t   errort   finish(   R   t   environt   start_responset   manager(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   __call__   s
    
	(   t   __name__t
   __module__R   R   (    (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR      s   	R   c           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  |  _ g  |  _ d  S(   N(   t   Falset   abortedt   transactions(   R   (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR   "   s    	c         C   s   t  |  _ d  S(   N(   R	   R   (   R   (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   abort&   s    c         C   s   t  |  _ |  i ƒ  d  S(   N(   R	   R   R   (   R   t   exc_info(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR
   )   s    	c         C   s:   x3 |  i  D]( } |  i o | i ƒ  q
 | i ƒ  q
 Wd  S(   N(   R   R   t   rollbackt   commit(   R   t   trans(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR   -   s
    
 
(   R   R   R   R   R
   R   (    (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR       s   			t   ConnectionFactoryc           B   s#   e  Z d  Z d „  Z d d „ Z RS(   s  
    Provides a callable interface for connecting to ADBAPI databases in
    a WSGI style (using the environment).  More advanced connection
    factories might use the REMOTE_USER and/or other environment
    variables to make the connection returned depend upon the request.
    c         O   sQ   | |  _  | |  _ | |  _ d „  |  _ t |  i  d ƒ o |  i  i |  _ n d  S(   Nc         S   s   d  |  i  d d ƒ S(   s   '%s't   's   ''(   t   replace(   t   s(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   <lambda>C   s    t   PgQuoteString(   t   modulet   argst   kwargst   quotet   hasattrR   (   R   R    R!   R"   (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR   <   s    			c         C   s?   |  i  i |  i |  i Ž  } |  i  | i d <|  i | i d <| S(   NR    R#   (   R    t   connectR!   R"   t   __dict__R#   (   R   R   t   conn(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR   G   s    N(   R   R   t   __doc__R   t   NoneR   (    (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyR   5   s   	c            s   ‡  ‡ f d †  } | S(   s  
    Provides a simple mechanism for starting a transaction based on the
    factory; and for either committing or rolling back the transaction
    depending on the result.  It checks for the response's current
    status code either through the latest call to start_response; or
    through a HTTPException's code.  If it is a 100, 200, or 300; the
    transaction is committed; otherwise it is rolled back.
    c            s_   ˆ |  ƒ ‰ ˆ |  d <d g ‰ d  ‡ ‡ f d † } d  ‡  ‡ f d † } t ˆ |  | | | ƒ S(   Ns   paste.connectioniô  c            s‚   |  o0 t  |  d t ƒ o ˆ i |  d i ƒ q7 n ˆ i ƒ  d j  o ˆ  i ƒ  n y ˆ  i ƒ  Wn d  Sn Xˆ  i ƒ  d  S(   Ni   i  (   t
   isinstanceR    t   appendt   codet   popR   R   t   close(   R   (   R'   t   should_commit(    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt	   finalizerZ   s    c            s0   ˆ i  t |  i d ƒ d ƒ ƒ ˆ  |  | | ƒ S(   Nt    i    (   R+   t   intt   split(   t   statust   headersR   (   R   R/   (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   basictrans_start_responseg   s     (   R)   R   (   R   R   R0   R6   (   R   t   factory(   R   R'   R/   s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   basic_transactionV   s    
	(    (   R   R7   R8   (    (   R   R7   s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pyt   BasicTransactionHandlerM   s    	R9   t   __main__(   t   PgSQLt   databaset   testings   SELECT now(), %ss	   B'n\'glesN(   R(   t   paste.httpexceptionsR    t   wsgilibR   t   objectR   R   R   R9   t   __all__R   R   t   pyPgSQLR;   R7   R'   t   cursort   currt   executeR#   t   fetchonet   timet   bing(    (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/transaction.pys   <module>   s   	!	