³ò
+e|Mc           @   sz   d  Z  d d k l Z d d k l Z d d k Z d d k l Z d g Z d d „ Z	 d e
 f d	 „  ƒ  YZ d
 „  Z d S(   sZ   
Cascades through several applications, so long as applications
return ``404 Not Found``.
iÿÿÿÿ(   t   httpexceptions(   t
   convertersN(   t   StringIOt   Cascadet   404c   	      K   sÎ   t  t t i | ƒ ƒ } g  } xl | i ƒ  D]^ \ } } | i d ƒ p t d | | f ƒ ‚ n |  i | d | ƒ} | i | | f ƒ q+ W| i	 ƒ  g  } | D] \ } } | | q¢ ~ } t
 | d | ƒS(   s!  
    Entry point for Paste Deploy configuration
    
    Expects configuration like::

        [composit:cascade]
        use = egg:Paste#cascade
        # all start with 'app' and are sorted alphabetically
        app1 = foo
        app2 = bar
        ...
        catch = 404 500 ...
    t   appsL   Bad configuration key %r (=%r); all configuration keys must start with 'app't   global_conft   catch(   t   mapt   intR   t   aslistt   itemst
   startswitht
   ValueErrort   get_appt   appendt   sortR   (	   t   loaderR   R   t
   local_conft   appst   namet   valueR   t   _[1](    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pyt   make_cascade   s     
'c           B   s#   e  Z d  Z d d „ Z d „  Z RS(   sf  
    Passed a list of applications, ``Cascade`` will try each of them
    in turn.  If one returns a status code listed in ``catch`` (by
    default just ``404 Not Found``) then the next application is
    tried.

    If all applications fail, then the last application's failure
    response is used.

    Instances of this class are WSGI applications.
    i”  c         C   sÊ   | |  _  h  |  _ g  |  _ x– | D]Ž } t | t ƒ o  t | i d  d ƒ d ƒ } n t | t i	 ƒ o | } | i
 } n t i | ƒ } | } | |  i | <|  i i | ƒ q" Wt |  i ƒ |  _ d  S(   Ni   i    (   R   t   catch_codest   catch_exceptionst
   isinstancet   strR	   t   splitt   NoneR    t   HTTPExceptiont   codet   get_exceptionR   t   tuple(   t   selft   applicationsR   t   errort   excR   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pyt   __init__9   s    			  c            sB  g  ‰ d	 ‡ ‡ ‡  f d † } y# t | i d d ƒ p d ƒ } Wn t j
 o d } n X| d j o÷ t } | d j p | d j  o° t i ƒ  } | d j  o | i | d i ƒ  ƒ nl | } xb | d j oT | d i t	 | d ƒ ƒ } | p t
 d ƒ ‚ n | i | ƒ | t | ƒ 8} qÇ W| i d ƒ n t | d i | ƒ ƒ } | | d <n t } x¨ ˆ i d  D]™ }	 | i ƒ  }
 | o |
 d i d ƒ n g  ‰ yJ |	 |
 | ƒ } ˆ p | Sn) t | d ƒ o t | ƒ | i ƒ  n Wquˆ i j
 o	 } quXquW| o | d i d ƒ n ˆ i d | ˆ  ƒ S(
   s,   
        WSGI application interface
        c            sQ   t  |  i d  d ƒ d ƒ } | ˆ i j o ˆ  i d  ƒ t Sn ˆ |  | | ƒ S(   Ni   i    (   R	   R   R   R   R   t   _consuming_writer(   t   statust   headerst   exc_infoR   (   t   failedR"   t   start_response(    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pyt   repl_start_responseO   s
    t   CONTENT_LENGTHi    i   s
   wsgi.inputs   Request body truncatediÿÿÿÿt   closeN(   R   R	   t   getR   t   Truet   tempfilet   TemporaryFilet   writet   readt   mint   IOErrort   lent   seekR   t   FalseR   t   copyt   hasattrt   listR/   R   (   R"   t   environR,   R-   t   lengtht   copy_wsgi_inputt   ft   copy_lent   chunkR   t   environ_copyt   vt   e(    (   R,   R"   R+   s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pyt   __call__J   sT    #  
	(   i”  (   t   __name__t
   __module__t   __doc__R&   RG   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pyR   +   s   c         C   s   d  S(   N(    (   t   s(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pyR'   „   s    (   RJ   t   pasteR    t
   paste.utilR   R2   t	   cStringIOR   t   __all__R   t   objectR   R'   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/cascade.pys   <module>   s   	Y