ó
TR¹Nc           @   so   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z d e	 f d     YZ
 d   Z d S(	   i’’’’N(   t   http(   t   signals(   t   force_unicode(   t   import_modulet   BaseHandlerc           B   s_   e  Z e j e j e j e j g Z d    Z d   Z	 d   Z
 d   Z d d  Z d   Z RS(   c         C   s"   d  |  _ |  _ |  _ |  _ d  S(   N(   t   Nonet   _request_middlewaret   _view_middlewaret   _response_middlewaret   _exception_middleware(   t   self(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyt   __init__   s    c         C   sņ  d d l  m } d d l m } g  |  _ g  |  _ g  |  _ g  } x”| j D]} y | j d  } Wn$ t	 k
 r | j
 d |   n X| |  | | d } } y t |  } Wn, t k
 rā }	 | j
 d | |	 f   n Xy t | |  }
 Wn* t k
 r"| j
 d | | f   n Xy |
   } Wn | j k
 rIqK n Xt | d	  rl| j | j  n  t | d
  r|  j j | j  n  t | d  r¹|  j j d | j  n  t | d  rK |  j j d | j  qK qK W| |  _ d S(   s   
        Populate middleware lists from settings.MIDDLEWARE_CLASSES.

        Must be called after the environment is fixed (see __call__).
        i’’’’(   t   settings(   t
   exceptionst   .s   %s isn't a middleware modulei   s#   Error importing middleware %s: "%s"s3   Middleware module "%s" does not define a "%s" classt   process_requestt   process_viewt   process_responsei    t   process_exceptionN(   t   django.confR   t   django.coreR   R   R   R	   t   MIDDLEWARE_CLASSESt   rindext
   ValueErrort   ImproperlyConfiguredR   t   ImportErrort   getattrt   AttributeErrort   MiddlewareNotUsedt   hasattrt   appendR   R   t   insertR   R   R   (   R
   R   R   t   request_middlewaret   middleware_patht   dott	   mw_modulet   mw_classnamet   modt   et   mw_classt   mw_instance(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyt   load_middleware   sB    			c         C   sō  d d l  m } m } d d l m } z¹y| j } | j |  | j d |  } x' |  j D] } | |  } | r^ | Sq^ Wt	 | d  rø | j
 } | j |  | j d |  } n  | j | j  \ }	 }
 } x0 |  j D]% } | | |	 |
 |  } | rŻ | SqŻ Wy |	 | |
 |  } WnC t k
 ra} x* |  j D] } | | |  } | r8| Sq8W  n X| d	 k r»y |	 j } Wn! t k
 r|	 j j d } n Xt d |	 j | f   n  | SWnt j k
 rm} | j ržd d l m } | j | |  Sy# | j   \ }	 } |	 | |  SWqŽz |  j | | t j     SWd	 t! j" j# d
 |  j d |  } XqŽXnq | j$ k
 rt j% d  St& k
 r  nA t j    } t! j" j# d
 |  j d |  } |  j | | |  SXWd	 | j d	  Xd	 S(   s8   Returns an HttpResponse object for the given HttpRequesti’’’’(   R   t   urlresolvers(   R   s   ^/t   urlconfs	   .__call__s4   The view %s.%s didn't return an HttpResponse object.(   t   debugNt   sendert   requests   <h1>Permission denied</h1>('   R   R   R*   R   R   t   ROOT_URLCONFt   set_urlconft   RegexURLResolverR   R   R+   t   resolvet	   path_infoR   t	   ExceptionR	   R   t	   func_nameR   t	   __class__t   __name__R   t
   __module__R    t   Http404t   DEBUGt   django.viewsR,   t   technical_404_responset
   resolve404t   handle_uncaught_exceptiont   syst   exc_infoR   t   got_request_exceptiont   sendt   PermissionDeniedt   HttpResponseForbiddent
   SystemExit(   R
   R.   R   R*   R   R+   t   resolvert   middleware_methodt   responset   callbackt   callback_argst   callback_kwargsR&   t	   view_nameR,   t
   param_dictt	   receiversR@   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyt   get_responseB   sp    			&c         C   s  d d l  m } d d l m } | j r/   n  | j rX d d l m } | j | |  Sd | j	 j
 d  | j k r| d p d | j f } y t |  } Wn d	 } n Xd
 |  j |  | f }	 | | |	 d t | j d k rž | d d | d  n  | j   \ }
 } |
 | |  S(   s  
        Processing for any otherwise uncaught exceptions (those that will
        generate HTTP 500 responses). Can be overridden by subclasses who want
        customised 500 handling.

        Be *very* careful when overriding this because the error could be
        caused by anything, so assuming something like the database is always
        available would be an error.
        i’’’’(   R   (   t   mail_admins(   R,   s   Error (%s IP): %st   REMOTE_ADDRt   internalt   EXTERNALs   Request repr() unavailables   %s

%st   fail_silentlyi   i   N(   R   R   t   django.core.mailRP   t   DEBUG_PROPAGATE_EXCEPTIONSR:   R;   R,   t   technical_500_responset   METAt   gett   INTERNAL_IPSt   patht   reprt   _get_tracebackt   Truet   urlconf_moduleR   t
   resolve500(   R
   R.   RF   R@   R   RP   R,   t   subjectt   request_reprt   messageRI   RM   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyR>      s$    
		4
c         C   s.   d d l  } d j | j | p' t j      S(   s3   Helper function to return the traceback as a stringi’’’’Ns   
(   t	   tracebackt   joint   format_exceptionR?   R@   (   R
   R@   Rd   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyR]   ·   s    c         C   s'   x  |  j  D] } | | |  } q
 W| S(   s“   
        Applies each of the functions in self.response_fixes to the request and
        response, modifying the response in the process. Returns the new
        response.
        (   t   response_fixes(   R
   R.   RH   t   func(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyt   apply_response_fixes¼   s    N(   R7   R8   R    t   fix_location_headert   conditional_content_removalt   fix_IE_for_attacht   fix_IE_for_varyRg   R   R)   RO   R>   R   R]   Ri   (    (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyR      s   		.	R	#c         C   s   d d l  m } | j d	 k	 r, t | j  S|  j d d  } | sY |  j d d  } n  | r t | t |  j d d     St |  j d d   S(
   sG  
    Returns the equivalent of the HTTP request's SCRIPT_NAME environment
    variable. If Apache mod_rewrite has been used, returns what would have been
    the script name prior to any rewriting (so it's the script name as seen
    from the client's perspective), unless DJANGO_USE_POST_REWRITE is set (to
    anything).
    i’’’’(   R   t
   SCRIPT_URLu    t   REDIRECT_URLt	   PATH_INFOt    t   SCRIPT_NAMEN(   R   R   t   FORCE_SCRIPT_NAMER   R   RY   t   len(   t   environR   t
   script_url(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyt   get_script_nameĘ   s    !(   R?   t   djangoR    R   R   t   django.utils.encodingR   t   django.utils.importlibR   t   objectR   Rw   (    (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/handlers/base.pyt   <module>   s   ¾