ó
K~‰Pc           @   s[   d  d l  Z  d  d l m Z m Z d  d l m Z e  j d ƒ Z d e f d „  ƒ  YZ	 d S(   iÿÿÿÿN(   t   compress_sequencet   compress_string(   t   patch_vary_headerss   \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   sy  | j  r# t | j ƒ d k  r# | St | d ƒ | j d ƒ rC | Sd | j j d d ƒ j ƒ  k rŸ | j d d ƒ j ƒ  } | j d ƒ s˜ d	 | k rŸ | Sn  | j j d
 d ƒ } t	 j
 | ƒ sÇ | S| j  rì t | j ƒ | _ | d =nP t | j ƒ } t | ƒ t | j ƒ k r| S| | _ t t | j ƒ ƒ | d <| j d ƒ rkt j d d | d ƒ | d <n  d | d <| S(   NiÈ   s   Accept-Encodings   Content-Encodingt   msiet   HTTP_USER_AGENTt    s   Content-Types   text/t
   javascriptt   HTTP_ACCEPT_ENCODINGs   Content-Lengtht   ETags   "$s   ;gzip"t   gzip(   s   Accept-Encoding(   t	   streamingt   lent   contentR   t
   has_headert   METAt   gett   lowert
   startswitht   re_accepts_gzipt   searchR    t   streaming_contentR   t   strt   ret   sub(   t   selft   requestt   responset   ctypet   aet   compressed_content(    (    s/   ../Django//lib/python/django/middleware/gzip.pyt   process_response   s0    !	
	 
(   t   __name__t
   __module__t   __doc__R   (    (    (    s/   ../Django//lib/python/django/middleware/gzip.pyR      s   (
   R   t   django.utils.textR    R   t   django.utils.cacheR   t   compileR   t   objectR   (    (    (    s/   ../Django//lib/python/django/middleware/gzip.pyt   <module>   s   