ó
Xé?_c           @   s\  d  d l  Z  d  d l Z d  d l Z d  d l Z y d  d l m Z Wn e k
 r` e ƒ  Z n Xd  d l Z d  d l	 m
 Z
 m Z d  d l m Z m Z m Z e j ƒ  d e j d <d e j d <d	 e j d
 <d e j d <d d d e d „ Z d d d e d „ Z e d „ Z d d „ Z e d „ Z d d d d e d „ Z d d d e d „ Z d S(   iÿÿÿÿN(   t   UnsupportedOperation(   t   ntobt   unquote(   t   cptoolst   httputilt   file_generator_limiteds   image/x-dwgs   .dwgs   image/x-icons   .icos   application/x-bzip2s   .bz2s   application/x-gzips   .gzc         C   s9  t  j j } t j j |  ƒ sP d |  } | rA t  j | d ƒ n  t | ƒ ‚ n  y t j |  ƒ } WnC t	 t
 t f k
 r¨ | r™ t  j d |  d ƒ n  t  j ƒ  ‚ n Xt j | j ƒ rç | rØ t  j d |  d ƒ n  t  j ƒ  ‚ n  t j | j ƒ | j d <t j ƒ  | d k rbd } |  j d ƒ }	 |	 d	 k rJ|  |	 j ƒ  } n  t j j | d ƒ } n  | d k	 r~| | j d
 <n  | r›t  j d | d ƒ n  d }
 | d k	 rî| d k rÎt j j |  ƒ } n  d | | f }
 |
 | j d <n  | rt  j d |
 d ƒ n  | j } t |  d ƒ } t | | | d | ƒS(   sø  Set status, headers, and body in order to serve the given path.

    The Content-Type header will be set to the content_type arg, if provided.
    If not provided, the Content-Type will be guessed by the file extension
    of the 'path' argument.

    If disposition is not None, the Content-Disposition header will be set
    to "<disposition>; filename=<name>". If name is None, it will be set
    to the basename of path. If disposition is None, no Content-Disposition
    header will be written.
    s   '%s' is not an absolute path.s   TOOLS.STATICFILEs   os.stat(%r) faileds   TOOLS.STATICs   %r is a directorys   Last-Modifiedt    t   .iÿÿÿÿs   Content-Types   Content-Type: %rs   %s; filename="%s"s   Content-Dispositions   Content-Disposition: %rt   rbt   debugN(   t   cherrypyt   servingt   responset   ost   patht   isabst   logt
   ValueErrort   statt   OSErrort	   TypeErrort   NotFoundt   S_ISDIRt   st_modeR   t   HTTPDatet   st_mtimet   headersR   t   validate_sincet   Nonet   rfindt   lowert	   mimetypest	   types_mapt   gett   basenamet   st_sizet   opent   _serve_fileobj(   R   t   content_typet   dispositiont   nameR	   R   t   msgt   stt   extt   it   cdt   content_lengtht   fileobj(    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt
   serve_file   sN    

	c   	      C   sM  t  j j } y t j |  j ƒ  ƒ } WnF t k
 rW | rN t  j d d ƒ n  d
 } nC t	 k
 rm d
 } n- Xt
 j | j ƒ | j d <t j ƒ  | j } | d
 k	 r¶ | | j d <n  | rÓ t  j d | d ƒ n  d
 } | d
 k	 r| d
 k rú | } n d | | f } | | j d <n  | r7t  j d | d ƒ n  t |  | | d	 | ƒS(   s  Set status, headers, and body in order to serve the given file object.

    The Content-Type header will be set to the content_type arg, if provided.

    If disposition is not None, the Content-Disposition header will be set
    to "<disposition>; filename=<name>". If name is None, 'filename' will
    not be set. If disposition is None, no Content-Disposition header will
    be written.

    CAUTION: If the request contains a 'Range' header, one or more seek()s will
    be performed on the file object.  This may cause undesired behavior if
    the file object is not seekable.  It could also produce undesired results
    if the caller set the read position of the file object prior to calling
    serve_fileobj(), expecting that the data would be served starting from that
    position.
    s   os has no fstat attributes   TOOLS.STATICs   Last-Modifieds   Content-Types   Content-Type: %rs   %s; filename="%s"s   Content-Dispositions   Content-Disposition: %rR	   N(   R
   R   R   R   t   fstatt   filenot   AttributeErrorR   R   R    R   R   R   R   R   R   R#   R%   (	   R/   R&   R'   R(   R	   R   R*   R.   R-   (    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt   serve_fileobjd   s2    	

		c            sJ  t  j j } t  j j } | j d k r-d | j d <t j | j j d ƒ ˆ ƒ ‰ ˆ g  k r£ d ˆ | j d <d } ˆ rŽ t  j	 | d ƒ n  t  j
 d	 | ƒ ‚ n  ˆ rt ˆ ƒ d k rcˆ d
 \ } } | ˆ k rà ˆ } n  | | }	 ˆ rt  j	 d | | f d ƒ n  d | _ d | | d ˆ f | j d <|	 | j d <ˆ j | ƒ t ˆ |	 ƒ | _ n§ d | _ y d d l m }
 Wn! t k
 r£d d l m }
 n X|
 ƒ  ‰  d ˆ  } | | j d <d | j k rà| j d =n  ‡  ‡ ‡ ‡ ‡ ‡ f d †  } | ƒ  | _ | j Sˆ r-t  j	 d d ƒ q-n  ˆ | j d <ˆ | _ | j S(   sE   Internal. Set response.body to the given file object, perhaps ranged.i   t   bytess   Accept-Rangest   Ranges
   bytes */%ss   Content-Ranges:   Invalid Range (first-byte-pos greater than Content-Length)s   TOOLS.STATICi   i    s    Single part; start: %r, stop: %rs   206 Partial Contents   bytes %s-%s/%ss   Content-Lengthiÿÿÿÿ(   t   _make_boundary(   t   choose_boundarys!   multipart/byteranges; boundary=%ss   Content-Typec          3   sî   t  d ƒ Vx» ˆ D]³ \ }  } ˆ rA t j d |  | f d ƒ n  t  d ˆ  d ƒ Vt  d ˆ d ƒ Vt  d |  | d ˆ f d ƒ Vˆ j |  ƒ t ˆ | |  ƒ } x | D] } | Vq« Wt  d ƒ Vq Wt  d ˆ  d d ƒ Vt  d ƒ Vd  S(	   Ns   
s   Multipart; start: %r, stop: %rs   TOOLS.STATICs   --t   asciis   
Content-type: %ss#   
Content-range: bytes %s-%s/%s

i   (   R   R
   R   t   seekR   (   t   startt   stopt   gent   chunk(   t   boundaryR.   R&   R	   R/   t   r(    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt   file_rangesÌ   s*    


	s   No byteranges requested(   i   i   (   R
   R   R   t   requestt   protocolR   R   t
   get_rangesR!   R   t	   HTTPErrort   lent   statusR:   R   t   bodyt   email.generatorR7   t   ImportErrort	   mimetoolsR8   (   R/   R&   R.   R	   R   RB   t   messageR;   R<   t   r_lent   make_boundaryt   ctRA   (    (   R?   R.   R&   R	   R/   R@   sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyR%   š   sX    	

			
	c         C   s   t  |  d d | ƒ S(   s5   Serve 'path' as an application/x-download attachment.s   application/x-downloadt
   attachment(   R0   (   R   R(   (    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt   serve_downloadô   s    c         C   s³   | r# t  j d |  | f d ƒ n  y[ d  } | rc t j j |  ƒ \ } } | j | d d  ƒ } n  t |  d | d | ƒt SWn. t  j	 k
 r® | rª t  j d d ƒ n  t
 SXd  S(   Ns    Attempting %r (content_types %r)s   TOOLS.STATICDIRi   R&   R	   R   s   TOOLS.STATICFILE(   R
   R   R   R   R   t   splitextR!   R0   t   TrueR   t   False(   t   filenamet   content_typesR	   R&   R@   R+   (    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt   _attemptú   s    	R   c         C   s  t  j j } | j d k r8 | r4 t  j d d ƒ n  t S| r~ t j | | j ƒ r~ | rz t  j d | j | f d ƒ n  t St	 j
 j | ƒ } t	 j
 j | ƒ sî | sÖ d } | rÇ t  j | d ƒ n  t | ƒ ‚ n  t	 j
 j | | ƒ } n  |  d k rd }  n  |  j d	 ƒ }  | j t |  ƒ d
 }	 t |	 j d	 ƒ ƒ }	 t	 j
 j | |	 ƒ }
 | ryt  j d |
 | j f d ƒ n  t	 j
 j |
 ƒ j t	 j
 j | ƒ ƒ s²t  j d ƒ ‚ n  t |
 | ƒ } | s| rt t	 j
 j |
 | ƒ | ƒ } | r
|
 d d	 k | _ q
qn  | S(   s  Serve a static resource from the given (root +) dir.

    match
        If given, request.path_info will be searched for the given
        regular expression before attempting to serve static content.

    content_types
        If given, it should be a Python dictionary of
        {file-extension: content-type} pairs, where 'file-extension' is
        a string (e.g. "gif") and 'content-type' is the value to write
        out in the Content-Type response header (e.g. "image/gif").

    index
        If provided, it should be the (relative) name of a file to
        serve for directory requests. For example, if the dir argument is
        '/home/me', the Request-URI is 'myapp', and the index arg is
        'index.html', the file '/home/me/myapp/index.html' will be sought.
    t   GETt   HEADs   request.method not GET or HEADs   TOOLS.STATICDIRs.   request.path_info %r does not match pattern %rs.   Static dir requires an absolute dir (or root).t   globalt   /s   \/i   s   Checking file %r to fulfill %ri“  iÿÿÿÿ(   s   GETs   HEAD(   R
   R   RB   t   methodR   RT   t   ret   searcht	   path_infoR   R   t
   expanduserR   R   t   joint   rstripRF   R   t   lstript   normpatht
   startswithRE   RW   t   is_index(   t   sectiont   dirt   roott   matchRV   t   indexR	   RB   R)   t   branchRU   t   handled(    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt	   staticdir  sH    			'c         C   sö   t  j j } | j d k r8 | r4 t  j d d ƒ n  t S| r~ t j | | j ƒ r~ | rz t  j d | j | f d ƒ n  t St	 j
 j |  ƒ sã | sË d |  f } | r¼ t  j | d ƒ n  t | ƒ ‚ n  t	 j
 j | |  ƒ }  n  t |  | d | ƒS(	   sï  Serve a static resource from the given (root +) filename.

    match
        If given, request.path_info will be searched for the given
        regular expression before attempting to serve static content.

    content_types
        If given, it should be a Python dictionary of
        {file-extension: content-type} pairs, where 'file-extension' is
        a string (e.g. "gif") and 'content-type' is the value to write
        out in the Content-Type response header (e.g. "image/gif").

    RX   RY   s   request.method not GET or HEADs   TOOLS.STATICFILEs.   request.path_info %r does not match pattern %rs5   Static tool requires an absolute filename (got '%s').R	   (   s   GETs   HEAD(   R
   R   RB   R\   R   RT   R]   R^   R_   R   R   R   R   Ra   RW   (   RU   Ri   Rj   RV   R	   RB   R)   (    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt
   staticfileY  s&    	
(   R   R]   R   R   t   ioR    RJ   t   objectR
   t   cherrypy._cpcompatR   R   t   cherrypy.libR   R   R   t   initR    R   RT   R0   R4   R%   RQ   RW   Rn   Ro   (    (    (    sz   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/static.pyt   <module>   s2   
	L	5ZI