
    ih                         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 d
lmZ  G d d          Z G d dee          Z G d dee          ZdS )    )urlparse)url2pathname)sync_to_async)settings)utils)serve)ASGIHandler)response_for_exception)WSGIHandlerget_path_info)Http404c                   @    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
S )StaticFilesHandlerMixinz8
    Common methods used by WSGI and ASGI handlers.
    Tc                     d S N selfs    Z/var/www/histauto/venv/lib/python3.11/site-packages/django/contrib/staticfiles/handlers.pyload_middlewarez'StaticFilesHandlerMixin.load_middleware   s	     	    c                 @    t          j                     t          j        S r   )r   check_settingsr   
STATIC_URLr   s    r   get_base_urlz$StaticFilesHandlerMixin.get_base_url   s    ""r   c                 Z    |                     | j        j                  o| j        j         S )z
        Check if the path should be handled. Ignore the path if:
        * the host is provided as part of the base_url
        * the request's path isn't under the media path (or equal)
        )
startswithbase_urlpathnetloc)r   r   s     r   _should_handlez&StaticFilesHandlerMixin._should_handle!   s(     t}122O4=;O7OOr   c                 ^    |                     | j        j                  }t          |          S )zW
        Return the relative path to the media file on disk for the given URL.
        )removeprefixr   r   r   )r   urlrelative_urls      r   	file_pathz!StaticFilesHandlerMixin.file_path)   s*     ''(:;;L)))r   c                 V    t          ||                     |j                  d          S )zServe the request path.T)insecure)r   r&   r   )r   requests     r   r   zStaticFilesHandlerMixin.serve0   s%    WdnnW\::TJJJJr   c                 |    	 |                      |          S # t          $ r}t          ||          cY d }~S d }~ww xY wr   )r   r   r
   r   r)   es      r   get_responsez$StaticFilesHandlerMixin.get_response4   sW    	6::g&&& 	6 	6 	6)'155555555	6s    
;6;;c                    K   	  t          | j        d          |           d {V S # t          $ r0} t          t          d          ||           d {V cY d }~S d }~ww xY w)NF)thread_sensitive)r   r   r   r
   r+   s      r   get_response_asyncz*StaticFilesHandlerMixin.get_response_async:   s      	JtzEJJJ7SSSSSSSSS 	 	 	V'=PUVVV             	s   $) 
A#%AA#A#N)__name__
__module____qualname____doc__handles_filesr   r   r!   r&   r   r-   r0   r   r   r   r   r      s          M  
# # #P P P* * *K K K6 6 6    r   r   c                   ,     e Zd ZdZ fdZ fdZ xZS )StaticFilesHandlerz
    WSGI middleware that intercepts calls to the static files directory, as
    defined by the STATIC_URL setting, and serves those files.
    c                     || _         t          |                                           | _        t	                                                       d S r   )applicationr   r   r   super__init__)r   r9   	__class__s     r   r;   zStaticFilesHandler.__init__I   sB    & !2!2!4!455r   c                     |                      t          |                    s|                     ||          S t                                          ||          S r   )r!   r   r9   r:   __call__)r   environstart_responser<   s      r   r>   zStaticFilesHandler.__call__N   sQ    ""=#9#9:: 	=##G^<<<ww888r   )r1   r2   r3   r4   r;   r>   __classcell__r<   s   @r   r7   r7   C   s[         
    
9 9 9 9 9 9 9 9 9r   r7   c                   2     e Zd ZdZd Z fdZ fdZ xZS )ASGIStaticFilesHandlerz
    ASGI application which wraps another and intercepts requests for static
    files, passing them off to Django's static file serving.
    c                 `    || _         t          |                                           | _        d S r   )r9   r   r   r   )r   r9   s     r   r;   zASGIStaticFilesHandler.__init__Z   s)    & !2!2!4!455r   c                    K   |d         dk    rD|                      |d                   r)t                                          |||           d {V S |                     |||           d {V S )Ntypehttpr   )r!   r:   r>   r9   )r   scopereceivesendr<   s       r   r>   zASGIStaticFilesHandler.__call__^   s      =F""t':':5='I'I" ))%$?????????%%eWd;;;;;;;;;r   c                    K   t                                          |           d {V }|j                            |j                   |j        r"|j        s|j        fd} |            |_        |S )Nc                 b   K    t          t                               d {V D ]} | W V  d S r   )r   list)part	_iterators    r   awrapperz;ASGIStaticFilesHandler.get_response_async.<locals>.awrappern   sQ      "5-"5"5i"@"@@@@@@@  DJJJJJ r   )r:   r0   _resource_closersappendclose	streamingis_asyncstreaming_content)r   r)   responserQ   rP   r<   s       @r   r0   z)ASGIStaticFilesHandler.get_response_asyncg   s      33G<<<<<<<<"))'-888 	4h&7 	4 2I     *2H&r   )r1   r2   r3   r4   r;   r>   r0   rA   rB   s   @r   rD   rD   T   sj         
6 6 6< < < < <        r   rD   N)urllib.parser   urllib.requestr   asgiref.syncr   django.confr   django.contrib.staticfilesr    django.contrib.staticfiles.viewsr   django.core.handlers.asgir	   django.core.handlers.exceptionr
   django.core.handlers.wsgir   r   django.httpr   r   r7   rD   r   r   r   <module>rc      sL   ! ! ! ! ! ! ' ' ' ' ' ' & & & & & &             , , , , , , 2 2 2 2 2 2 1 1 1 1 1 1 A A A A A A @ @ @ @ @ @ @ @      1 1 1 1 1 1 1 1h9 9 9 9 90+ 9 9 9"    4k     r   