
    +h!                        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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)decode_if_byte_string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      Y/var/www/html/e360mart/e360mart_env/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                       e Zd ZdZej        dz   ZdZdZdZde	f fd	Z
d Zd Zed             Zd	 Zd
 Z fdZd Zd Zd Z xZS )r   z
    Wrap WhiteNoise to allow it to function as Django middleware, rather
    than WSGI middleware

    This functions as both old- and new-style middleware, so can be included in
    either MIDDLEWARE or MIDDLEWARE_CLASSES.
    )rootuse_findersstatic_prefixNFc                `   || _         |                     |           t                                          d            | j        r!|                     | j        | j                   | j        r|                     | j                   | j        r| j	        s| 
                                 d S d S d S )N)prefix)get_responseconfigure_from_settingssuper__init__static_root	add_filesr"   r    r!   autorefreshadd_files_from_finders)r   r%   r   	__class__s      r   r(   zWhiteNoiseMiddleware.__init__-   s    ($$X... 	HNN4+D4FNGGG9 	&NN49%%% 	*D$4 	*'')))))	* 	* 	* 	*r   c                ^    |                      |          }||                     |          }|S r   )process_requestr%   )r   requestresponses      r   __call__zWhiteNoiseMiddleware.__call__9   s3    ''00((11Hr   c                    | j         r|                     |j                  }n| j                            |j                  }||                     ||          S d S r   )r+   	find_file	path_infofilesgetserve)r   r0   static_files      r   r/   z$WhiteNoiseMiddleware.process_request?   s[     	<..):;;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intr;   r   fileheaders)r9   r0   r1   r;   http_responsekeyvalues          r   r8   zWhiteNoiseMiddleware.serveG   st    ++GNGLIIX_%%.x}/B6RRR.)"* 	' 	'JC!&M#r   c                v   |j         | _        |j         | _        t          |j        pd          j        | _        t                                          d          }|r;| j        	                    |          r!| j        t          |          d          | _        |j         rd| _        | j        D ]Z}d|                                 }	 t          ||          }t          |          }t!          | ||           K# t"          $ r Y Ww xY wt%          | j                  | _        t          |j                  | _        d S )N /r   WHITENOISE_)DEBUGr+   r!   r   
STATIC_URLpathr"   r
   rstrip
startswithlenmax_ageconfig_attrsuppergetattrr   setattrAttributeErrorr   STATIC_ROOTr)   )r   r   script_prefixattrsettings_keyrC   s         r   r&   z,WhiteNoiseMiddleware.configure_from_settingsR   sK   #>#>%h&9&?R@@E)++22377 	N!,,];; N%)%7M8J8J8L8L%M"> 	DL% 	+ 	+D777L+,77 .e44dE****	 "   
 ;4;MNN01EFFs   C77
DD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$   rE   rF   \c                8    i | ]}|t          j        |          S r   )osstat).0rJ   s     r   
<dictcomp>z?WhiteNoiseMiddleware.add_files_from_finders.<locals>.<dictcomp>y   s"    EEEddBGDMMEEEr   )
stat_cache)r   get_finderslistrQ   stripjoinr"   replace
setdefaultrJ   valuesitemsadd_file_to_dictionary)r   r6   finderrJ   storager$   urlr_   s           r   r,   z+WhiteNoiseMiddleware.add_files_from_findersj   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!   rL   r"   r   findrM   r'   candidate_paths_for_url)r   rk   rJ   pathsr-   s       r   rn   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)rL   r"   rM   get_name_without_hashget_static_urlr   )r   rJ   rk   namename_without_hash
static_urls         r   immutable_file_testz(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   )r[   rJ   splitext)r   filenamename_with_hashextrs   s        r   rq   z*WhiteNoiseMiddleware.get_name_without_hash   sB     !g..x88w//2czr   c                h    	 t          t          j        |                    S # t          $ r Y d S w xY wr   )r   r   rk   
ValueError)r   rs   s     r   rr   z#WhiteNoiseMiddleware.get_static_url   sC    	()<)@)F)FGGG 	 	 	44	s    # 
11)r   r   r   r   r   rO   r    r!   r"   r   r(   r2   r/   staticmethodr8   r&   r,   rn   rv   rq   rr   __classcell__)r-   s   @r   r   r      s         *-UULDKM$(8 
* 
* 
* 
* 
* 
*  4 4 4   \G G G0J J J&      (        r   )
__future__r   r[   	posixpathr   urllib.parser   django.confr   django.contrib.staticfilesr   "django.contrib.staticfiles.storager   django.httpr	   django.urlsr
   baser   string_utilsr   r   __all__r   r   r   r   r   <module>r      s8   " " " " " " 				       ! ! ! ! ! !             . . . . . . B B B B B B $ $ $ $ $ $ ) ) ) ) ) )       N N N N N N N N!
"	 	 	 	 	\ 	 	 	L L L L L: L L L L Lr   