ó
Ñ7ec           @   sk   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z m Z e  j d ƒ Z	 d e f d „  ƒ  YZ
 d S(   iÿÿÿÿN(   t   patch_vary_headers(   t   MiddlewareMixin(   t   compress_sequencet   compress_strings   \bgzip\bt   GZipMiddlewarec           B   s   e  Z d  Z d „  Z RS(   sÇ   
    This middleware compresses content if the browser allows gzip compression.
    It sets the Vary header accordingly, so that caches will base their storage
    on the Accept-Encoding header.
    c         C   s#  | j  r# t | j ƒ d k  r# | S| j d ƒ r6 | St | d ƒ | j j d d ƒ } t j | ƒ sk | S| j  r t	 | j
 ƒ | _
 | d =nP t | j ƒ } t | ƒ t | j ƒ k r¾ | S| | _ t t | j ƒ ƒ | d <| j d ƒ } | r| j d ƒ rd	 | | d <n  d
 | d <| S(   NiÈ   s   Content-Encodings   Accept-Encodingt   HTTP_ACCEPT_ENCODINGt    s   Content-Lengtht   ETagt   "s   W/t   gzip(   s   Accept-Encoding(   t	   streamingt   lent   contentt
   has_headerR    t   METAt   gett   re_accepts_gzipt   searchR   t   streaming_contentR   t   strt
   startswith(   t   selft   requestt   responset   aet   compressed_contentt   etag(    (    s@   /usr/local/lib/python2.7/dist-packages/django/middleware/gzip.pyt   process_response   s*    	
	
(   t   __name__t
   __module__t   __doc__R   (    (    (    s@   /usr/local/lib/python2.7/dist-packages/django/middleware/gzip.pyR   
   s   (   t   ret   django.utils.cacheR    t   django.utils.deprecationR   t   django.utils.textR   R   t   compileR   R   (    (    (    s@   /usr/local/lib/python2.7/dist-packages/django/middleware/gzip.pyt   <module>   s
   