a
    Døg"  ã                   @   sJ   d dl Zd dlmZ dZd eeeƒ¡Zdd„ Z	e	dd„ ƒZ
dd
d„ZdS )é    N)Ú
guess_type)r   é   é   Ú.c                    s(   g ‰ ‡ ‡fdd„}‡ fdd„}||_ |S )Nc                      s   ˆ sˆ   ˆƒ ¡ ˆ d S )Nr   )Úappend© ©Ú_cachedÚfnr   úU/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/utils/sendfile.pyÚ
_decorated   s    z_lazy_load.<locals>._decoratedc                      s   ˆ rˆ   ¡  q d S )N)Úpopr   )r	   r   r   Úclear   s    z_lazy_load.<locals>.clear)r   )r
   r   r   r   r   r   Ú
_lazy_load   s
    r   c                  C   sJ   ddl m}  ddlm} ddlm} t|dd ƒ}|s<|dƒ‚| |ƒ}|jS )Nr   )Úimport_module)Úsettings)ÚImproperlyConfiguredZSENDFILE_BACKENDz-You must specify a value for SENDFILE_BACKEND)Ú	importlibr   Zdjango.confr   Zdjango.core.exceptionsr   ÚgetattrÚsendfile)r   r   r   ÚbackendÚmoduler   r   r   Ú_get_sendfile   s    r   Fc                 C   s   |pt ƒ }tj |¡s.ddlm} |d| ƒ‚t|ƒ\}	}
|du rP|	rL|	}nd}|| ||d}|rjdg}ndg}|du r„tj |¡}|rèdd	lm	} dd
l
m} ||ƒ}||ƒ}| d| ¡ ||krèddlm} ||ƒ}| d| ¡ d |¡|d< tj |¡|d< ||d< |p|
|d< |S )aQ  
    create a response to send file using backend configured in SENDFILE_BACKEND

    If attachment is True the content-disposition header will be set.
    This will typically prompt the user to download the file, rather
    than view it.  The content-disposition filename depends on the
    value of attachment_filename:

        None (default): Same as filename
        False: No content-disposition filename
        String: Value used as filename

    If no mimetype or encoding are specified, then they will be guessed via the
    filename (using the standard python mimetypes module)
    r   )ÚHttp404z"%s" does not existNzapplication/octet-stream)ÚmimetypeÚ
attachmentÚinline)Ú	force_str)Ústring_to_asciizfilename="%s")Úquotezfilename*=UTF-8''%sz; zContent-DispositionzContent-lengthzContent-TypezContent-Encoding)r   ÚosÚpathÚexistsZdjango.httpr   r   ÚbasenameZdjango.utils.encodingr   Zwagtail.coreutilsr   r   Úurllib.parser   ÚjoinÚgetsize)ÚrequestÚfilenamer   Zattachment_filenamer   Úencodingr   Z	_sendfiler   Zguessed_mimetypeZguessed_encodingÚresponseÚpartsr   r   Zascii_filenamer   Zquoted_filenamer   r   r   r   )   s<    
r   )FNNNN)Úos.pathr    Ú	mimetypesr   ÚVERSIONr%   ÚmapÚstrÚ__version__r   r   r   r   r   r   r   Ú<module>   s   
     ù