ó
®â0_c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z m Z d  d l m Z m Z m Z d  d l m Z d  d	 l m Z d  d
 l m Z d d l m Z m Z m Z e j d ƒ Z d e  f d „  ƒ  YZ! d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   settings(   t   signals(   t   ImproperlyConfiguredt   MiddlewareNotUsed(   t   connectionst   transaction(   t   get_resolvert   get_urlconft   set_urlconf(   t   six(   t   RemovedInDjango20Warning(   t   import_stringi   (   t   convert_exception_to_responset   get_exception_responset   handle_uncaught_exceptionu   django.requestt   BaseHandlerc           B  sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C  s:   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   Nonet   _request_middlewaret   _view_middlewaret   _template_response_middlewaret   _response_middlewaret   _exception_middlewaret   _middleware_chain(   t   self(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyt   __init__   s    					c         C  sð  g  |  _  g  |  _ g  |  _ g  |  _ g  |  _ t j d k r§t j	 d t
 ƒ t |  j ƒ } x…t j D];} t | ƒ } y | ƒ  } WnW t k
 rÝ } t j re t j | ƒ rÄ t j d | | ƒ q× t j d | ƒ qe qe n Xt | d ƒ r|  j  j | j ƒ n  t | d ƒ r(|  j j | j ƒ n  t | d ƒ rP|  j j d | j ƒ n  t | d ƒ rx|  j j d | j ƒ n  t | d	 ƒ re |  j j d | j ƒ qe qe Wn<t |  j ƒ } x*t t j ƒ D]} t | ƒ } y | | ƒ } WnW t k
 rA} t j rÆt j | ƒ r(t j d | | ƒ q;t j d | ƒ qÆqÆn X| d k rat d
 | ƒ ‚ n  t | d ƒ r‰|  j j d | j ƒ n  t | d ƒ r®|  j j | j ƒ n  t | d	 ƒ rÓ|  j j | j ƒ n  t | ƒ } qÆW| |  _  d S(   uÉ   
        Populate middleware lists from settings.MIDDLEWARE (or the deprecated
        MIDDLEWARE_CLASSES).

        Must be called after the environment is fixed (see __call__ in subclasses).
        u   Old-style middleware using settings.MIDDLEWARE_CLASSES is deprecated. Update your middleware and use settings.MIDDLEWARE instead.u   MiddlewareNotUsed(%r): %su   MiddlewareNotUsed: %ru   process_requestu   process_viewu   process_template_responsei    u   process_responseu   process_exceptionu$   Middleware factory %s returned None.N(!   R   R   R   R   R   R   t
   MIDDLEWARER   t   warningst   warnR   R   t   _legacy_get_responset   MIDDLEWARE_CLASSESR   R   t   DEBUGR
   t	   text_typet   loggert   debugt   hasattrt   appendt   process_requestt   process_viewt   insertt   process_template_responset   process_responset   process_exceptiont   _get_responset   reversedR   R   (   R   t   handlert   middleware_patht   mw_classt   mw_instancet   exct
   middleware(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyt   load_middleware#   sh    						 	c         C  sj   t  | d t ƒ  ƒ } xN t j ƒ  D]@ } | j d r" | j | k r" t j d | j ƒ | ƒ } q" q" W| S(   Nu   _non_atomic_requestsu   ATOMIC_REQUESTSt   using(   t   getattrt   setR   t   allt   settings_dictt   aliasR   t   atomic(   R   t   viewt   non_atomic_requestst   db(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyt   make_view_atomicm   s
    "c         C  s   t  | | | | |  j ƒ S(   N(   R   t	   __class__(   R   t   requestt   resolvert   status_codet	   exception(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyR   t   s    c         C  sF  t  t j ƒ |  j | ƒ } yO xH |  j D]= } | | | ƒ } | d k r) t d | j j j	 ƒ ‚ q) q) WWnQ t
 k
 r¾ t j j d |  j d | ƒ |  j | t t ƒ  ƒ t j ƒ  ƒ } n X| j j | ƒ t | d t ƒ r	t t | d d ƒ ƒ r	| j ƒ  } n  | j d k rBt j d | j d i d d	 6| d
 6ƒn  | S(   u8   Return an HttpResponse object for the given HttpRequest.uS   %s.process_response didn't return an HttpResponse object. It returned None instead.t   senderR@   u   is_renderedu   renderi”  u   Not Found: %st   extrau   status_codeu   requestN(   R	   R   t   ROOT_URLCONFR   R   R   t
   ValueErrort   __self__R?   t   __name__t	   ExceptionR   t   got_request_exceptiont   sendR   R   R   t   syst   exc_infot   _closable_objectsR$   R5   t   Truet   callablet   renderRB   R!   t   warningt   path(   R   R@   t   responset   middleware_method(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyt   get_responsew   s(    (+c         C  s÷  d } t | d ƒ r7 | j } t | ƒ t | ƒ } n	 t ƒ  } | j | j ƒ } | \ } } } | | _ x0 |  j D]% }	 |	 | | | | ƒ } | rt Pqt qt W| d k rù |  j	 | ƒ }
 y |
 | | | Ž } Wqù t
 k
 rõ } |  j | | ƒ } qù Xn  | d k rOt | t j ƒ r#| j } n | j j d } t d | j | f ƒ ‚ n¤ t | d ƒ rót | j ƒ róxH |  j D]= }	 |	 | | ƒ } | d k rwt d |	 j j j ƒ ‚ qwqwWy | j ƒ  } Wqót
 k
 rï} |  j | | ƒ } qóXn  | S(   uÉ   
        Resolve and call the view, then apply view, exception, and
        template_response middleware. This method is everything that happens
        inside the request/response middleware.
        u   urlconfu	   .__call__uN   The view %s.%s didn't return an HttpResponse object. It returned None instead.u   renderu\   %s.process_template_response didn't return an HttpResponse object. It returned None instead.N(   R   R#   t   urlconfR	   R   t   resolvet	   path_infot   resolver_matchR   R>   RJ   t   process_exception_by_middlewaret
   isinstancet   typest   FunctionTypeRI   R?   RG   t
   __module__RQ   RR   R   RH   (   R   R@   RU   RX   RA   R[   t   callbackt   callback_argst   callback_kwargsRV   t   wrapped_callbackt   et	   view_name(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyR+      sL    	
		c         C  s4   x* |  j  D] } | | | ƒ } | r
 | Sq
 W‚  d S(   uŠ   
        Pass the exception to the exception middleware. If no middleware
        return a response for this exception, raise it.
        N(   R   (   R   RC   R@   RV   RU   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyR\   Ý   s
    c         C  s   t  | | | ƒ S(   u9   Allow subclasses to override uncaught exception handling.(   R   (   R   R@   RA   RN   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyR   è   s    c         C  sR   d } x' |  j D] } | | ƒ } | r Pq q W| d k rN |  j | ƒ } n  | S(   u“   
        Apply process_request() middleware and call the main _get_response(),
        if needed. Used only for legacy MIDDLEWARE_CLASSES.
        N(   R   R   R+   (   R   R@   RU   RV   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyR   ì   s    (   RI   R`   R   R3   R>   R   RW   R+   R\   R   R   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyR      s   		J			&	@		("   t
   __future__R    t   loggingRM   R^   R   t   django.confR   t   django.coreR   t   django.core.exceptionsR   R   t	   django.dbR   R   t   django.urlsR   R   R	   t   django.utilsR
   t   django.utils.deprecationR   t   django.utils.module_loadingR   RC   R   R   R   t	   getLoggerR!   t   objectR   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/handlers/base.pyt   <module>   s   