³ò
-e|Mc        
   @   sÍ   d  Z  d d k Z d d k l Z l Z d d k l Z y d d k l Z Wn# e	 j
 o d d k l Z n Xd e
 f d „  ƒ  YZ d e
 f d	 „  ƒ  YZ d
 e
 f d „  ƒ  YZ d „  Z d d „ Z d S(   s-   
WSGI middleware

Gzip-encodes the response.
iÿÿÿÿN(   t   header_valuet   remove_header(   t   CONTENT_LENGTH(   t   StringIOt
   GzipOutputc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR      s   t
   middlewarec           B   s   e  Z d  d „ Z d „  Z RS(   i   c         C   s   | |  _  t | ƒ |  _ d  S(   N(   t   applicationt   intt   compress_level(   t   selfR   R
   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyt   __init__   s    	c         C   s|   d | i  d d ƒ j o |  i | | ƒ Sn t | |  i ƒ } |  i | | i ƒ } | d  j	 o | i | ƒ n | i ƒ  S(   Nt   gzipt   HTTP_ACCEPT_ENCODINGt    (   t   getR   t   GzipResponseR
   t   gzip_start_responset   Nonet   finish_responset   write(   R   t   environt   start_responset   responset   app_iter(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyt   __call__   s    	(   R   R   R   R   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR      s   R   c           B   s/   e  Z d  „  Z d d „ Z d „  Z d „  Z RS(   c         C   s4   | |  _  | |  _ t ƒ  |  _ t |  _ d  |  _ d  S(   N(   R   R
   R   t   buffert   Falset   compressibleR   t   content_length(   R   R   R
   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR   .   s
    			c         C   sÉ   | |  _  t | d ƒ } t | d ƒ } t |  _ | o: | i d ƒ p | i d ƒ o d | j o t |  _ n | o t |  _ n |  i o | i d ƒ n t | d ƒ | |  _  | |  _ |  i	 i
 S(	   Ns   content-types   content-encodings   text/s   application/t   zipR   s   content-length(   s   content-encodings   gzip(   t   headersR    R   R   t
   startswitht   Truet   appendR   t   statusR   R   (   R   R$   R    t   exc_infot   ctt   ce(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR   5   s    		'
		c         C   s3   |  i  } | i d ƒ | i ƒ  } | i ƒ  | g S(   Ni    (   R   t   seekt   getvaluet   close(   R   t   outt   s(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR   F   s
    	
c      	   C   sÓ   |  i  o( t i d d d |  i d |  i ƒ } n
 |  i } z: x | D] } | i | ƒ qE W|  i  o | i ƒ  n Wd  t | d ƒ o | i ƒ  n X|  i i ƒ  } t	 i
 |  i | ƒ |  i |  i |  i ƒ d  S(   Nt   modet   wbt   compresslevelt   fileobjR*   (   R   R   t   GzipFileR
   R   R   R*   t   hasattrt   tellR   t   updateR    R   R$   (   R   R   t   outputR,   R   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR   M   s    
	 
N(   R   R   R   R   R   R   R   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyR   ,   s   		c         K   s,   d d  k  } | i d t d ƒ d „  } | S(   Niÿÿÿÿs=   This function is deprecated; use make_gzip_middleware insteadi   c         S   s
   t  |  ƒ S(   N(   R   (   R   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyt   filterd   s    (   t   warningst   warnt   DeprecationWarning(   R   t   confR7   R6   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyt   filter_factory_   s    
	i   c         C   s   t  | ƒ } t |  d | ƒS(   s¯   
    Wrap the middleware, so that it applies gzipping to a response
    when it is supported by the browser and the content is of
    type ``text/*`` or ``application/*``
    R
   (   R	   R   (   t   appt   global_confR
   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pyt   make_gzip_middlewareh   s    (   t   __doc__R   t   paste.responseR    R   t   paste.httpheadersR   t	   cStringIOR   t   ImportErrort   objectR   R   R   R;   R>   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/gzipper.pys   <module>   s   3		