
    +Jf!                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ dgZ G d de          Z G d de          ZdS )    )annotationsN)basename)urlparse)settings)finders)staticfiles_storage)FileResponse)get_script_prefix)
WhiteNoise)ensure_leading_trailing_slashWhiteNoiseMiddlewarec                      e Zd ZdZd ZdS )WhiteNoiseFileResponsea  
    Wrap Django's FileResponse to prevent setting any default headers. For the
    most part these just duplicate work already done by WhiteNoise but in some
    cases (e.g. the content-disposition header introduced in Django 3.0) they
    are actively harmful.
    c                    d S N )selfargskwargss      X/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/whitenoise/middleware.pyset_headersz"WhiteNoiseFileResponse.set_headers   s        N)__name__
__module____qualname____doc__r   r   r   r   r   r      s-             r   r   c                  f     e Zd ZdZdef fd	Zd Zed             Zd Z	 fdZ
d Zd	 Zd
 Z xZS )r   zh
    Wrap WhiteNoise to allow it to function as Django middleware, rather
    than WSGI middleware.
    Nc                   || _         	 |j        }n# t          $ r
 |j        }Y nw xY w	 |j        }n# t          $ r |j        rd}nd}Y nw xY w	 |j        }n# t          $ r d}Y nw xY w	 |j        }n# t          $ r d}Y nw xY w	 |j        }n# t          $ r d }Y nw xY w	 |j        }n# t          $ r d }Y nw xY w	 |j	        }	n# t          $ r d }	Y nw xY w	 |j
        }
n# t          $ r d }
Y nw xY wt                                          d |||||||	|
	  	         	 |j        | _        n# t          $ r |j        | _        Y nw xY w	 |j        | _        n# t          $ r t#          |j        pd          j        | _        t)                                          d          }|r;| j                            |          r!| j        t/          |          d          | _        Y nw xY wt1          | j                  | _        |j        | _        | j        r!|                     | j        | j                   	 |j        }n# t          $ r d }Y nw xY w|r|                     |           | j        r| j        s|                                  d S d S d S )	Nr   <   Tzutf-8)	applicationautorefreshmax_ageallow_all_originscharset	mimetypesadd_headers_function
index_fileimmutable_file_test /)prefix)get_responseWHITENOISE_AUTOREFRESHAttributeErrorDEBUGWHITENOISE_MAX_AGEWHITENOISE_ALLOW_ALL_ORIGINSWHITENOISE_CHARSETWHITENOISE_MIMETYPESWHITENOISE_ADD_HEADERS_FUNCTIONWHITENOISE_INDEX_FILEWHITENOISE_IMMUTABLE_FILE_TESTsuper__init__WHITENOISE_USE_FINDERSuse_findersWHITENOISE_STATIC_PREFIXstatic_prefixr   
STATIC_URLpathr
   rstrip
startswithlenr   STATIC_ROOTstatic_root	add_filesWHITENOISE_ROOTr!   add_files_from_finders)r   r,   r   r!   r"   r#   r$   r%   r&   r'   r(   script_prefixroot	__class__s                r   r8   zWhiteNoiseMiddleware.__init__%   s   (	) ( ?KK 	) 	) 	)".KKK	)	1GG 	 	 	~ 		
	% ( E 	% 	% 	% $	%	1GG 	 	 	GGG		 5II 	 	 	III		(#+#K   	( 	( 	(#'   	(	!7JJ 	 	 	JJJ		'"*"I 	' 	' 	'"&	' 	#/!5! 3 	 
	
 
	
 
	
	.'>D 	. 	. 	.'~D	.	R!)!BD 	R 	R 	R!)(*=*C!D!D!ID-//66s;;M R%00?? R)-);C<N<N<P<P)QD&	R ;4;MNN#/ 	HNN4+D4FNGGG	+DD 	 	 	DDD	 	!NN4    	*D$4 	*'')))))	* 	* 	* 	*s    &&2 A
AA A&%A&*A2 2B BB BB B( (B76B7;C CCC C-,C-D( (E EE BGG.H6 6IIc                    | j         r|                     |j                  }n| j                            |j                  }||                     ||          S |                     |          S r   )r!   	find_file	path_infofilesgetserver,   )r   requeststatic_files      r   __call__zWhiteNoiseMiddleware.__call__u   sg     	<..):;;KK*..):;;K"::k7333  )))r   c                    |                      |j        |j                  }t          |j                  }t          |j        pd|          }|d= |j        D ]
\  }}|||<   |S )Nr   )statuszcontent-type)r,   methodMETAintrT   r   fileheaders)rQ   rP   responserT   http_responsekeyvalues          r   rO   zWhiteNoiseMiddleware.serve~   st    ++GNGLIIX_%%.x}/B6RRR.)"* 	' 	'JC!&M#r   c                   i }t          j                    D ]}|                    d           D ]\  }}t          |dd           pd                    d          }d                    | j        ||rdnd|                    dd          f          }|                    ||	                    |                     d |
                                D             }|                                D ]\  }}|                     |||           d S )Nr+   r)   r*   \c                8    i | ]}|t          j        |          S r   )osstat).0r>   s     r   
<dictcomp>z?WhiteNoiseMiddleware.add_files_from_finders.<locals>.<dictcomp>   s"    EEEddBGDMMEEEr   )
stat_cache)r   get_finderslistgetattrstripjoinr<   replace
setdefaultr>   valuesitemsadd_file_to_dictionary)r   rM   finderr>   storager+   urlre   s           r   rF   z+WhiteNoiseMiddleware.add_files_from_finders   s1   )++ 	: 	:F!'T!2!2 : :g!'8T::@bGGLLgg*%-2T3//	    gll4&8&89999: FEellnnEEE
 	J 	JIC''Tj'IIII	J 	Jr   c              #  
  K   | j         rN|                    | j                  r4t          j        |t          | j                  d                    }|r|V  t                                          |          }|D ]}|V  d S r   )r:   r@   r<   r   findrA   r7   candidate_paths_for_url)r   rr   r>   pathsrI   s       r   ru   z,WhiteNoiseMiddleware.candidate_paths_for_url   s       	t/A B B 	<C(:$;$;$=$= >??D 


//44 	 	DJJJJ	 	r   c                "   |                     | j                  sdS |t          | j                  d         }|                     |          }||k    rdS |                     |          }|r"t          |          t          |          k    rdS dS )z
        Determine whether given URL represents an immutable file (i.e. a
        file with a hash of its contents as part of its name) which can
        therefore be cached forever
        FNT)r@   r<   rA   get_name_without_hashget_static_urlr   )r   r>   rr   namename_without_hash
static_urls         r   r(   z(WhiteNoiseMiddleware.immutable_file_test   s     ~~d011 	53t)**,,- 66t<<$$$5(():;;
  	(:..(3--??4ur   c                    t           j                            |          \  }}t           j                            |          d         }||z   S )aW  
        Removes the version hash from a filename e.g, transforms
        'css/application.f3ea4bcc2.css' into 'css/application.css'

        Note: this is specific to the naming scheme used by Django's
        CachedStaticFilesStorage. You may have to override this if
        you are using a different static files versioning system
        r   )ra   r>   splitext)r   filenamename_with_hashextrz   s        r   rx   z*WhiteNoiseMiddleware.get_name_without_hash   sB     !g..x88w//2czr   c                N    	 t          j        |          S # t          $ r Y d S w xY wr   )r   rr   
ValueError)r   rz   s     r   ry   z#WhiteNoiseMiddleware.get_static_url   s:    	&*4000 	 	 	44	s    
$$)r   r   r   r   r   r8   rR   staticmethodrO   rF   ru   r(   rx   ry   __classcell__)rI   s   @r   r   r      s         
 %)8 N* N* N* N* N* N*`* * *   \J J J&      (        r   )
__future__r   ra   	posixpathr   urllib.parser   django.confr   django.contrib.staticfilesr   "django.contrib.staticfiles.storager   django.httpr	   django.urlsr
   whitenoise.baser   whitenoise.string_utilsr   __all__r   r   r   r   r   <module>r      s2   " " " " " " 				       ! ! ! ! ! !             . . . . . . B B B B B B $ $ $ $ $ $ ) ) ) ) ) ) & & & & & & A A A A A A!
"	 	 	 	 	\ 	 	 	k k k k k: k k k k kr   