o
    h                     @   s   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 dZG dd deeZG dd deeZdS )    )urlparse)url2pathname)sync_to_async)settings)utils)serve)ASGIHandler)response_for_exception)WSGIHandlerget_path_info)Http404c                   @   sL   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd ZdS )StaticFilesHandlerMixinz8
    Common methods used by WSGI and ASGI handlers.
    Tc                 C   s   d S N selfr   r   k/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/django/contrib/staticfiles/handlers.pyload_middleware   s   z'StaticFilesHandlerMixin.load_middlewarec                 C   s   t   tjS r   )r   Zcheck_settingsr   Z
STATIC_URLr   r   r   r   get_base_url   s   z$StaticFilesHandlerMixin.get_base_urlc                 C   s   | | jd o| jd  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)r   pathr   r   r   _should_handle    s   z&StaticFilesHandlerMixin._should_handlec                 C   s   |t | jd d }t|S )zW
        Return the relative path to the media file on disk for the given URL.
        r   N)lenr   r   )r   urlZrelative_urlr   r   r   	file_path(   s   z!StaticFilesHandlerMixin.file_pathc                 C   s   t || |jddS )zServe the request path.T)Zinsecure)r   r   r   )r   requestr   r   r   r   /   s   zStaticFilesHandlerMixin.servec              
   C   s<   z|  |W S  ty } zt||W  Y d }~S d }~ww r   )r   r   r	   r   r   er   r   r   get_response3   s   z$StaticFilesHandlerMixin.get_responsec              
      sZ   zt | jdd|I d H W S  ty, } zt tdd||I d H W  Y d }~S d }~ww )NF)Zthread_sensitive)r   r   r   r	   r   r   r   r   get_response_async9   s   $z*StaticFilesHandlerMixin.get_response_asyncN)__name__
__module____qualname____doc__Zhandles_filesr   r   r   r   r   r!   r"   r   r   r   r   r      s    r   c                       s,   e Zd ZdZ fddZ fddZ  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                    s"   || _ t|  | _t   d S r   )applicationr   r   r   super__init__r   r(   	__class__r   r   r*   E   s   zStaticFilesHandler.__init__c                    s(   |  t|s| ||S t ||S r   )r   r   r(   r)   __call__)r   environZstart_responser,   r   r   r.   J   s   zStaticFilesHandler.__call__r#   r$   r%   r&   r*   r.   __classcell__r   r   r,   r   r'   @   s    r'   c                       s(   e Zd ZdZdd Z fddZ  ZS )ASGIStaticFilesHandlerz
    ASGI application which wraps another and intercepts requests for static
    files, passing them off to Django's static file serving.
    c                 C   s   || _ t|  | _d S r   )r(   r   r   r   r+   r   r   r   r*   U   s   zASGIStaticFilesHandler.__init__c                    sF   |d dkr|  |d rt |||I d H S | |||I d H S )Ntypehttpr   )r   r)   r.   r(   )r   scopeZreceivesendr,   r   r   r.   Y   s   zASGIStaticFilesHandler.__call__r0   r   r   r,   r   r2   P   s    r2   N)urllib.parser   urllib.requestr   Zasgiref.syncr   Zdjango.confr   Zdjango.contrib.staticfilesr   Z django.contrib.staticfiles.viewsr   Zdjango.core.handlers.asgir   Zdjango.core.handlers.exceptionr	   Zdjango.core.handlers.wsgir
   r   Zdjango.httpr   r   r'   r2   r   r   r   r   <module>   s    1