σ
¬PrOc           @@  sR   d  d l  m Z d  d l Z d  d l m Z d  d l Z d e f d     YZ d S(   i    (   t   absolute_importN(   t   StringIOt   CgitbMiddlewarec           B@  s>   e  Z d  Z e d d d d  Z d   Z d   Z d   Z RS(   sω   Forked from paste.cgitb_catcher.

    If bazjunk.catch_errors is False in environ, display a HTML
    error page instead, generated by a passed-in callable, unless
    the response has already started.
    
    Fix handling of GeneratorExit/.close()i   t   htmlc         C@  s@   | |  _  | |  _ | |  _ | |  _ t |  |  _ | |  _ d  S(   N(   t   appt   gen_htmlt   displayt   logdirt   intt   contextt   format(   t   selfR   R   R   R   R	   R
   (    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyt   __init__   s    				c         C@  s₯   y& |  j  | |  } |  j | |  SWnx d | k r>   n  t j   } | d d g |  | j d d    |  r |  j | |  } n |  j   } | g SXd  S(   Ns   bazjunk.throw_errorss   500 Internal Server Errors   content-types	   text/htmls   bazjunk.catch_errorsc         S@  s   t  S(   N(   t   False(   t   e(    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyt   <lambda>+   s    (   s   content-types	   text/html(   R   t   catching_itert   syst   exc_infot   gett   exception_handlerR   (   R   t   environt   start_responset   app_iterR   t   response(    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyt   __call__   s    	c         c@  s  | s t   n  t } y< x | D] } | Vq Wt | d  rP t } | j   n  Wnΐ t k
 r | rt | d  r| j   qn d | k r   n  |  j t j   |  } | rt | d  ry | j   Wq|  j t j   |  } | d | 7} qXn  | Vn Xd  S(   Nt   closes   bazjunk.throw_errorss$   <hr noshade>Error in .close():<br>%s(	   t   StopIterationR   t   hasattrt   TrueR   t   GeneratorExitR   R   R   (   R   R   R   t   error_on_closet   vR   t   close_response(    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyR   1   s4    		c         C@  st   | j  d d    |  s!   n  t   } t j d | d |  j d |  j d |  j d |  j  } | |   | j   S(   Ns   bazjunk.catch_errorsc         S@  s   t  S(   N(   R   (   R   (    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyR   N   s    t   fileR   R   R	   R
   (	   R   R   t   cgitbt   HookR   R   R	   R
   t   getvalue(   R   R   R   t
   dummy_filet   hook(    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyR   M   s    				
N(	   t   __name__t
   __module__t   __doc__R   t   NoneR   R   R   R   (    (    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyR   	   s   		(   t
   __future__R    R#   t	   cStringIOR   R   t   objectR   (    (    (    sa   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/bazjunk/middleware/cgitb.pyt   <module>   s   