
    df"                         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y)    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|j                         D ci c]  \  }}|| j                  v r|| c}}       y c c}}w )Ni0  )status_coder   )super__init__itemsNOT_MODIFIED_HEADERS)selfr   namevalue	__class__s       N/home/api-vastappli/venv/lib/python3.12/site-packages/starlette/staticfiles.pyr   zNotModifiedResponse.__init__   sQ     $+==?D%4444 e 	 	
s   A)__name__
__module____qualname__r   r   r   __classcell__)r   s   @r   r   r      s    
 
 
    r   c                   j   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y) StaticFilesNFT)	directorypackageshtml	check_dirfollow_symlinkr&   r'   r(   r)   r*   returnc                    || _         || _        | j                  ||      | _        || _        d| _        || _        |r2|/t        j                  j                  |      st        d| d      y y y )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__'   su     # #33IxH	#,.rww}}Y7OYK7GHII 8P.9r#   c                    g }||j                  |       |xs g D ]  }t        |t              r|\  }}nd}t        j                  j                  |      }|J d|d       |j                  J d|d       t        j                  j                  t        j                  j                  |j                  d|            }t        j                  j                  |      sJ d|d|d       |j                  |        |S )z
        Given `directory` and `packages` arguments, return a list of all the
        directories that should be used for serving static files from.
        staticszPackage z could not be found.z..r-   z' in package )append
isinstancetuple	importlibutil	find_specoriginr1   r2   normpathjoinr3   )r   r&   r'   directoriespackagestatics_dirspecpackage_directorys           r   r.   zStaticFiles.get_directories;   s     y)~2 	2G'5)'.$'>>++G4D#Ox{:N%OO;;*VhwkAU,VV " 0 0T[[$<! 77==! Y[O=CWXY 01	2  r#   scopereceivesendc                    K   |d   dk(  sJ | j                   s| j                          d{    d| _         | j                  |      }| j                  ||       d{   } ||||       d{    y7 I7 7 	w)z'
        The ASGI entry point.
        typehttpNT)r0   check_configget_pathget_response)r   rE   rF   rG   r2   responses         r   __call__zStaticFiles.__call__\   s~      V}&&""##%%%"&D}}U#**477ugt,,, & 8,s3   *A<A61A<A8A<0A:1A<8A<:A<c                     t         j                  j                  t        j                  j                  |d   j	                  d             S )z
        Given the ASGI scope, return the `path` string to serve up,
        with OS specific path separators, and any '..', '.' components removed.
        r2   /)r1   r2   r>   r?   split)r   rE   s     r   rL   zStaticFiles.get_pathj   s5    
 wweFm.A.A#.F GHHr#   r2   c                 Z  K   |d   dvrt        d      	 t        j                  j                  | j                  |       d{   \  }}|r2t        j                  |j                        r| j                  |||      S |rt        j                  |j                        r| j                  rt        j                  j                  |d      }t        j                  j                  | j                  |       d{   \  }}|}t        j                  |j                        r^|d   j!                  d	      s7t#        |
      }|j%                  |j                  d	z         }t'        |      S | j                  |||      S | j                  rht        j                  j                  | j                  d       d{   \  }}|r1t        j                  |j                        rt)        |||d   d      S t        d      7 # t
        $ r t        d      t        $ r  w xY w7 ,7 nw)z`
        Returns an HTTP response, given the incoming path, method and request headers.
        method)GETHEADi  )r   Ni  z
index.htmlr2   rQ   rE   )r2   )urlz404.htmli  )stat_resultrT   r   )r   anyio	to_threadrun_synclookup_pathPermissionErrorOSErrorstatS_ISREGst_modefile_responseS_ISDIRr(   r1   r2   r?   endswithr   replacer   r   )r   r2   rE   	full_pathrY   
index_pathrX   s          r   rM   zStaticFiles.get_responseq   s     ?/1C00	+0??+C+C  $, &"I{ 4<<(;(;<%%ieDDT\\+*=*=>499 dL9J+0??+C+C  *, &"I{ &4<<8K8K+LV}--c2E*C++388c>+:C+44)))[%HH99+0??+C+C  *, &"I{ t||K,?,?@# + ? #	  ,,O&  	1C00 		&&sO   H+-H HH B.H+:H&;B?H+:H);AH+H H##H+)H+c                    | j                   D ]  }t        j                  j                  ||      }| j                  r t        j                  j                  |      }nt        j                  j                  |      }t        j                  j                  |      }t        j                  j                  ||g      |k7  r	 |t        j                  |      fc S  y# t        t        f$ r Y w xY w)N) N)r/   r1   r2   r?   r*   abspathrealpath
commonpathr`   FileNotFoundErrorNotADirectoryError)r   r2   r&   joined_pathrg   s        r   r]   zStaticFiles.lookup_path   s     -- 	I'',,y$7K""GGOOK8	GG,,[9	((3Iww!!9i"89YF  "'')"444	  &'9: s    CC-,C-rg   rY   r   c                     |d   }t        |      }t        ||||      }| j                  |j                  |      rt	        |j                        S |S )NrT   rW   )r   rY   rT   )r   r   is_not_modifiedr   r   )r   rg   rY   rE   r   rT   request_headersrN   s           r   rc   zStaticFiles.file_response   sY     x!.;KPV
  0 0/B&x'7'788r#   c                   K   | j                   y	 t        j                  j                  t        j
                  | j                          d{   }t        j                  |j                        s9t        j                  |j                        st        d| j                    d      yy7 ]# t        $ r t        d| j                    d      w xY ww)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&   rZ   r[   r\   r1   r`   rn   r4   rd   rb   S_ISLNK)r   rY   s     r   rK   zStaticFiles.check_config   s      >>!	 % 8 8$.. QQK
 [001T\\+BUBU5V$T^^$44IJ  6W1 R  	)$..)99JK 	s/   C;B, B*B, AC*B, ,#CCresponse_headersrs   c                     	 |d   }|d   }||k(  ry	 	 t        |d         }t        |d         }||||k\  ryy# t         $ r Y 3w xY w# t         $ r Y yw xY w)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-modifiedF)KeyErrorr   )r   rv   rs   if_none_matchr   if_modified_sincelast_modifieds          r   rr   zStaticFiles.is_not_modified   s    	+O<M#F+D$ %

	 )/:M*N O%&6&GHM!-!-%6   		  		s    ; %A
 	AA
	AA)NN)   )r+   N)r   r    r!   typingOptionalPathLikeListUnionstrTupleboolr   r.   r   r
   r   rO   rL   r	   rM   r1   rY   r]   intrc   rK   r   rr    r#   r   r%   r%   &   s    04 $J ??8,J //KKS&,,sCx*@%@AB
	J J J J 
J, 04 ??8, //KKS&,,sCx*@%@AB
 
X	B-E -G -4 -D -Ie I I/-s /-5 /-X /-b	c6??2>>::	;2  ^^ 	
  
"( ':A	r#   r%   )importlib.utilr:   r1   r`   r}   email.utilsr   rZ   starlette.datastructuresr   r   starlette.exceptionsr   starlette.responsesr   r   r	   starlette.typesr
   r   r   r   r   r   r   r%   r   r#   r   <module>r      sU     	   !  1 . H H 0 0<<//0
( 
*P Pr#   