File: //opt/alt/python27/lib/python2.7/site-packages/paste/errordocument.pyo
�
a�Nc           @   s�   d  Z  d d l Z d d l Z d d l m Z d d l m Z m Z m Z d d l m	 Z	 d d l
 m Z d �  Z d e
 f d	 �  �  YZ d
 e
 f d �  �  YZ d �  Z d
 d d d d
 g Z d d � Z d e
 f d �  �  YZ d S(   s  
Middleware to display error documents for certain status codes
The middleware in this module can be used to intercept responses with
specified status codes and internally forward the request to an appropriate
URL where the content can be displayed to the user as an error document.
i����N(   t   urlparse(   t   ForwardRequestExceptiont   RecursiveMiddlewaret
   RecursionLoop(   t
   converters(   t   replace_headerc         C   s[   x6 | D]. } t  | t � s t d t | � � � q q Wd �  } t t |  | d | �� S(   s�  
    Intercepts a response with a particular status code and returns the
    content from a specified URL instead.
    The arguments are:
    ``app``
        The WSGI application or middleware chain.
    ``codes``
        A dictionary of integer status codes and the URL to be displayed
        if the response uses that code.
    For example, you might want to create a static file to display a
    "File Not Found" message at the URL ``/error404.html`` and then use
    ``forward`` middleware to catch all 404 status codes and display the page
    you created. In this example ``app`` is your exisiting WSGI
    applicaiton::
        from paste.errordocument import forward
        app = forward(app, codes={404:'/error404.html'})
    s4   All status codes should be type int. %s is not validc         S   s   | j  |  � r | |  Sd  Sd  S(   N(   t   has_keyt   None(   t   codet   messaget   environt   global_conft   codes(    (    sD   /opt/alt/python27/lib/python2.7/site-packages/paste/errordocument.pyt   error_codes_mapper0   s    R   (   t
   isinstancet   intt	   TypeErrort   reprR   t   StatusBasedForward(   t   appR   R   R
   (    (    sD   /opt/alt/python27/lib/python2.7/site-packages/paste/errordocument.pyt   forward   s    
	t   StatusKeeperc           B   s   e  Z d  �  Z d �  Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   t   statust   urlt   headers(   t   selfR   R   R   R   (    (    sD   /opt/alt/python27/lib/python2.7/site-packages/paste/errordocument.pyt   __init__@   s    			c            s�   d  �  � f d � } �  j j d � } | d | d <t | � d k rX | d | d <n
 d | d <y �  j | | � SWnL t k
 r� } | d j d	 | � | d
 d g t j �  � d
 �  j	 g SXd  S(   Nc            sk   xR | D]J \ } } | j  �  d k r>