
    =h"                         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Zd dl	m
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j0                  edf   Z G d	 d
e      Z G d d      Zy)    N)	parsedate)get_route_path)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       e/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/starlette/staticfiles.pyr   zNotModifiedResponse.__init__   sV     $+==?#2KD%4444 e#2 	 	
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originr2   r3   normpathjoinr4   )r   r'   r(   directoriespackagestatics_dirspecpackage_directorys           r   r/   zStaticFiles.get_directories=   s     y)~2~G'5)'.$'>>++G4D#Ox{:N%OO#;;*VhwkAU,VV* " 0 0T[[$<! 77==! Y[O=CWXY  01 &  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)r1   check_configget_pathget_response)r   rF   rG   rH   r3   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        |      }t        j                  j                  t        j                  j                  |j                  d             S )z
        Given the ASGI scope, return the `path` string to serve up,
        with OS specific path separators, and any '..', '.' components removed.
        /)r   r2   r3   r?   r@   split)r   rF   
route_paths      r   rM   zStaticFiles.get_pathl   s;    
 $E*
wwj.>.>s.C DEEr$   r3   c                 R  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                  rdt        j                  j                  | j                  d       d{   \  }}|r-t        j                  |j                        rt)        ||d      S t        d      7 # t
        $ r t        d      t        $ r  w xY w7 (7 jw)z`
        Returns an HTTP response, given the incoming path, method and request headers.
        method)GETHEADi  )r   Ni  z
index.htmlr3   rR   rF   )r3   )urlz404.htmli  )stat_resultr   )r   anyio	to_threadrun_synclookup_pathPermissionErrorOSErrorstatS_ISREGst_modefile_responseS_ISDIRr)   r2   r3   r@   endswithr   replacer	   r   )r   r3   rF   	full_pathr[   
index_pathrZ   s          r   rN   zStaticFiles.get_responset   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,?,?@#I;TWXX,,E&  	1C00 		&&sO   H'-H  G=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)r0   r2   r3   r@   r+   abspathrealpath
commonpathrb   FileNotFoundErrorNotADirectoryError)r   r3   r'   joined_pathri   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-ri   r[   r   c                     t        |      }t        |||      }| j                  |j                  |      rt	        |j                        S |S )NrY   )r   r[   )r   r   is_not_modifiedr   r   )r   ri   r[   rF   r   request_headersrO   s          r   re   zStaticFiles.file_response   sM     ".;K
  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'   r\   r]   r^   r2   rb   rp   r5   rf   rd   S_ISLNK)r   r[   s     r   rL   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_headersru   c                    	 |d   }|d   }||j                  d      D cg c]  }|j                  d       c}v ry	 	 t        |d         }t        |d         }||||k\  ryyc c}w # t        $ r Y 8w 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   ,z W/Tzif-modified-sincezlast-modifiedF)rS   stripKeyErrorr   )r   rx   ru   if_none_matchr   tagif_modified_sincelast_modifieds           r   rt   zStaticFiles.is_not_modified   s    	+O<M#F+DM4G4G4LM4LS		%(4LMM N

	 )/:M*N O%&6&GHM!-!-%6 # N 		  		s2   A+ A&A+ %A: &A+ +	A76A7:	BB)NN)   )r,   N)r    r!   r"   typingOptionalPathLikeListUnionstrTupleboolr   r/   r   r   r   rP   rM   r
   rN   r2   r[   r_   intre   rL   r   rt    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 -Fe F F*-s *-5 *-X *-X	c6??2>>::	;2  ^^ 	
  
 ( ':A	r$   r&   )importlib.utilr;   r2   rb   r   email.utilsr   r\   anyio.to_threadstarlette._utilsr   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 . H H 0 0<<//0
( 
*K Kr$   