
    "d"                         d dl Zd dlZd dlZd dlZd dlmZ d dlZd dlm	Z	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZmZ ej        edf         Z G d d	e          Z G d
 d          ZdS )    N)	parsedate)URLHeaders)HTTPException)FileResponseRedirectResponseResponse)ReceiveScopeSendzos.PathLike[str]c                   (     e Zd ZdZdef fdZ xZS )NotModifiedResponse)zcache-controlzcontent-locationdateetagexpiresvaryheadersc                      t                                          d fd|                                D                        d S )Ni0  c                 .    i | ]\  }}|j         v ||S  )NOT_MODIFIED_HEADERS).0namevalueselfs      9D:\api_v1\venv\Lib\site-packages\starlette/staticfiles.py
<dictcomp>z0NotModifiedResponse.__init__.<locals>.<dictcomp>   s7       D%4444 e444    )status_coder   )super__init__items)r   r   	__class__s   ` r   r!   zNotModifiedResponse.__init__   s`       #*==??   	 	
 	
 	
 	
 	
r   )__name__
__module____qualname__r   r   r!   __classcell__)r#   s   @r   r   r      sL        
 
 
 
 
 
 
 
 
 
 
r   r   c                   $   e Zd Zdddddddej        e         dej        ej        ej        eej	        eef         f                           de
de
d	e
d
dfdZ	 	 ddej        e         dej        ej        ej        eej	        eef         f                           d
ej        e         fdZdededed
dfdZded
efdZdeded
efdZded
ej	        eej        ej                 f         fdZ	 ddedej        deded
ef
dZd dZdeded
e
fdZdS )!StaticFilesNFT)	directorypackageshtml	check_dirfollow_symlinkr*   r+   r,   r-   r.   returnc                    || _         || _        |                     ||          | _        || _        d| _        || _        |r4|4t          j        	                    |          st          d| d          d S d S d S )NFDirectory 'z' does not exist)r*   r+   get_directoriesall_directoriesr,   config_checkedr.   ospathisdirRuntimeError)r   r*   r+   r,   r-   r.   s         r   r!   zStaticFiles.__init__'   s     # #33IxHH	#, 	J.rw}}Y7O7O.HYHHHIII	J 	J....r   c                    g }||                     |           |pg D ]}t          |t                    r|\  }}nd}t          j                            |          }|J d|d            |j        J d|d            t          j        	                    t          j        
                    |j        d|                    }t          j                            |          sJ d|d|d            |                     |           |S )z
        Given `directory` and `packages` arguments, return a list of all the
        directories that should be used for serving static files from.
        NstaticszPackage z could not be found.z..r1   z' in package )append
isinstancetuple	importlibutil	find_specoriginr5   r6   normpathjoinr7   )r   r*   r+   directoriespackagestatics_dirspecpackage_directorys           r   r2   zStaticFiles.get_directories;   sK     y)))~2 	2 	2G'5)) ('.$'>++G44D##%O%O%O%O###;**,Vw,V,V,V*** " 0 0T[$<<! ! 7==!  Y YX[XXXXXY Y Y 01111r   scopereceivesendc                    K   |d         dk    sJ | j         s!|                                  d{V  d| _         |                     |          }|                     ||           d{V } ||||           d{V  dS )z'
        The ASGI entry point.
        typehttpNT)r4   check_configget_pathget_response)r   rI   rJ   rK   r6   responses         r   __call__zStaticFiles.__call__\   s       V}&&&&" 	'##%%%%%%%%%"&D}}U##**477777777hugt,,,,,,,,,,,r   c                     t           j                            t          j        j        |d                             d                     S )z
        Given the ASGI scope, return the `path` string to serve up,
        with OS specific path separators, and any '..', '.' components removed.
        r6   /)r5   r6   rB   rC   split)r   rI   s     r   rP   zStaticFiles.get_pathj   s5    
 weFm.A.A#.F.F GHHHr   r6   c                 6  K   |d         dvrt          d          	 t          j                            | j        |           d{V \  }}n(# t
          $ r t          d          t          $ r  w xY w|r0t          j        |j	                  r| 
                    |||          S |rt          j        |j	                  r| j        rt          j                            |d          }t          j                            | j        |           d{V \  }}|t          j        |j	                  rp|d                             d	          s>t#          |
          }|                    |j        d	z             }t'          |          S | 
                    |||          S | j        rbt          j                            | j        d           d{V \  }}|r2t          j        |j	                  rt)          |||d         d          S t          d          )z`
        Returns an HTTP response, given the incoming path, method and request headers.
        method)GETHEADi  )r   Ni  z
index.htmlr6   rU   rI   )r6   )urlz404.htmli  )stat_resultrX   r   )r   anyio	to_threadrun_synclookup_pathPermissionErrorOSErrorstatS_ISREGst_modefile_responseS_ISDIRr,   r5   r6   rC   endswithr   replacer   r   )r   r6   rI   	full_pathr]   
index_pathr\   s          r   rQ   zStaticFiles.get_responseq   s      ?/11C0000	+0?+C+C $, , & & & & & &"I{{  	1 	1 	1C0000 	 	 		  	I4<(;<< 	I%%ieDDD 	IT\+*=>> 	I49 	I dL99J+0?+C+C *, , & & & & & &"I{ &4<8K+L+L&V}--c22 5E***C++38c>+::C+4444)))[%HHH9 	+0?+C+C *, , & & & & & &"I{  t|K,?@@ # + ? #	    ,,,,s   .A %A2c                    | j         D ]}t          j                            ||          }| j        r t          j                            |          }nt          j                            |          }t          j                            |          }t          j                            ||g          |k    r	 |t          j        |          fc S # t          t          f$ r Y w xY wdS )N) N)r3   r5   r6   rC   r.   abspathrealpathcommonprefixrd   FileNotFoundErrorNotADirectoryError)r   r6   r*   joined_pathrk   s        r   ra   zStaticFiles.lookup_path   s     - 	 	I',,y$77K" :GOOK88		G,,[99	((33Iw##Y	$:;;yHH  "')"4"44444%'9:   xs   6CC"!C"   rk   r]   r   c                     |d         }t          |          }t          ||||          }|                     |j        |          rt	          |j                  S |S )NrX   r[   )r   r]   rX   )r   r   is_not_modifiedr   r   )r   rk   r]   rI   r   rX   request_headersrR   s           r   rg   zStaticFiles.file_response   sn     x!...;KPV
 
 
  0/BB 	9&x'7888r   c                 n  K   | j         dS 	 t          j                            t          j        | j                    d{V }n&# t          $ r t          d| j          d          w xY wt          j        |j	                  s1t          j
        |j	                  st          d| j          d          dS dS )z
        Perform a one-off configuration check that StaticFiles is actually
        pointed at a directory, so that we can raise loud errors rather than
        just returning 404 responses.
        NzStaticFiles directory 'z' does not exist.zStaticFiles path 'z' is not a directory.)r*   r^   r_   r`   r5   rd   rr   r8   rh   rf   S_ISLNK)r   r]   s     r   rO   zStaticFiles.check_config   s       >!F	 % 8 8$. Q QQQQQQQKK  	 	 	K$.KKK  	 [011 	T\+BU5V5V 	JT^JJJ  	 	 	 	s   5A #A&response_headersrx   c                     	 |d         }|d         }||k    rdS n# t           $ r Y nw xY w	 t          |d                   }t          |d                   }|
|||k    rdS n# t           $ r Y nw xY wdS )z
        Given the request and response headers, return `True` if an HTTP
        "Not Modified" response could be returned instead.
        zif-none-matchr   Tzif-modified-sincezlast-modifiedNF)KeyErrorr   )r   r{   rx   if_none_matchr   if_modified_sincelast_modifieds          r   rw   zStaticFiles.is_not_modified   s    	+O<M#F+D$$t % 	 	 	D	
	 )/:M*N O O%&6&GHHM!-!-%66t 	 	 	D	 us    
((4A# #
A0/A0)NN)ru   )r/   N)r$   r%   r&   typingOptionalPathLikeListUnionstrTupleboolr!   r2   r   r
   r   rS   rP   r	   rQ   r5   r]   ra   intrg   rO   r   rw   r   r   r   r)   r)   &   s}        04 $J J J ?8,J /KS&,sCx*@%@AB
	J J J J 
J J J J, 04  ?8, /KS&,sCx*@%@AB
 
X	   B-E -G -4 -D - - - -Ie I I I I I/-s /-5 /-X /- /- /- /-b	c6?2>::	;   2   ^ 	
  
   "   ( ':A	     r   r)   )importlib.utilr>   r5   rd   r   email.utilsr   r^   starlette.datastructuresr   r   starlette.exceptionsr   starlette.responsesr   r   r	   starlette.typesr
   r   r   r   r   r   r   r)   r   r   r   <module>r      s%       				   ! ! ! ! ! !  1 1 1 1 1 1 1 1 . . . . . . H H H H H H H H H H 0 0 0 0 0 0 0 0 0 0<//0
 
 
 
 
( 
 
 
*P P P P P P P P P Pr   