a c"@sddlZddlZddlZddlZddlmZddlZddlm Z m Z ddl m Z ddl mZmZmZddlmZmZmZejedfZGdd d eZGd d d ZdS) N) parsedate)URLHeaders) HTTPException) FileResponseRedirectResponseResponse)ReceiveScopeSendzos.PathLike[str]cs&eZdZdZedfdd ZZS)NotModifiedResponse)z cache-controlzcontent-locationdateetagexpiresvary)headerscs&tjdfdd|DddS)Ni0cs i|]\}}|jvr||qS)NOT_MODIFIED_HEADERS).0namevalueselfrb/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/staticfiles.py s z0NotModifiedResponse.__init__..) status_coder)super__init__items)rr __class__rrrs  zNotModifiedResponse.__init__)__name__ __module__ __qualname__rrr __classcell__rrrrr s r c @s*eZdZddddddejeejejejeej eeffe e e ddddZ d!ejeejejejeej eeffejedd d Z e eedd d d Ze edddZee edddZeej eejejfdddZd"eeje eedddZddddZeee ddd ZdS)# StaticFilesNFT) directorypackageshtml check_dirfollow_symlink)r&r'r(r)r*returncCsX||_||_||||_||_d|_||_|rT|durTtj |sTt d|ddS)NF Directory 'z' does not exist) r&r'get_directoriesall_directoriesr(config_checkedr*ospathisdir RuntimeError)rr&r'r(r)r*rrrr's zStaticFiles.__init__)r&r'r+cCsg}|dur|||pgD]}t|tr6|\}}nd}tj|}|dus^Jd|d|jdusxJd|dtj tj |jd|}tj |sJd|d|d||q|S)z Given `directory` and `packages` arguments, return a list of all the directories that should be used for serving static files from. NZstaticszPackage z could not be found.z..r,z ' in package ) append isinstancetuple importlibutil find_specoriginr0r1normpathjoinr2)rr&r' directoriespackageZ statics_dirspecpackage_directoryrrrr-;s(       zStaticFiles.get_directories)scopereceivesendr+cs\|ddksJ|js*|IdHd|_||}|||IdH}||||IdHdS)z' The ASGI entry point. typehttpNT)r/ check_configget_path get_response)rrArBrCr1responserrr__call__\s zStaticFiles.__call__)rAr+cCstjtjj|ddS)z Given the ASGI scope, return the `path` string to serve up, with OS specific path separators, and any '..', '.' components removed. r1/)r0r1r;r<split)rrArrrrGjszStaticFiles.get_path)r1rAr+csz|ddvrtddztj|j|IdH\}}Wn.tyPtddYntybYn0|rt|j r| |||S|r"t |j r"|j r"t j|d}tj|j|IdH\}}|dur"t|j r"|dd st|d }|j|jd d }t|d S| |||S|j rltj|jd IdH\}}|rlt|j rlt|||dddStdddS)z` Returns an HTTP response, given the incoming path, method and request headers. method)GETHEADi)rNiz index.htmlr1rKrA)r1)urlz404.htmli) stat_resultrMr)ranyio to_threadrun_sync lookup_pathPermissionErrorOSErrorstatS_ISREGst_mode file_responseS_ISDIRr(r0r1r<endswithrreplacerr)rr1rA full_pathrRZ index_pathrQrrrrHqsF      zStaticFiles.get_response)r1r+c Cs|jD]}tj||}|jr,tj|}n tj|}tj|}tj||g|krZqz|t|fWSt t fyYqYq0qdS)N)N) r.r0r1r<r*abspathrealpath commonprefixrYFileNotFoundErrorNotADirectoryError)rr1r&Z joined_pathr`rrrrVs    zStaticFiles.lookup_path)r`rRrArr+cCs>|d}t|d}t||||d}||j|r:t|jS|S)NrMrP)rrRrM)rris_not_modifiedrr )rr`rRrArrMrequest_headersrIrrrr\s  zStaticFiles.file_response)r+cs~|jdurdSztjtj|jIdH}Wn$tyNtd|jdYn0t|j szt |j sztd|jddS)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. NzStaticFiles directory 'z' does not exist.zStaticFiles path 'z' is not a directory.) r&rSrTrUr0rYrer3r]r[S_ISLNK)rrRrrrrFs    zStaticFiles.check_config)response_headersrir+cCsz"|d}|d}||kr WdSWnty4Yn0z:t|d}t|d}|durn|durn||krnWdSWntyYn0dS)z Given the request and response headers, return `True` if an HTTP "Not Modified" response could be returned instead. z if-none-matchrTzif-modified-sincez last-modifiedNF)KeyErrorr)rrkriZ if_none_matchrZif_modified_sinceZ last_modifiedrrrrhs(      zStaticFiles.is_not_modified)NN)rg)r!r"r#typingOptionalPathLikeListUnionstrTupleboolrr-r r r rJrGrrHr0rRrVintr\rFrrhrrrrr%&sT  !2  r%)importlib.utilr7r0rYrm email.utilsrrSZstarlette.datastructuresrrZstarlette.exceptionsrZstarlette.responsesrrrZstarlette.typesr r r rqrrror r%rrrrs