
    Ojo#                        d dl mZ d dlZd dlZd dlZd dlZd dlm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 d d
lmZ e
edf   Z G d de      Z  G d d      Z!y)    )annotationsN)	parsedate)Union)get_route_path)URLHeaders)HTTPException)FileResponseRedirectResponseResponse)ReceiveScopeSend)WebSocketClosezos.PathLike[str]c                  $     e Zd ZdZd fdZ xZS )NotModifiedResponse)zcache-controlzcontent-locationdateetagexpiresvaryc           	         t         |   d|j                         D ci c]  \  }}|| j                  v s|| c}}       y c c}}w )Ni0  )status_codeheaders)super__init__itemsNOT_MODIFIED_HEADERS)selfr   namevalue	__class__s       l/var/www/origus_pro_usr/data/www/origus.pro/core/.venv/lib/python3.12/site-packages/starlette/staticfiles.pyr   zNotModifiedResponse.__init__!   sD    4;MMOi[T5ttOhOhGhT5[i 	 	
is
   AA)r   r   )__name__
__module____qualname__r   r   __classcell__)r!   s   @r"   r   r      s    
 
    r   c                      e Zd Zdddddd	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 ddZddZddZdd	Zdd
Z	 d	 	 	 	 	 	 	 	 	 ddZ	ddZ
ddZy)StaticFilesNFT)	directorypackageshtml	check_dirfollow_symlinkc                   || _         || _        | 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..r0   z' in package )append
isinstancetuple	importlibutil	find_specoriginr4   r5   normpathjoinr6   )r   r*   r+   directoriespackagestatics_dirspecpackage_directorys           r"   r1   zStaticFiles.get_directories;   s     y)~2 	2G'5)'.$'>>++G4D#Ox{:N%OO#;;*VhwkAU,VV* " 0 0dkk4Q\1] ^77==!23 k_M'DXY3 01	2 r'   c                J  K   |d   dk(  rt               } ||||       d{    y|d   dk(  sJ | j                  s| j                          d{    d| _        | j                  |      }| j	                  ||       d{   } ||||       d{    y7 x7 K7 7 w)z'
        The ASGI entry point.
        type	websocketNhttpT)r   r3   check_configget_pathget_response)r   scopereceivesendwebsocket_closer5   responses          r"   __call__zStaticFiles.__call__X   s      =K',.O!%$777V}&&&""##%%%"&D}}U#**477ugt,,, 8 & 8,sE    B#B.B#B1B#BB#B!B#B#B#!B#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   r4   r5   rA   rB   split)r   rO   
route_paths      r"   rM   zStaticFiles.get_pathk   s;    
 $E*
wwj.>.>s.C DEEr'   c                  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        $ r0}|j                  t        j                  k(  rt        d      |d}~wt        $ r t        d      w xY w7 j7 w)z`
        Returns an HTTP response, given the incoming path, method and request headers.
        method)GETHEADi  )r   Ni  i  z
index.htmlr5   rV   rO   )r5   )urlz404.html)stat_resultr   )r	   anyio	to_threadrun_synclookup_pathPermissionErrorOSErrorerrnoENAMETOOLONG
ValueErrorstatS_ISREGst_modefile_responseS_ISDIRr,   r4   r5   rB   endswithr   replacer   r
   )r   r5   rO   	full_pathr_   exc
index_pathr^   s           r"   rN   zStaticFiles.get_responses   s     ?/1C00	1+0??+C+CDDTDTVZ+[%["I{ 4<<(;(;<%%ieDDT\\+*=*=>499 dL9J+0??+C+CDDTDTV`+a%a"I{&4<<8K8K+LV}--c2E*C++388c>+:C+44)))[%HH99+0??+C+CDDTDTV`+a%a"I{t||K,?,?@#I;TWXX,,G &\ 	1C00 	yyE...#44I 	1C00	1 &b &bs[   I)-H  G=H  B.I):I$;B?I):I';AI)=H   I!+II!!I)'I)c                V   |j                  d      ry| j                  D ]  }t        j                  j	                  ||      }| j
                  r?t        j                  j                  |      }t        j                  j                  |      }n>t        j                  j                  |      }t        j                  j                  |      }t        j                  j                  ||g      t        |      k7  r	 |t        j                  |      fc S  y# t        t        f$ r Y w xY w)N)rV   \) N)
startswithr2   r4   r5   rB   r.   abspathrealpath
commonpathstrri   FileNotFoundErrorNotADirectoryError)r   r5   r*   joined_pathrp   s        r"   rc   zStaticFiles.lookup_path   s    ??;'-- 	I'',,y$7K""GGOOK8	GGOOI6	GG,,[9	GG,,Y7	ww!!9i"89S^K "'')"444	  &'9: s   :DD('D(c                    t        |      }t        |||      }| j                  |j                  |      rt	        |j                        S |S )Nr]   )r   r_   )r   r
   is_not_modifiedr   r   )r   rp   r_   rO   r   request_headersrS   s          r"   rl   zStaticFiles.file_response   sI     ".	{P[\ 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`   ra   rb   r4   ri   r{   r7   rm   rk   S_ISLNK)r   r_   s     r"   rL   zStaticFiles.check_config   s      >>!	\ % 8 8$.. QQK [001T\\+BUBU5V!3DNN3CCXYZZ 6W1 R  	\!88HHYZ[[	\s/   C;B, B*B, AC*B, ,#CCc                N   |j                  d      x}rW|j                         dk(  ry|d   }||j                  d      D cg c]!  }|j                         j                  d      # c}v S 	 t	        |d         }t	        |d         }||||k\  ryy	c c}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-match*Tr   ,zW/zif-modified-sincezlast-modifiedF)getstriprW   removeprefixr   KeyError)r   response_headersr   if_none_matchr   tagif_modified_sincelast_modifieds           r"   r   zStaticFiles.is_not_modified   s    
 ,//@@=@""$+#F+DmFYFYZ]F^_sCIIK44T:___	 )/:M*N O%&6&GHM ,1JO`dqOq  `  		s   &B,%B 	B$#B$)r*   PathLike | Noner+   "list[str | tuple[str, str]] | Noner,   boolr-   r   r.   r   returnNone)NN)r*   r   r+   r   r   zlist[PathLike])rO   r   rP   r   rQ   r   r   r   )rO   r   r   rz   )r5   rz   rO   r   r   r   )r5   rz   r   z!tuple[str, os.stat_result | None])   )
rp   PathLiker_   zos.stat_resultrO   r   r   intr   r   )r   r   )r   r   r   r   r   r   )r#   r$   r%   r   r1   rT   rM   rN   rc   rl   rL   r    r'   r"   r)   r)   (   s     &*7;$J #J 5	J
 J J J 
J( &*7;" 5 
	:-&F+-Z4  $ 	
  
[ r'   r)   )"
__future__r   rf   importlib.utilr=   r4   ri   email.utilsr   typingr   r`   anyio.to_threadstarlette._utilsr   starlette.datastructuresr   r   starlette.exceptionsr	   starlette.responsesr
   r   r   starlette.typesr   r   r   starlette.websocketsr   rz   r   r   r)   r   r'   r"   <module>r      s`    "   	  !    + 1 . H H 0 0 /(()
( 
" r'   