ó
Xé?_c           @   sÙ   d  d l  Z  d  d l Z d  d l Z d  d l m Z m Z m Z m Z d  d l m	 Z	 d  d l m
 Z
 d  d l m Z d d d „ Z d d d	 „  ƒ  YZ d
 d d „  ƒ  YZ d „  Z d „  Z d d d g e d „ Z d S(   iÿÿÿÿN(   t
   basestringt   BytesIOt   ntobt
   unicodestr(   t   file_generator(   t   is_closable_iterator(   t   set_vary_headers   utf-8c         C   sw   t  j j } |  d k	 r? t |  t ƒ s3 |  g }  n  |  | _ n4 | rs t | t ƒ s` | g } n  | j | | _ n  d S(   s;  Replace or extend the list of charsets used to decode a request entity.

    Either argument may be a single string or a list of strings.

    encoding
        If not None, restricts the set of charsets attempted while decoding
        a request entity to the given set (even if a different charset is
        given in the Content-Type request header).

    default_encoding
        Only in effect if the 'encoding' argument is not given.
        If given, the set of charsets attempted while decoding a request
        entity is *extended* with the given value(s).

    N(   t   cherrypyt   requestt   bodyt   Nonet
   isinstancet   listt   attempt_charsets(   t   encodingt   default_encodingR	   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   decode   s    t   UTF8StreamEncoderc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t	   _iterator(   t   selft   iterator(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   __init__&   s    c         C   s   |  S(   N(    (   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   __iter__)   s    c         C   s
   |  j  ƒ  S(   N(   t   __next__(   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   next,   s    c         C   s4   t  |  j ƒ } t | t ƒ r0 | j d ƒ } n  | S(   Ns   utf-8(   R   R   R   R   t   encode(   R   t   res(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyR   /   s    c         C   s#   t  |  j ƒ r |  j j ƒ  n  d  S(   N(   R   R   t   close(   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyR   5   s    c         C   s1   | j  d ƒ r! t |  | ƒ ‚ n  t |  j | ƒ S(   Nt   __(   t
   startswitht   AttributeErrort   getattrR   (   R   t   attr(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   __getattr__9   s    (   t   __name__t
   __module__R   R   R   R   R   R!   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyR   %   s   					t   ResponseEncoderc           B   s_   e  Z d  Z d Z d Z d Z e Z e Z	 e
 Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(	   s   utf-8s+   Response body could not be encoded with %r.t   strictc         K   sŒ   x* | j  ƒ  D] \ } } t |  | | ƒ q Wt ƒ  |  _ t j j } | j d  k	 rˆ |  j	 rp t j
 d d ƒ n  | j |  _ |  | _ n  d  S(   Ns   Replacing request.handlers   TOOLS.ENCODE(   t   itemst   setattrt   sett   attempted_charsetsR   t   servingR   t   handlerR
   t   debugt   logt
   oldhandler(   R   t   kwargst   kt   vR   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyR   I   s    	c            sK   ˆ  ˆ j  k r t Sˆ j  j ˆ  ƒ ‡  ‡ f d †  } | ˆ j ƒ ˆ _ t S(   s   Encode a streaming response body.

        Use a generator wrapper, and just pray it works as the stream is
        being written out.
        c         3   sA   x: |  D]2 } t  | t ƒ r4 | j ˆ  ˆ j ƒ } n  | Vq Wd  S(   N(   R   R   R   t   errors(   R	   t   chunk(   R   R   (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   encoder`   s    (   R)   t   Falset   addR	   t   True(   R   R   R4   (    (   R   R   s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   encode_streamV   s    c         C   s   | |  j  k r t S|  j  j | ƒ g  } xd |  j D]Y } t | t ƒ r y | j | |  j ƒ } Wq t t	 f k
 r{ t SXn  | j
 | ƒ q3 W| |  _ t S(   s    Encode a buffered response body.(   R)   R5   R6   R	   R   R   R   R2   t   LookupErrort   UnicodeErrort   appendR7   (   R   R   R	   R3   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   encode_stringh   s    	c         C   s$  t  j j } t  j j } |  j r; t  j d | j d ƒ n  | j rP |  j } n% |  j } d | j	 k ru | j	 d =n  | j	 j
 d ƒ } g  | D] } | j j ƒ  ^ qŽ } |  j rÏ t  j d t | ƒ d ƒ n  |  j d  k	 rb|  j j ƒ  } |  j rt  j d | d ƒ n  | s,d | k s,| | k r´|  j rLt  j d | d ƒ n  | | ƒ r_| Sq´nR| sÀ|  j r‹t  j d	 |  j d ƒ n  | |  j ƒ r¡|  j St  j d
 |  j |  j ƒ ‚ nô x¡ | D]™ } | j d k rÇ| j d k r$|  j rt  j d | d ƒ n  | |  j ƒ r]|  j Sq`| j } |  j rMt  j d | d ƒ n  | | ƒ r`| SqÇqÇWd | k r´d }	 |	 | k r´|  j ržt  j d d ƒ n  | |	 ƒ r±|	 Sq´n  | j	 j d ƒ }
 |
 d  k rÛd } n
 d |
 } d j t |  j ƒ ƒ } | d | f 7} t  j d | ƒ ‚ d  S(   Ns   response.stream %rs   TOOLS.ENCODEs   Content-Lengths   Accept-Charsets   charsets %ss   Specified encoding %rt   *s   Attempting encoding %rs   Attempting default encoding %riô  i    s%   Attempting default encoding due to %rs"   Attempting encoding %s (qvalue >0)s
   iso-8859-1s   Attempting ISO-8859-1 encodings2   Your client did not send an Accept-Charset header.s0   Your client sent this Accept-Charset header: %s.s   , s    We tried these charsets: %s.i–  (   R   R*   R   t   responseR,   R-   t   streamR8   R<   t   headerst   elementst   valuet   lowert   reprR   R
   R   t	   HTTPErrort   failmsgt   qvaluet   gett   joint   sortedR)   (   R   R   R>   R4   t   encst   enct   charsetsR   t   elementt   isot   act   msgt	   _charsets(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   find_acceptable_charsetx   s|    				"					
				
					

	
c         O   sî  t  j j } |  j | | Ž  |  _ t |  j t ƒ rZ |  j rN |  j g |  _ qœ g  |  _ nB t |  j d ƒ r t |  j ƒ |  _ n |  j d  k rœ g  |  _ n  | j
 j d ƒ } |  j rç t  j d g  | D] } t | ƒ ^ qÇ d ƒ n  | rç|  j rç| d } |  j rs| j j ƒ  j d ƒ rJ|  j rAt  j d | d ƒ n  t } q•|  j rjt  j d | d ƒ n  t } n" |  j rt  j d	 d ƒ n  t } | rç|  j ƒ  | j d
 <|  j rÎt  j d | d ƒ n  t | ƒ | j
 d <qçn  |  j S(   Nt   reads   Content-Types   Content-Type: %rs   TOOLS.ENCODEi    s   text/s#   Content-Type %s starts with "text/"s?   Not finding because Content-Type %s does not start with "text/"s   Finding because not text_onlyt   charsets   Setting Content-Type %s(   R   R*   R>   R.   R	   R   R    t   hasattrR   R
   R@   RA   R,   R-   t   strt   add_charsett	   text_onlyRB   RC   R   R7   R5   RS   t   params(   R   t   argsR/   R>   t   ctt   ht   do_find(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   __call__×   sN    		$
		
			
			
	
N(   R"   R#   R   RF   R
   R   R2   R7   RY   RX   R5   R,   R   R8   R<   RS   R_   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyR$   ?   s   				_c         c   s9  d d l  } t d ƒ Vt d ƒ Vt d ƒ Vt j d t t j ƒ  ƒ t d d ƒ @ƒ Vt d	 ƒ Vt d
 ƒ V| j t d ƒ ƒ } d } | j | | j | j	 | j
 d ƒ } x> |  D]6 } | t | ƒ 7} | j | | ƒ } | j | ƒ Vq´ W| j ƒ  Vt j d | t d d ƒ @ƒ Vt j d | t d d ƒ @ƒ Vd S(   s,   Compress 'body' at the given compress_level.iÿÿÿÿNs   ‹s   t    s   <Lt   FFFFFFFFi   s   s   ÿt    i    (   t   zlibR   t   structt   packt   intt   timet   crc32t   compressobjt   DEFLATEDt	   MAX_WBITSt   DEF_MEM_LEVELt   lent   compresst   flush(   R	   t   compress_levelRc   t   crct   sizet   zobjt   line(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyRn     s&    *	c         C   sa   d d  l  } t ƒ  } | j |  ƒ | j d ƒ | j d d d | ƒ } | j ƒ  } | j ƒ  | S(   Niÿÿÿÿi    t   modet   rbt   fileobj(   t   gzipR   t   writet   seekt   GzipFileRT   R   (   R	   Rx   t   zbuft   zfilet   data(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt
   decompress-  s    	
i   s	   text/htmls
   text/plainc         C   s-  t  j j } t  j j } t | d ƒ | j sN | rJ t  j d d d ƒn  d St | d t ƒ r€ | r| t  j d d d ƒn  d S| j	 j
 d ƒ } | s¸ | r´ t  j d d d ƒn  d S| j	 j d	 d
 ƒ j d ƒ d } x| D]} | j d k r)| j d k r)| r%t  j d | d d ƒn  d S| j d k rá | j d k rk| rgt  j d | d d ƒn  d S| | k r•t } d | k rb| j d ƒ \ }	 }
 xÁ | D]¶ } d | k r¥| j d ƒ \ } } |	 | k r[| d k rît } PqXd | k rXd |
 k rX|
 j d ƒ \ } } | j d ƒ \ } } | d k rU| | k rUt } PqUqXq[q¥q¥Wn  | s•| rŽt  j d | | f d d ƒn  d Sn  | r±t  j d d d ƒn  d | j	 d <t | j |  ƒ | _ d | j	 k rï| j	 d =n  d Sqá W| rt  j d d d ƒn  t  j d d ƒ j ƒ  d S(   s“  Try to gzip the response body if Content-Type in mime_types.

    cherrypy.response.headers['Content-Type'] must be set to one of the
    values in the mime_types arg before calling this function.

    The provided list of mime-types must be of one of the following form:
        * type/subtype
        * type/*
        * type/*+subtype

    No compression is performed if any of the following hold:
        * The client sends no Accept-Encoding request header
        * No 'gzip' or 'x-gzip' is present in the Accept-Encoding header
        * No 'gzip' or 'x-gzip' with a qvalue > 0 is present
        * The 'identity' value is given with a qvalue > 0.

    s   Accept-Encodings   No response bodyt   contexts
   TOOLS.GZIPNt   cacheds   Not gzipping cached responses   No Accept-Encodings   Content-TypeRb   t   ;i    t   identitys   Non-zero identity qvalue: %sRx   s   x-gzips   Zero gzip qvalue: %st   /R=   t   +s$   Content-Type %s not in mime_types %rt   Gzippings   Content-Encodings   Content-Lengths   No acceptable encoding found.t   GZIPi–  s   identity, gzip(   s   gzips   x-gzip(   R   R*   R   R>   R   R	   R-   R   R5   R@   RA   RH   t   splitRB   RG   R7   Rn   RE   t   set_response(   Rp   t
   mime_typesR,   R   R>   t
   acceptableR\   t   codingt   foundt   ct_media_typet   ct_sub_typet	   mime_typet
   media_typet   sub_typet   ct_leftt   ct_rightt   leftt   right(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyRx   9  sz    	"

	(    (    (   Rd   Rg   R   t   cherrypy._cpcompatR    R   R   R   t   cherrypy.libR   R   R   R
   R   R   R$   Rn   R   R5   Rx   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/encoding.pyt   <module>   s   "Ð		