ó
Xé?_c           @   s  d  Z  d d l Z d d l Z d d l m Z m Z m Z m	 Z	 m
 Z
 m Z d d l m Z d d l m Z d d l m Z d „  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s„  WSGI interface (see PEP 333 and 3333).

Note that WSGI environ keys and values are 'native strings'; that is,
whatever the type of "" is. For Python 2, that's a byte string; for Python 3,
it's a unicode string. But PEP 3333 says: "even if Python's str type is
actually Unicode "under the hood", the content of native strings must
still be translatable to bytes via the Latin-1 encoding!"
iÿÿÿÿN(   t   BytesIOt   bytestrt   ntobt   ntout   py3kt
   unicodestr(   t   _cperror(   t   httputil(   t   is_closable_iteratorc         C   sª   i  } |  t  d ƒ } x t |  j ƒ  ƒ D]y \ } } | t  d ƒ t  d ƒ t  d ƒ g k rn | j | ƒ } n! t | t ƒ r | j d ƒ } n  | | | j d ƒ <q) W| S(   sL   Return a new environ dict for WSGI 1.x from the given WSGI u.x environ.
    s   wsgi.url_encodingt	   PATH_INFOt   SCRIPT_NAMEt   QUERY_STRINGs
   ISO-8859-1(   R   t   listt   itemst   encodet
   isinstanceR   (   t   environt   env1xt   url_encodingt   kt   v(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   downgrade_wsgi_ux_to_1x   s    't   VirtualHostc           B   s8   e  Z d  Z d Z e Z i  Z d e d „ Z d „  Z	 RS(   si  Select a different WSGI application based on the Host header.

    This can be useful when running multiple sites within one CP server.
    It allows several domains to point to different applications. For example::

        root = Root()
        RootApp = cherrypy.Application(root)
        Domain2App = cherrypy.Application(root)
        SecureApp = cherrypy.Application(Secure())

        vhost = cherrypy._cpwsgi.VirtualHost(RootApp,
            domains={'www.domain2.example': Domain2App,
                     'www.domain2.example:443': SecureApp,
                     })

        cherrypy.tree.graft(vhost)
    c         C   s%   | |  _  | p i  |  _ | |  _ d  S(   N(   t   defaultt   domainst   use_x_forwarded_host(   t   selfR   R   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   __init__F   s    	c         C   sg   | j  d d ƒ } |  j r0 | j  d | ƒ } n  |  j j  | ƒ } | d  k rZ |  j } n  | | | ƒ S(   Nt	   HTTP_HOSTt    t   HTTP_X_FORWARDED_HOST(   t   getR   R   t   NoneR   (   R   R   t   start_responset   domaint   nextapp(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   __call__K   s    	N(
   t   __name__t
   __module__t   __doc__R    R   t   TrueR   R   R   R$   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR   "   s   	t   InternalRedirectorc           B   s#   e  Z d  Z e d „ Z d „  Z RS(   s>   WSGI middleware that handles raised cherrypy.InternalRedirect.c         C   s   | |  _  | |  _ d  S(   N(   R#   t	   recursive(   R   R#   R*   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR   Z   s    	c   
      C   sl  g  } x_t  rg| j ƒ  } y |  j | | ƒ SWq	 t j k
 rct j ƒ  d } | j d d ƒ } | j d d ƒ } | j d d ƒ } | | } | r© | d | 7} n  | j | ƒ |  j	 s| | j
 }	 | j ré |	 d | j 7}	 n  |	 | k r| j j ƒ  t d |	 ƒ ‚ qn  d | d	 <| j
 | d <| j | d <t ƒ  | d
 <d | d <| j | d <q	 Xq	 Wd  S(   Ni   R
   R   R	   R   t   ?s1   InternalRedirector visited the same URL twice: %rt   GETt   REQUEST_METHODs
   wsgi.inputt   0t   CONTENT_LENGTHs   cherrypy.previous_request(   R(   t   copyR#   t	   _cherrypyt   InternalRedirectt   _syst   exc_infoR   t   appendR*   t   patht   query_stringt   requestt   closet   RuntimeErrorR    (
   R   R   R!   t   redirectionst   irt   snR6   t   qst   old_urit   new_uri(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR$   ^   s8    	
		

(   R%   R&   R'   t   FalseR   R$   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR)   V   s   t   ExceptionTrapperc           B   s)   e  Z d  Z e e f d „ Z d „  Z RS(   s&   WSGI middleware that traps exceptions.c         C   s   | |  _  | |  _ d  S(   N(   R#   t   throws(   R   R#   RC   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR   ˆ   s    	c         C   s   t  |  j | | |  j ƒ S(   N(   t   _TrappedResponseR#   RC   (   R   R   R!   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR$   Œ   s
    (   R%   R&   R'   t   KeyboardInterruptt
   SystemExitR   R$   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRB   „   s   RD   c           B   sS   e  Z e g  ƒ Z d  „  Z d „  Z e r6 d „  Z n	 d „  Z d „  Z	 d „  Z
 RS(   c         C   sd   | |  _  | |  _ | |  _ | |  _ t |  _ |  j |  j  |  j |  j ƒ |  _ t |  j ƒ |  _	 d  S(   N(
   R#   R   R!   RC   RA   t   started_responset   trapt   responset   itert   iter_response(   R   R#   R   R!   RC   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR   ™   s    					c         C   s   t  |  _ |  S(   N(   R(   RG   (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   __iter__£   s    	c         C   s   |  j  t |  j ƒ S(   N(   RH   t   nextRK   (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   __next__¨   s    c         C   s   |  j  |  j j ƒ S(   N(   RH   RK   RM   (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRM   «   s    c         C   s&   t  |  j d ƒ r" |  j j ƒ  n  d  S(   NR9   (   t   hasattrRI   R9   (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR9   ®   s    c   
      O   sm  y | | | Ž  SWnU|  j  k
 r* ‚  n?t k
 r= ‚  n,t j ƒ  } t j | d d ƒt j j st d } n  t j | ƒ \ } } } t	 rÛ | j
 d ƒ } g  | D]* \ } }	 | j
 d ƒ |	 j
 d ƒ f ^ q¨ } n  |  j rö t g  ƒ |  _ n t | ƒ |  _ y |  j | | t j ƒ  ƒ Wn  t j d t d d ƒ ‚  n X|  j rat d ƒ j | ƒ S| Sn Xd  S(   Nt   severityi(   R   s
   ISO-8859-1t	   traceback(   RC   t   StopIterationR   t
   format_excR1   t   logR8   t   show_tracebackst
   bare_errorR   t   decodeRG   RJ   RK   R!   R3   R4   R(   R   t   join(
   R   t   funct   argst   kwargst   tbt   st   ht   bR   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRH   ²   s6    	7		(   R%   R&   RJ   RI   R   RL   R   RN   RM   R9   RH   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRD   •   s   	
			t   AppResponsec           B   s   e  Z d  Z d „  Z d „  Z e r0 d „  Z n	 d „  Z d „  Z d „  Z	 i d d 6d	 d
 6d d 6d d 6d d 6Z
 d „  Z RS(   s1   WSGI response iterable for CherryPy applications.c   	      C   s—  | |  _  yst sK | j t d ƒ ƒ t d ƒ d f k rK t | ƒ } qK n  | |  _ |  j ƒ  t j j	 } | j
 } t | t ƒ s‘ t d ƒ ‚ n  g  } xn | j D]c \ } } t | t ƒ sÏ t d | ƒ ‚ n  t | t ƒ sñ t d | ƒ ‚ n  | j | | f ƒ q¡ Wt rW| j d ƒ } g  | D]* \ } } | j d ƒ | j d ƒ f ^ q$} n  t | j ƒ |  _ | | | ƒ |  _ Wn |  j ƒ  ‚  n Xd  S(   Ns   wsgi.versiont   ui    s,   response.output_status is not a byte string.s1   response.header_list key %r is not a byte string.s3   response.header_list value %r is not a byte string.s
   ISO-8859-1(   t   cpappR   R   R   R   R   t   runR1   t   servingRI   t   output_statusR   R   t	   TypeErrort   header_listR5   RW   RJ   t   bodyRK   t   writeR9   (	   R   R   R!   Rb   t   rt	   outstatust
   outheadersR   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR   ã   s>    	'	
	7
c         C   s   |  S(   N(    (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRL     s    c         C   s   t  |  j ƒ S(   N(   RM   RK   (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRN     s    c         C   s   |  j  j ƒ  S(   N(   RK   RM   (   R   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRM     s    c         C   sy   t  j j j } |  j j ƒ  | ru t |  j ƒ ru |  j j } y | ƒ  Wqu t	 k
 rq t  j
 d t d d ƒ qu Xn  d S(   s?   Close and de-reference the current request and response. (Core)RQ   RP   i(   N(   R1   Rd   RI   t   streamRb   t   release_servingR   RK   R9   t	   ExceptionRT   R(   (   R   t	   streamingt
   iter_close(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR9     s    c         C   ss  |  j  j } t j d t | d d ƒ p* d ƒ | d d ƒ ƒ } t j | d d ƒ t | d d ƒ pf d ƒ | d d ƒ ƒ } | d	 ƒ } | d
 d ƒ } |  j j | | | | ƒ \ } } | d ƒ pÒ | d ƒ pÒ d | _ |  j  d | _	 |  j  d | _
 |  j  | _ | d d ƒ | _ |  j  d } t j |  j  j d d ƒ |  j  j d d ƒ ƒ }	 |  j  j d d ƒ }
 t r"|  j  j d d ƒ } |  j j |  j  j d d ƒ d d ƒ } | j ƒ  | j ƒ  k r"y4 |	 j | ƒ j | ƒ } |
 j | ƒ j | ƒ } Wn t t f k
 rqX| }	 | }
 q"n  |  j  j d ƒ } |  j |  j  ƒ } |  j  d } | j | |	 |
 | | | ƒ d S(   s&   Create a Request object using environ.R   t   SERVER_PORTiP   iÿÿÿÿt   SERVER_NAMEt   REMOTE_ADDRt   REMOTE_PORTt   REMOTE_HOSTs   wsgi.url_schemet   ACTUAL_SERVER_PROTOCOLs   HTTP/1.1t
   LOGON_USERt   REMOTE_USERs   wsgi.multithreads   wsgi.multiprocesss   cherrypy.previous_requestR-   R
   R	   R   s   wsgi.url_encodings
   ISO-8859-1s   request.uri_encodings   utf-8t   SERVER_PROTOCOLs
   wsgi.inputN(   R   R   R   t   Hostt   intRb   t   get_servingR    t   logint   multithreadt   multiprocesst   wsgi_environt   prevt   urljoinR   t   find_configt   lowerR   RW   t   UnicodeEncodeErrort   UnicodeDecodeErrort   translate_headersRc   (   R   t   envt   localt   remotet   schemet   sprotoR8   t   respt   methR6   R>   t   old_enct   new_enct   u_patht   u_qst   rprotot   headerst   rfile(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRc   '  sF    	!!t   Authorizationt   HTTP_CGI_AUTHORIZATIONs   Content-LengthR/   s   Content-Typet   CONTENT_TYPEs   Remote-HostRv   s   Remote-AddrRt   c         c   su   xn | D]f } | |  j  k r5 |  j  | | | f Vq | d  d k r | d j d d ƒ } | | | f Vq q Wd S(   s8   Translate CGI-environ header names to HTTP header names.i   t   HTTP_t   _t   -N(   t   headerNamest   replace(   R   R   t   cgiNamet   translatedHeader(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyRˆ   g  s    (   R%   R&   R'   R   RL   R   RN   RM   R9   Rc   R   Rˆ   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR`   ß   s   	*				9

t	   CPWSGIAppc           B   s_   e  Z d  Z d e f d e f g Z d Z i  Z e	 Z
 d d „ Z d „  Z d „  Z d „  Z RS(   s5   A WSGI application object for a CherryPy Application.RB   R)   c         C   sE   | |  _  |  j |  _ | r/ |  j j | ƒ n  |  j j ƒ  |  _ d  S(   N(   Rb   t   pipelinet   extendt   configR0   (   R   Rb   R¢   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR   Ž  s
    	c         C   s   |  j  | | |  j ƒ S(   sÒ   WSGI application callable for the actual CherryPy application.

        You probably shouldn't call this; call self.__call__ instead,
        so that any WSGI middleware in self.pipeline can run first.
        (   t   response_classRb   (   R   R   R!   (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   tail•  s    c         C   s‚   |  j  } | d  k ru |  j } xH |  j d  d  d … D]0 \ } } |  j j | i  ƒ } | | |  } q5 W| |  _  n  | | | ƒ S(   Niÿÿÿÿ(   t   headR    R¦   R¢   R¤   R   (   R   R   R!   R§   t   namet   callablet   conf(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR$     s    		#c         C   sr   | d k r |  j  j | ƒ nO | d k r7 | |  _ n7 | j d d ƒ \ } } |  j j | i  ƒ } | | | <d S(   s(   Config handler for the 'wsgi' namespace.R¢   R¥   t   .i   N(   R¢   R£   R¥   t   splitR¤   t
   setdefault(   R   R   R   R¨   t   argt   bucket(    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   namespace_handler©  s    N(   R%   R&   R'   RB   R)   R¢   R    R§   R¤   R`   R¥   R   R¦   R$   R°   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyR¡   s  s   			(   R'   t   sysR3   t   cherrypyR1   t   cherrypy._cpcompatR    R   R   R   R   R   R   t   cherrypy.libR   R   R   t   objectR   R)   RB   RD   R`   R¡   (    (    (    sw   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/_cpwsgi.pyt   <module>   s   .	4.J”