o
    ^"<f†  ã                   @   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   úZ/var/www/html/kck/venv/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   Úcheck_settingsr   Ú
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   ÚurlÚrelative_urlr   r   r   Ú	file_path(   s   z!StaticFilesHandlerMixin.file_pathc                 C   s   t ||  |j¡ddS )zServe the request path.T)Ú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)Úthread_sensitive)r   r   r   r	   r#   r   r   r   Úget_response_async9   s   €$€ÿz*StaticFilesHandlerMixin.get_response_asyncN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú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   r0   E   s   zStaticFilesHandler.__init__c                    s(   |   t|ƒ¡s|  ||¡S tƒ  ||¡S r   )r   r   r.   r/   Ú__call__)r   ÚenvironÚstart_responser2   r   r   r4   J   s   zStaticFilesHandler.__call__©r(   r)   r*   r+   r0   r4   Ú__classcell__r   r   r2   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   r1   r   r   r   r0   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/   r4   r.   )r   ÚscopeÚreceiveÚsendr2   r   r   r4   Y   s   €zASGIStaticFilesHandler.__call__r7   r   r   r2   r   r9   P   s    r9   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   r-   r9   r   r   r   r   Ú<module>   s    1